Create a LlamaIndex RAG system with intelligent query routing across multiple document indices and re-ranking.
You are a LlamaIndex expert. Build a multi-index RAG system with query routing. ## Configuration - **Number of Indices**: [NUM_INDICES e.g. 4] - **Index Types**: [INDEX_TYPES e.g. VectorStoreIndex, SummaryIndex, KeywordTableIndex, KnowledgeGraphIndex] - **Data Sources**: [DATA_SOURCES e.g. technical docs, FAQs, API references, tutorials] - **Embedding Model**: [EMBED_MODEL e.g. BAAI/bge-large-en-v1.5] - **Reranker**: [RERANKER e.g. Cohere rerank-v3 / cross-encoder] ## Implementation Requirements ### 1. Index Construction For each data source in [DATA_SOURCES]: - Create appropriate index from [INDEX_TYPES] - Configure node parsers with semantic chunking - Add metadata filters (date, category, author) - Build hierarchical node relationships (parent-child chunks) ### 2. Query Router - Implement LLMSingleSelector router that analyzes user queries - Define routing rules based on query intent: - Factual lookups → KeywordTableIndex - Conceptual questions → VectorStoreIndex - Summarization requests → SummaryIndex - Relationship queries → KnowledgeGraphIndex - Add fallback to ensemble retrieval when confidence is low ### 3. Response Synthesis - Use TreeSummarize for multi-source responses - Apply [RERANKER] to re-rank retrieved nodes - Implement citation tracking with node source references - Add response evaluation using faithfulness and relevancy metrics ### 4. Evaluation Pipeline - Generate synthetic QA pairs from documents - Measure retrieval metrics (MRR, NDCG, Hit Rate) - Track response quality (faithfulness, answer relevancy) - Output evaluation report as structured JSON Provide complete Python code with type hints, error handling, and a CLI interface for indexing and querying.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Llama 4 Maverick.
Fill in parameters for your use case. Run the indexing pipeline first, then test routing with diverse query types to verify correct index selection.
Initial release
Sign in and download this prompt to leave a review.