Problem
The MemoryGraph.hybridSearch() supports multi-hop retrieval, but there's no dedicated medical RAG pipeline that:
- Uses medical context windows (512+ tokens with overlap)
- Applies re-ranking after initial retrieval
- Implements query decomposition for complex medical questions
- Supports evidence citation from retrieved nodes
Proposed Solution
Create lib/src/rag/medical_rag_pipeline.dart that:
-
Extends MemoryPipeline with medical-specific stages:
QueryNormalizationStage - expands abbreviations (TA → tensión arterial)
MedicalQueryDecompositionStage - splits compound queries
HybridRetrievalStage - uses existing hybridSearch with medical config
ReRankingStage - applies cross-encoder re-ranking (needs LLM adapter)
EvidenceCitationStage - attaches source nodes to generated response
-
Create lib/src/rag/medical_prompt_builder.dart:
- Constructs RAG prompts with retrieved context
- Adds medical safety disclaimers
- Handles Spanish medical terminology
Reference
OrionHealth consumer: orionhealth/lib/features/local_agent/infrastructure/rag_llm_service.dart already uses RagLlmService which needs re-ranking support.
Current limitation noted in IsarVectorStoreService.searchWithReRanking() - the TODO says "Implement re-ranking when LLM adapter is configured"
Problem
The
MemoryGraph.hybridSearch()supports multi-hop retrieval, but there's no dedicated medical RAG pipeline that:Proposed Solution
Create
lib/src/rag/medical_rag_pipeline.dartthat:Extends
MemoryPipelinewith medical-specific stages:QueryNormalizationStage- expands abbreviations (TA → tensión arterial)MedicalQueryDecompositionStage- splits compound queriesHybridRetrievalStage- uses existinghybridSearchwith medical configReRankingStage- applies cross-encoder re-ranking (needs LLM adapter)EvidenceCitationStage- attaches source nodes to generated responseCreate
lib/src/rag/medical_prompt_builder.dart:Reference
OrionHealth consumer:
orionhealth/lib/features/local_agent/infrastructure/rag_llm_service.dartalready usesRagLlmServicewhich needs re-ranking support.Current limitation noted in
IsarVectorStoreService.searchWithReRanking()- the TODO says "Implement re-ranking when LLM adapter is configured"