parse incorrectly formatted vectors so we can salvage broken indexes

This commit is contained in:
Nate 2025-07-05 09:53:53 -07:00
parent a1d830e381
commit de2d0c187f
2 changed files with 18 additions and 2 deletions

View file

@ -234,6 +234,23 @@ export class LanceDbIndex implements CodebaseIndex {
return results;
}
/**
* Due to a bug in indexing, some indexes have vectors
* without the surrounding []. These would fail to parse
* but this allows such existing indexes to function properly
*/
private parseVector(vector: string): number[] {
try {
return JSON.parse(vector);
} catch (err) {
try {
return JSON.parse(`[${vector}]`);
} catch (err2) {
throw new Error(`Failed to parse vector: ${vector}`, { cause: err2 });
}
}
}
async *update(
tag: IndexTag,
results: RefreshIndexResults,
@ -297,7 +314,7 @@ export class LanceDbIndex implements CodebaseIndex {
const lanceRows: LanceDbRow[] = [];
for (const item of cachedItems) {
try {
const vector = JSON.parse(item.vector);
const vector = this.parseVector(item.vector);
const { uuid, startLine, endLine, contents } = item;
lanceRows.push({

View file

@ -405,7 +405,6 @@ export const sessionSlice = createSlice({
}
} else if (message.role === "thinking" && message.signature) {
if (lastMessage.role === "thinking") {
console.log("add signature", message.signature);
lastMessage.signature = message.signature;
}
} else if (