mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-19 08:28:06 +02:00
fix(wiki): ignore empty embedding vectors
This commit is contained in:
parent
7a86aa9ddc
commit
77dce6fdb3
3 changed files with 56 additions and 2 deletions
|
|
@ -82,6 +82,14 @@ describe('SqliteKnowledgeIndex', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('does not treat empty embeddings as indexed semantic vectors', () => {
|
||||
const index = new SqliteKnowledgeIndex({ dbPath });
|
||||
index.sync([page({ path: 'knowledge/global/revenue.md', key: 'revenue', embedding: [] })]);
|
||||
|
||||
expect(index.getExistingPages().get('knowledge/global/revenue.md')?.embedding).toBeNull();
|
||||
expect(index.searchSemanticCandidates({ queryEmbedding: [1, 0], limit: 10 })).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns semantic lane candidates from stored page embeddings', () => {
|
||||
const index = new SqliteKnowledgeIndex({ dbPath });
|
||||
index.sync([
|
||||
|
|
|
|||
|
|
@ -75,7 +75,9 @@ function parseEmbedding(raw: string | null): number[] | null {
|
|||
}
|
||||
try {
|
||||
const embedding = JSON.parse(raw) as unknown;
|
||||
return Array.isArray(embedding) && embedding.every((value) => typeof value === 'number') ? embedding : null;
|
||||
return Array.isArray(embedding) && embedding.length > 0 && embedding.every((value) => typeof value === 'number')
|
||||
? embedding
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -170,7 +172,7 @@ export class SqliteKnowledgeIndex {
|
|||
content: searchText,
|
||||
tags: page.tags.join(' '),
|
||||
searchText,
|
||||
embeddingJson: page.embedding ? JSON.stringify(page.embedding) : null,
|
||||
embeddingJson: page.embedding && page.embedding.length > 0 ? JSON.stringify(page.embedding) : null,
|
||||
};
|
||||
upsertPage.run(row);
|
||||
deleteFts.run(row);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue