Concept Flow - Multi-query retrieval for better recall
User Input Query
↓
Split into Multiple Queries
↓
Send Each Query to Retriever
↓
Collect Multiple Results
↓
Combine Results
↓
Return Enhanced Recall Output
The process splits one query into several, retrieves results for each, then combines them to improve recall.
Execution Sample
LangChain
queries = ['query part 1', 'query part 2']
results = []
for q in queries:
res = retriever.get_relevant_documents(q)
results.extend(res)
combined = combine_results(results)
This code runs multiple queries separately, collects all results, and merges them for better recall.
Execution Table
Step
Action
Query
Retriever Output
Results Collected
1
Split main query
Full query → ['query part 1', 'query part 2']
N/A
[]
2
Send first query
query part 1
Docs A, B
[Docs A, B]
3
Send second query
query part 2
Docs C
[Docs A, B, C]
4
Combine results
N/A
N/A
[Docs A, B, C]
5
Return combined output
N/A
N/A
[Docs A, B, C]
💡 All queries processed and results combined for final output.
Variable Tracker
Variable
Start
After Step 2
After Step 3
Final
queries
[]
['query part 1', 'query part 2']
['query part 1', 'query part 2']
['query part 1', 'query part 2']
results
[]
[Docs A, B]
[Docs A, B, C]
[Docs A, B, C]
combined
N/A
N/A
N/A
[Docs A, B, C]
Key Moments - 3 Insights
Why do we split one query into multiple smaller queries?
Splitting helps the retriever focus on different aspects, increasing the chance to find more relevant documents, as shown in steps 2 and 3 where separate queries return different documents.
How do we avoid duplicate documents in combined results?
After collecting results from each query, we can filter duplicates before combining, ensuring the final list (step 4) has unique documents.
What happens if one query returns no results?
The results list still collects documents from other queries; an empty result for one query doesn't stop the process, as seen in step 3 where results are added only if found.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what documents are collected after step 3?
A[Docs A, B]
B[Docs A, B, C]
C[Docs C]
D[]
💡 Hint
Check the 'Results Collected' column at step 3 in the execution table.
At which step does the retriever process the second query?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Query' columns in the execution table for step 3.
If the first query returned no documents, how would the 'results' variable look after step 2?
A[]
B[Docs A, B]
C[Docs C]
D['query part 1']
💡 Hint
Refer to the 'results' variable values in variable_tracker after step 2.
Concept Snapshot
Multi-query retrieval splits one question into parts.
Each part is sent separately to the retriever.
Results from all parts are collected and combined.
This improves recall by covering more angles.
Duplicates should be removed before final output.
Full Transcript
Multi-query retrieval means breaking a single user query into multiple smaller queries. Each smaller query is sent to the retriever to find relevant documents. The results from all queries are collected and combined to improve the chance of finding all useful information. This process helps recall because different queries can catch different relevant documents. After collecting, duplicates are removed to keep the output clean. If one query returns no results, others still contribute to the final combined output.
Practice
(1/5)
1. What is the main purpose of multi-query retrieval in langchain?
easy
A. To store data in multiple vector stores
B. To reduce the number of queries sent to the database
C. To speed up the response time by using a single query
D. To ask several related questions to get better search results
Solution
Step 1: Understand the concept of multi-query retrieval
Multi-query retrieval involves asking multiple related questions instead of just one to improve the quality of search results.
Step 2: Identify the main goal of this approach
The goal is to get better and more complete search results by combining answers from several queries.
Final Answer:
To ask several related questions to get better search results -> Option D
Quick Check:
Multi-query retrieval = multiple related questions for better results [OK]
Thinking get_relevant_documents needs no arg when it does
Assuming vectorstore undefined without context
5. You want to improve recall for a complex topic by using multi-query retrieval with three related queries. Which approach best ensures you get the most relevant documents without duplicates?
hard
A. Use MultiQueryRetriever.from_llm(retriever, llm) to generate multiple queries and deduplicate results
B. Run each query separately and pick the first result from each
C. Combine all queries into one long string and run a single query
D. Use only the query with the highest expected relevance
Solution
Step 1: Understand multi-query retrieval goal
It aims to combine results from multiple related queries to improve recall.
Step 2: Identify best practice to avoid duplicates
Using MultiQueryRetriever.from_llm(retriever, llm) generates multiple queries via LLM and deduplicates results for completeness without repeats.
Final Answer:
Use MultiQueryRetriever.from_llm(retriever, llm) to generate multiple queries and deduplicate results -> Option A
Quick Check:
MultiQueryRetriever generates + deduplicates = best recall [OK]
Hint: MultiQueryRetriever generates queries then deduplicates for best recall [OK]
Common Mistakes:
Running queries separately without combining results
Merging queries into one string loses query specificity
Using only one query misses relevant documents
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.