Changesets · Branches · Tags · Compare
| Changeset | a95359706ef42de25c34b528f1684b535200e6634542cddec97853eb422ebfa4 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-17 15:48 +02:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-17 15:48 +02:00 |
| Parents | bc96543ccce6, 195936261ffb |
1 file changed
modified core/context/retrieval/pipelines/BaseRetrievalPipeline.ts +22 −2
| @@ -60,12 +60,13 @@ | ||
| 60 | 60 | export default class BaseRetrievalPipeline implements IRetrievalPipeline { |
| 61 | 61 | private ftsIndex = new FullTextSearchCodebaseIndex(); |
| 62 | 62 | private lanceDbIndex: LanceDbIndex | null = null; |
| 63 | + private lanceDbInitPromise: Promise<void> | null = null; | |
| 63 | 64 | |
| 64 | 65 | constructor(protected readonly options: RetrievalPipelineOptions) { |
| 65 | 66 | void this.initLanceDb(); |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | - private async initLanceDb() { | |
| 69 | + protected async initLanceDb() { | |
| 69 | 70 | const embedModel = this.options.config.selectedModelByRole.embed; |
| 70 | 71 | |
| 71 | 72 | if (!embedModel) { |
| @@ -77,6 +78,23 @@ | ||
| 77 | 78 | ); |
| 78 | 79 | } |
| 79 | 80 | |
| 81 | + protected async ensureLanceDbInitialized(): Promise<boolean> { | |
| 82 | + if (this.lanceDbIndex) { | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | + | |
| 86 | + if (this.lanceDbInitPromise) { | |
| 87 | + await this.lanceDbInitPromise; | |
| 88 | + return this.lanceDbIndex !== null; | |
| 89 | + } | |
| 90 | + | |
| 91 | + this.lanceDbInitPromise = this.initLanceDb(); | |
| 92 | + await this.lanceDbInitPromise; | |
| 93 | + this.lanceDbInitPromise = null; // clear after init | |
| 94 | + | |
| 95 | + return this.lanceDbIndex !== null; | |
| 96 | + } | |
| 97 | + | |
| 80 | 98 | private getCleanedTrigrams( |
| 81 | 99 | query: RetrievalPipelineRunArguments["query"], |
| 82 | 100 | ): string[] { |
| @@ -163,7 +181,9 @@ | ||
| 163 | 181 | input: string, |
| 164 | 182 | n: number, |
| 165 | 183 | ): Promise<Chunk[]> { |
| 166 | - if (!this.lanceDbIndex) { | |
| 184 | + const initialized = await this.ensureLanceDbInitialized(); | |
| 185 | + | |
| 186 | + if (!initialized || !this.lanceDbIndex) { | |
| 167 | 187 | console.warn( |
| 168 | 188 | "LanceDB index not available, skipping embeddings retrieval", |
| 169 | 189 | ); |