Build an agentic RAG system that performs multi-step retrieval with query decomposition, self-reflection, and adaptive search.
You are an AI systems architect. Build an agentic RAG system with multi-step reasoning. ## Configuration - **Knowledge Base**: [KB e.g. technical documentation / legal corpus / research papers] - **LLM**: [LLM e.g. Claude 4 Opus / GPT-5] - **Vector Store**: [VS e.g. Pinecone / Qdrant / Chroma] - **Framework**: [FRAMEWORK e.g. LangGraph / custom Python] ## Agent Architecture ### 1. Query Analysis Node - Classify query complexity: simple (single retrieval) vs complex (multi-step) - Decompose complex queries into sub-questions - Identify required information types (facts, comparisons, procedures, opinions) - Detect temporal requirements (latest, historical, time-range) - Extract entities and constraints for filtering ### 2. Adaptive Retrieval Node - Strategy selection based on query type: - Direct retrieval for factual queries - Iterative retrieval for exploratory queries - Comparative retrieval for analysis queries - Hierarchical retrieval for deep-dive queries - Dynamic top_k adjustment based on result quality - Re-ranking with cross-encoder scoring - Metadata filtering based on extracted constraints - Fallback to web search when knowledge base insufficient ### 3. Self-Reflection Node - Evaluate retrieved context relevance (0-1 score per chunk) - Identify information gaps in retrieved context - Decide: sufficient to answer, need more retrieval, need clarification - Generate follow-up retrieval queries to fill gaps - Maximum reflection iterations: [MAX_REFLECT e.g. 3] ### 4. Answer Generation Node - Synthesize answer from multiple retrieved contexts - Cite sources with chunk references and confidence - Handle conflicting information across sources - Generate structured output (summary, details, references) - Indicate confidence level and caveats ### 5. Answer Verification Node - Fact-check generated answer against retrieved sources - Detect unsupported claims (hallucination check) - Verify numerical accuracy - Check logical consistency - Flag low-confidence sections for human review ### 6. State Management - LangGraph state schema with typed fields - Conditional edges based on reflection outcomes - Conversation context accumulation across turns - Session persistence for multi-turn interactions Provide the complete agent graph implementation with visualization, evaluation harness, and example conversations.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro.
Set up your vector store with indexed documents. Configure the LLM and retrieval parameters. Test with simple queries first, then progressively complex multi-hop questions. Monitor reflection iterations.
Initial release
Sign in and download this prompt to leave a review.