Query Transformations
User queries are often short or poorly phrased. Query transformations rewrite or expand the query to improve retrieval. Techniques include multi‑query, HyDE, and step‑back prompting.
Multi‑Query Retrieval
Generates multiple variations of the query using an LLM, retrieves for each, and combines results. Improves recall for ambiguous queries.
from langchain.retrievers import MultiQueryRetriever
retriever = MultiQueryRetriever.from_llm(retriever=base_retriever, llm=llm)HyDE (Hypothetical Document Embeddings)
Ask the LLM to generate a hypothetical answer (fake document) and use its embedding for retrieval. This bridges the query‑document vocabulary gap.
from langchain.chains import HypotheticalDocumentEmbedder
hyde = HypotheticalDocumentEmbedder(llm=llm, base_embeddings=embeddings)
query_embedding = hyde.embed_query(question)Step‑Back Prompting
First ask a broader, "step‑back" question, retrieve information for that, then use it to answer the original question. Useful for complex reasoning.
When to Use
- User queries are short or ambiguous → Multi‑Query.
- Query and document vocabulary differ → HyDE.
- Complex multi‑step reasoning → Step‑Back.
Two Minute Drill
- Multi‑Query generates query variations for better recall.
- HyDE creates a hypothetical answer to match document vocabulary.
- Step‑Back broadens the query for complex reasoning.
- Choose transformation based on query characteristics.
Need more clarification?
Drop us an email at career@quipoinfotech.com
