Advanced Retrieval-Augmented Generation with specialized agents for hybrid search, query classification, answer fusion, and self-correction. Implements SELF-RAG patterns for production-grade RAG systems.
- Hybrid Search - Vector + BM25 + Metadata with RRF fusion
- Query Classification - Adaptive retrieval based on query type
- Answer Fusion - Multi-source synthesis with voting
- Cross-Reference Validation - Fact verification across sources
- Source Citation - APA, MLA, Chicago, IEEE formatting
- Knowledge Gap Detection - Iterative retrieval for missing info
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agentic RAG Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββ β
β β Query β Classify: factual, analytical, β
β β Classification β comparative, procedural β
β ββββββββββ¬ββββββββββ β
β β β
β ββββββββββββββββββββ β
β β Hybrid Search β Vector + BM25 + Metadata β
β β (RRF Fusion) β Reciprocal Rank Fusion β
β ββββββββββ¬ββββββββββ β
β β β
β ββββββββββββββββββββ β
β β Knowledge Gap β Detect missing info β
β β Detection β Trigger re-retrieval β
β ββββββββββ¬ββββββββββ β
β β β
β ββββββββββββββββββββ β
β β Answer Fusion β Combine multiple sources β
β β (Voting/Hybrid) β Consistency analysis β
β ββββββββββ¬ββββββββββ β
β β β
β ββββββββββββββββββββ β
β β Cross-Reference β Verify facts across sources β
β β Validation β β
β ββββββββββ¬ββββββββββ β
β β β
β ββββββββββββββββββββ β
β β Source Citation β APA, MLA, Chicago, IEEE β
β ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
git clone https://github.com/yourusername/agentic-rag-framework.git
cd agentic-rag-framework
pip install -r requirements.txtfrom rag_engine.agents import HybridSearchAgent, QueryClassificationAgent
# Classify query for adaptive retrieval
classifier = QueryClassificationAgent(llm_client=my_llm)
classification = await classifier.execute(QueryClassificationRequest(
query="Compare Python vs JavaScript for web development"
))
print(classification.query_type) # "comparative"
print(classification.suggested_strategy) # "multi_source_comparison"
# Hybrid search with RRF fusion
searcher = HybridSearchAgent(
vector_store=my_vector_db,
keyword_index=my_bm25_index
)
results = await searcher.execute(HybridSearchRequest(
query="machine learning best practices",
semantic_weight=0.5,
keyword_weight=0.3,
metadata_weight=0.2,
fusion_strategy=FusionStrategy.RRF
))Combines vector, keyword, and metadata search with score fusion.
from rag_engine.agents import HybridSearchAgent, FusionStrategy
agent = HybridSearchAgent(vector_store=vs, keyword_index=ki)
result = await agent.execute(HybridSearchRequest(
query="quantum computing applications",
fusion_strategy=FusionStrategy.RRF, # Reciprocal Rank Fusion
use_reranking=True
))Classifies queries by type, complexity, and intent.
from rag_engine.agents import QueryClassificationAgent
agent = QueryClassificationAgent(llm_client=llm)
result = await agent.execute(QueryClassificationRequest(
query="How do I implement a binary search tree?"
))
print(result.classification.query_type) # PROCEDURAL
print(result.classification.complexity) # MODERATE
print(result.classification.intent) # LEARNINGCombines answers from multiple sources using ensemble techniques.
from rag_engine.agents import AnswerFusionAgent, FusionStrategy
agent = AnswerFusionAgent(llm_client=llm)
result = await agent.execute(AnswerFusionRequest(
answers=[answer1, answer2, answer3],
query="What is the capital of France?",
strategy=FusionStrategy.VOTING
))
print(result.fused_answer)
print(result.consistency_score)Validates facts across multiple sources.
from rag_engine.agents import CrossReferenceValidationAgent
agent = CrossReferenceValidationAgent(llm_client=llm)
result = await agent.execute(CrossReferenceRequest(
primary_content="Paris is the capital of France",
reference_sources=[source1, source2, source3]
))
print(result.overall_reliability)
print(result.inconsistencies)Generates properly formatted citations.
from rag_engine.agents import SourceCitationAgent, CitationStyle
agent = SourceCitationAgent()
result = await agent.execute(CitationRequest(
sources=[source1, source2],
style=CitationStyle.APA
))
print(result.bibliography)agentic-rag-framework/
βββ rag_engine/
β βββ __init__.py
β βββ agents/
β βββ hybrid_search_agent.py
β βββ query_classification_agent.py
β βββ answer_fusion_agent.py
β βββ cross_reference_validation_agent.py
β βββ source_citation_agent.py
βββ examples/
βββ tests/
βββ requirements.txt
βββ README.md
MIT License - See LICENSE
Ravi Teja K - AI/ML Engineer
- GitHub: @TEJA4704