Merge pull request #6664 from continuedev/jacob/bug/race-condition-initLanceDb
fix: race condition for this.lanceDbIndex being loaded and retrieveEmbeddings accessing it
This commit is contained in:
commit
ada6b53fda
1 changed files with 22 additions and 2 deletions
|
|
@ -60,12 +60,13 @@ export interface IRetrievalPipeline {
|
|||
export default class BaseRetrievalPipeline implements IRetrievalPipeline {
|
||||
private ftsIndex = new FullTextSearchCodebaseIndex();
|
||||
private lanceDbIndex: LanceDbIndex | null = null;
|
||||
private lanceDbInitPromise: Promise<void> | null = null;
|
||||
|
||||
constructor(protected readonly options: RetrievalPipelineOptions) {
|
||||
void this.initLanceDb();
|
||||
}
|
||||
|
||||
private async initLanceDb() {
|
||||
protected async initLanceDb() {
|
||||
const embedModel = this.options.config.selectedModelByRole.embed;
|
||||
|
||||
if (!embedModel) {
|
||||
|
|
@ -77,6 +78,23 @@ export default class BaseRetrievalPipeline implements IRetrievalPipeline {
|
|||
);
|
||||
}
|
||||
|
||||
protected async ensureLanceDbInitialized(): Promise<boolean> {
|
||||
if (this.lanceDbIndex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.lanceDbInitPromise) {
|
||||
await this.lanceDbInitPromise;
|
||||
return this.lanceDbIndex !== null;
|
||||
}
|
||||
|
||||
this.lanceDbInitPromise = this.initLanceDb();
|
||||
await this.lanceDbInitPromise;
|
||||
this.lanceDbInitPromise = null; // clear after init
|
||||
|
||||
return this.lanceDbIndex !== null;
|
||||
}
|
||||
|
||||
private getCleanedTrigrams(
|
||||
query: RetrievalPipelineRunArguments["query"],
|
||||
): string[] {
|
||||
|
|
@ -163,7 +181,9 @@ export default class BaseRetrievalPipeline implements IRetrievalPipeline {
|
|||
input: string,
|
||||
n: number,
|
||||
): Promise<Chunk[]> {
|
||||
if (!this.lanceDbIndex) {
|
||||
const initialized = await this.ensureLanceDbInitialized();
|
||||
|
||||
if (!initialized || !this.lanceDbIndex) {
|
||||
console.warn(
|
||||
"LanceDB index not available, skipping embeddings retrieval",
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue