Vector Retrieval and Top-K
Vector retrieval embeds a query and finds nearby document vectors. TopK controls candidate count: too few can miss evidence, while too many can add noise, latency, and cost. Tune with recall and answer-quality measurements. Apply trusted filters and treat low-relevance results as a reason to abstain rather than forcing an answer.
Capture candidate IDs, scores, and filter metadata in evaluation traces so retrieval failures are reproducible.
Implementation example
const candidates = await vectorStore.search({
vector: queryEmbedding, topK: 20, filter: trustedFilter
});💡 The API is illustrative; topK is an experiment parameter, not a universal default.
Key Takeaways
- Inspect the relevant pipeline stage instead of guessing.
- Preserve source provenance, versions, and access scope.
- Measure quality on representative queries.
Knowledge Check
What is the risk of always increasing topK?