You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add index metadata contract to prevent incompatible provider searches
Store embedding provider, model, and dimensions in SQLite metadata.
Refuse to search if current provider is incompatible with indexed data.
User must run index with force=true to rebuild when provider changes.
-[Search Returns No Results](#search-returns-no-results)
@@ -189,6 +190,47 @@ The next `/index` will rebuild from scratch.
189
190
190
191
---
191
192
193
+
## Embedding Provider Changed
194
+
195
+
**Error message:**
196
+
```
197
+
Index incompatible: <reason>. Run index with force=true to rebuild.
198
+
```
199
+
200
+
**Cause:** The index was built with a different embedding provider or model than what's currently configured. Embeddings from different providers have different dimensions and are not compatible.
201
+
202
+
**Common scenarios:**
203
+
- Switched from GitHub Copilot to OpenAI
204
+
- Changed Ollama embedding model
205
+
- Updated to a new version of the embedding model
206
+
207
+
**Solutions:**
208
+
209
+
### Force Re-index
210
+
Ask the agent:
211
+
> "Force reindex the codebase"
212
+
213
+
Or run `/index` with the force option. This will:
214
+
1. Delete all existing embeddings
215
+
2. Re-index all files with the new provider
216
+
217
+
### Why This Happens
218
+
Different embedding providers produce vectors with different dimensions:
reason: `Dimension mismatch: index has ${storedMetadata.embeddingDimensions}D vectors (${storedMetadata.embeddingProvider}/${storedMetadata.embeddingModel}), but current provider uses ${currentDimensions}D (${currentProvider}/${currentModel}). Run "index --force" to rebuild.`,
424
+
storedMetadata,
425
+
currentProvider,
426
+
currentModel,
427
+
currentDimensions,
428
+
};
429
+
}
430
+
431
+
if(storedMetadata.embeddingModel!==currentModel){
432
+
return{
433
+
compatible: false,
434
+
reason: `Model mismatch: index was built with "${storedMetadata.embeddingModel}", but current model is "${currentModel}". Embeddings may be incompatible. Run "index --force" to rebuild.`,
435
+
storedMetadata,
436
+
currentProvider,
437
+
currentModel,
438
+
currentDimensions,
439
+
};
440
+
}
441
+
442
+
return{
443
+
compatible: true,
444
+
storedMetadata,
445
+
currentProvider,
446
+
currentModel,
447
+
currentDimensions,
448
+
};
449
+
}
450
+
451
+
checkCompatibility(): IndexCompatibility{
452
+
if(this.indexCompatibility){
453
+
returnthis.indexCompatibility;
454
+
}
455
+
return{compatible: true};
456
+
}
457
+
458
+
requiresRebuild(): boolean{
459
+
return!this.checkCompatibility().compatible;
460
+
}
461
+
342
462
privateasyncensureInitialized(): Promise<{
343
463
store: VectorStore;
344
464
provider: EmbeddingProviderInterface;
@@ -750,6 +870,9 @@ export class Indexer {
750
870
751
871
stats.durationMs=Date.now()-startTime;
752
872
873
+
this.saveIndexMetadata(detectedProvider);
874
+
this.indexCompatibility={compatible: true};
875
+
753
876
this.logger.recordIndexingEnd();
754
877
this.logger.info("Indexing complete",{
755
878
files: stats.totalFiles,
@@ -884,6 +1007,11 @@ export class Indexer {
884
1007
name?: string;
885
1008
}>
886
1009
>{
1010
+
constcompatibility=this.checkCompatibility();
1011
+
if(!compatibility.compatible){
1012
+
thrownewError(compatibility.reason??"Index is incompatible with current embedding provider");
0 commit comments