Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 6 · 5. Retrieval & RAG Patterns
Lesson 42 of 68

Query Decomposition

Breaking complex questions into solvable parts.

Derpx0610 Jan · 1 min read
LangChain Mastery
The Retriever InterfaceSimilarity vs MMRMulti-Query RetrievalRAG-FusionQuery DecompositionParent Document RetrievalContextual CompressionPost-Retrieval Re-RankingConversational RAG & History
Contents
1. The Multi-Hop Problem2. Decomposition Strategy3. Least-to-Most Prompting4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
The Retriever InterfaceSimilarity vs MMRMulti-Query RetrievalRAG-FusionQuery DecompositionParent Document RetrievalContextual CompressionPost-Retrieval Re-RankingConversational RAG & History
Contents
1. The Multi-Hop Problem2. Decomposition Strategy3. Least-to-Most Prompting4. Summary

1. The Multi-Hop Problem

User Query: "Is the revenue of Apple in 2022 higher than Microsoft's?"

A single vector search fails here. There is no single document comparing Apple and Microsoft revenue for 2022 directly. The answer exists in two documents:

  1. Apple 2022 10-K
  2. Microsoft 2022 10-K

If you search for the whole sentence, you might get neither.

2. Decomposition Strategy

We use an LLM to break the query into independent sub-questions.

Step 1: Decompose

  • Q1: "What was Apple's revenue in 2022?"
  • Q2: "What was Microsoft's revenue in 2022?"

Step 2: Retrieve

  • Search Q1 -> gets Apple Doc ($394B).
  • Search Q2 -> gets MSFT Doc ($198B).

Step 3: Answer

  • The LLM context now has both numbers. It can perform the comparison.

3. Least-to-Most Prompting

For even harder problems, query 2 might depend on the answer to query 1. "Who is the CEO of the company that made the iPhone?"

  1. Q1: "Who made the iPhone?" -> Answer: Apple.
  2. Q2: "Who is the CEO of Apple?" -> Answer: Tim Cook.

This requires a loop (Agentic behavior), not just parallel retrieval.

4. Summary

If your users ask compound questions, simple retrieval is mathematically impossible. You must break the bond.

Key Intuition: "Solve the parts to solve the whole."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonRAG-FusionNext lesson →Parent Document Retrieval