Asking 5 questions is better than asking 1. Expanding the search net.
User Query: "Why is my screen dark?" Document: "Display brightness settings can be adjusted in the Control Panel."
Semantic Distance: Far. The user used "dark," the doc uses "brightness." The user used "screen," the doc uses "Display."
If you rely on a single query, you rely on a perfect semantic match.
We ask an LLM to generate 3 variations of the user's question.
We then run ALL 3 queries against the vector store. If any of them hits the document, we retrieve it.
from langchain.retrievers.multi_query import MultiQueryRetriever
retriever = MultiQueryRetriever.from_llm(
retriever=vectorstore.as_retriever(),
llm=chat_model
)
# It generates queries, searches all, and creates a unique union of docs.
It solves the "Vocabulary Mismatch" problem. It covers different "Embeddings Neighborhoods" (synonyms often live in different clusters).
Users are bad at prompting. Don't let their poor wording break your retrieval. Expand their intent.
Key Intuition: "Cast a wider net by saying the same thing in different ways."