
Strategy Selection: Which Pattern for Which Question?
Become a Graph RAG architect. Learn how to classify user intent and dynamically select between Neighborhood, Path, Temporal, and Global retrieval strategies for the best AI response.
Strategy Selection: Which Pattern for Which Question?
We have a toolbox full of powerful retrieval strategies. But a master craftsman knows that the tool depends on the task. If you use "Neighborhood Retrieval" for a "Global Relationship" question, your AI will be too granular. If you use "Global Summarization" for a "Specific Path" question, your AI will be too vague.
In this final lesson of Module 9, we will build a Retrieval Router. We will learn how to classify user questions into Intent Categories and map those categories to the optimal graph retrieval pattern. This is the logic that lives inside the "Brain" of your Agentic RAG system.
1. The Retrieval Decision Matrix
| Question Type | Intent | Optimal Strategy |
|---|---|---|
| "Who is sSudeep?" | Entity Details | Neighborhood Expansion |
| "How are A and B related?" | Bridge/Influence | Path-Based Retrieval |
| "What happened after X?" | History/Causality | Temporal/Sequence Retrieval |
| "What are the main risks?" | High-Level Insight | Community Summarization |
| "Find projects like X" | Semantic Discovery | Similarity-Driven Search |
2. The Router Agent Architecture
In a production system, you put an "Intent Classifier" (a small, fast LLM like GPT-3.5 or Gemini Flash) at the front of the pipeline.
- User Question: "Draft a summary of why the Tokyo project failed."
- Classifier: "This looks like a combination of a Path (Tokyo project -> Failure event) and a Neighborhood (Context around Tokyo)."
- Orchestrator: Runs both queries in parallel and merges the results into a single context block.
3. Designing for Multimodal Intent
Some questions require Multiple Strategies in a sequence.
- "Summarize the last 3 months (Temporal) for the top 5 projects (Neighborhood) in the Finance community (Global)."
This is the "Boss Fight" of Graph RAG. It requires an Agentic Loop (which we will build in Module 10) that can decompose the question into multiple graph calls.
graph TD
Q[User Question] --> R[Router Agent]
R -->|Entity?| S1[Neighborhood Strategy]
R -->|Relationship?| S2[Path Strategy]
R -->|Trends?| S3[Global Strategy]
S1 & S2 & S3 -->|Raw Facts| C[Context Assembler]
C -->|Augmented Prompt| LLM[Final LLM Answer]
style R fill:#f4b400,color:#fff
style LLM fill:#34A853,color:#fff
4. Implementation: A Simple Intent Router in Python
def select_strategy(user_query):
# This would typically be an LLM call
# For now, we use keyword mapping for demonstration
query_lower = user_query.lower()
if "how is" in query_lower and "related to" in query_lower:
return "PATH_STRATEGY"
if "summary" in query_lower or "overall" in query_lower:
return "GLOBAL_STRATEGY"
if "tell me about" in query_lower:
return "NEIGHBORHOOD_STRATEGY"
return "SEMANTIC_STRATEGY"
# USAGE
question = "How is Sudeep related to the Tokyo budget?"
strategy = select_strategy(question)
print(f"Executing: {strategy}")
# RESULT: PATH_STRATEGY
5. Summary and Exercises
Strategy selection is the "Intelligence" of the retrieval layer.
- Neighborhoods provide the portrait.
- Paths provide the evidence.
- Temporal provides the timeline.
- Global provides the perspective.
- Routing ensures the user gets the right context at the right time.
Exercises
- Intent Classification: Pick a random question from a customer support log. Which of the 5 strategies would you use? Is it a "Hybrid" question?
- The "Failure" Cost: What happens to the AI's answer if you use "Path Retrieval" for a "Who is..." question? Why is it less helpful?
- Visual Logic: Draw a flow chart for a system that first checks for a "Neighborhood" and, if it finds a specific dependency, automatically triggers a "Path" search to investigate that dependency.
Congratulations! You have completed Module 9: Graph RAG Retrieval Strategies. You now have the tactical knowledge to retrieve any kind of context.
In Module 10: Advanced Retrieval with LangChain and LangGraph, we will stop writing Python skeletons and start building actual autonomous agents.