Skip to content

Feat: Medical RAG Pipeline with Multi-Hop Search #39

@iberi22

Description

@iberi22

Problem

The MemoryGraph.hybridSearch() supports multi-hop retrieval, but there's no dedicated medical RAG pipeline that:

  1. Uses medical context windows (512+ tokens with overlap)
  2. Applies re-ranking after initial retrieval
  3. Implements query decomposition for complex medical questions
  4. Supports evidence citation from retrieved nodes

Proposed Solution

Create lib/src/rag/medical_rag_pipeline.dart that:

  1. 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
  2. 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions