( store: SqliteStore, queryVec: number[], topK: number, maxChunks?: number, ownerFilter?: string[], )
| 24 | * When maxChunks > 0, only searches the most recent maxChunks chunks (uses index; avoids full scan as data grows). |
| 25 | */ |
| 26 | export function vectorSearch( |
| 27 | store: SqliteStore, |
| 28 | queryVec: number[], |
| 29 | topK: number, |
| 30 | maxChunks?: number, |
| 31 | ownerFilter?: string[], |
| 32 | ): VectorHit[] { |
| 33 | const all = maxChunks != null && maxChunks > 0 |
| 34 | ? store.getRecentEmbeddings(maxChunks, ownerFilter) |
| 35 | : store.getAllEmbeddings(ownerFilter); |
| 36 | const scored: VectorHit[] = all.map((row) => ({ |
| 37 | chunkId: row.chunkId, |
| 38 | score: cosineSimilarity(queryVec, row.vector), |
| 39 | })); |
| 40 | scored.sort((a, b) => b.score - a.score); |
| 41 | return scored.slice(0, topK); |
| 42 | } |
no test coverage detected