File size: 2,131 Bytes
5c8e4ec
 
 
 
 
 
 
 
 
 
42d7509
 
5c8e4ec
 
42d7509
 
 
5c8e4ec
 
 
42d7509
 
 
 
5c8e4ec
 
 
 
42d7509
 
5c8e4ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""OnCall AI - Medical RAG System (Backward Compatibility)

This file provides backward compatibility with the original rag.py interface.
Import everything from the new modular structure.
"""

import sys
from pathlib import Path

# Add pdf-version directory to Python path
sys.path.insert(0, str(Path(__file__).parent))

# Import all functions for backward compatibility
from models.embedding_models import load_biomedbert_model, load_meditron_model
from data.loaders import load_annotations, filter_pdf_files
from data.pdf_processing import (
    extract_pdf_text, extract_tables_from_pdf,
    extract_images_ocr_from_pdf, extract_pdf_content_enhanced
)
from indexing.document_indexer import build_document_index, split_text_into_chunks
from indexing.embedding_creator import create_text_embedding, create_tag_embeddings, create_chunk_embeddings
from indexing.storage import save_document_system, load_document_system
from retrieval.document_retriever import (
    find_relevant_documents_top_k, find_relevant_documents_top_p,
    find_relevant_documents_threshold, find_relevant_documents,
    create_document_tag_mapping
)
from retrieval.chunk_retriever import find_relevant_chunks, get_documents_for_rag, get_chunks_for_rag
from demos.demo_runner import build_medical_rag_system, demo_rag_query, demo_all_strategies

# Main function for backward compatibility
def main():
    """Main program entry compatible with original rag.py."""
    try:
        # Build the system with chunk embeddings
        build_medical_rag_system(enable_chunk_embeddings=True)
        
        # Demo chunk-based retrieval
        print("\n" + "="*80)
        print("🧩 CHUNK-BASED RETRIEVAL DEMO")
        print("="*80)
        demo_rag_query("chest pain and shortness of breath", 
                      strategy="top_p", use_chunks=True, top_p=0.8)
        
    except KeyboardInterrupt:
        print("\n\n👋 User interrupted, program exiting")
    except Exception as e:
        print(f"\n❌ Program execution error: {e}")
        import traceback
        traceback.print_exc()


if __name__ == "__main__":
    main()