(queryEmbedding: number[], chunks: Chunk[], topK: number)
| 281 | |
| 282 | /** Rank all embedded chunks against a query embedding, best first. */ |
| 283 | export function rankChunks(queryEmbedding: number[], chunks: Chunk[], topK: number): ScoredChunk[] { |
| 284 | return chunks |
| 285 | .filter(c => c.embedding && c.embedding.length > 0) |
| 286 | .map(c => ({ chunk: c, score: cosineSim(queryEmbedding, c.embedding!) })) |
| 287 | .sort((a, b) => b.score - a.score) |
| 288 | .slice(0, topK); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Hybrid rank: semantic (cosine over embeddings) fused with lexical (BM25) via |
no test coverage detected