Once your data is indexed, there are still choices about how to retrieve.
The simple "embed the question, find top K chunks" approach works, but better strategies often help.
Hybrid Search
Pure semantic (embedding-based) search has a weakness: it can miss exact-keyword matches that matter.
If the user asks about "Error 503" and the relevant chunk is the only one that mentions "Error 503" explicitly, semantic search should find it — but might rank a more "vibes-similar" chunk higher.
Hybrid search combines:
- Semantic search (using embeddings)
- Keyword search (using a traditional text-search algorithm like BM25)
Then it merges the results.
For many real-world applications, hybrid search outperforms either approach alone.
Re-ranking
A common pattern:
- Retrieve the top, say, 50 candidate chunks using fast semantic + keyword search.
- Pass all 50 to a smaller, specialized re-ranker model that scores each candidate's relevance to the query more carefully.
- Take the top 5 according to the re-ranker.
This trades a little speed for much higher relevance.
Re-ranker models (like Cohere Rerank or open-source alternatives) read the query and the candidate together, which gives them more context than simple vector similarity.
Query Transformation
Sometimes the user's question, as phrased, doesn't match well to the documents.
Several techniques help:
- Query rewriting: An LLM rewrites the user's question into a cleaner, more searchable form before retrieval.
- HyDE (Hypothetical Document Embeddings): Have an LLM generate a hypothetical answer to the question, embed that, and use it as the search query. This often works surprisingly well because hypothetical answers tend to look more like the real documents than questions do.
- Multi-query: Generate several variations of the question and retrieve for each, then merge results.
Metadata Filtering
If your documents are tagged (by department, date, author, document type, etc.), you can filter retrievals.
"Find chunks similar to this question, but only from documents in the 'engineering' category, last updated this year."
This dramatically improves precision when the corpus is large and varied.
Contextual Compression
After retrieving chunks, you can have a small LLM strip out irrelevant sentences from each chunk before passing the remaining text to the main LLM.
This saves on tokens and reduces noise.