AI / LlamaIndex Interview Questions
How does similarity_top_k affect retrieval?
similarity_top_k sets how many of the closest-matching Nodes a vector retriever returns for a given query. A higher value returns more candidate Nodes; a lower value returns fewer.
Raising it tends to improve recall, the chance that the actually relevant Node is somewhere in the retrieved set, especially when relevant information is spread across multiple chunks. But it also increases the number of tokens sent to the LLM, raising cost and latency, and can hurt precision by including marginally relevant or irrelevant Nodes that dilute the synthesizer's attention.
Lowering it keeps prompts tight and cheap but risks missing relevant context entirely if the right Node doesn't make the cut. In practice, teams often set similarity_top_k a bit higher than needed and rely on a node postprocessor like a reranker to trim down to the truly relevant subset before synthesis.
More Related questions...