File size: 3,084 Bytes
c40af6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
One-time setup script to process PDF documents and initialize vector database.
Run this after adding your PDF documents to knowledge_base/pdfs/
"""

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from app.dutch_chatbot.document_processor import DocumentProcessor
from app.dutch_chatbot.vector_store import VectorStore
from app.dutch_chatbot.config import Config
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def main():
    print("🧬 DUTCH Test Assistant Vector Database Setup")
    print("=" * 50)

    try:
            config = Config()
            config.validate()
    except ValueError as e:
        print(f"❌ Configuration error: {e}")
        print("Please check your .env file and ensure ANTHROPIC_API_KEY is set.")
        return

    # Check if PDF directory exists
    if not os.path.exists(config.PDF_DATA_PATH):
        print(f"❌ PDF directory not found: {config.PDF_DATA_PATH}")
        print("Please create the directory and add your medical test PDF documents.")
        return
    
    # Check for PDF files
    pdf_files = [f for f in os.listdir(config.PDF_DATA_PATH) if f.lower().endswith('.pdf')]
    if not pdf_files:
        print(f"❌ No PDF files found in {config.PDF_DATA_PATH}")
        print("Please add your medical test PDF documents to the directory.")
        print("Or run: uv run python scripts/add_sample_data.py to create sample documents")
        return

    print(f"πŸ“„ Found {len(pdf_files)} PDF files:")
    for pdf in pdf_files:
        print(f"   - {pdf}")

    # Initialize components
    print("\nπŸ”„ Processing documents...")
    processor = DocumentProcessor()

    # Process all PDFs
    chunks = processor.process_all_pdfs()
    
    if not chunks:
        print("❌ No text chunks created. Please check your PDF files.")
        return
    
    # Save processed chunks
    processor.save_processed_chunks(chunks)

    # Initialize vector store
    print("\nπŸ”„ Setting up vector database...")
    vector_store = VectorStore()
    vector_store.create_collection()

    # Add documents to vector database
    vector_store.add_documents(chunks)

    # Verify setup
    info = vector_store.get_collection_info()
    print(f"\nβœ… Setup complete!")
    print(f"πŸ“Š Vector database info:")
    print(f"   - Documents: {info.get('document_count', 'Unknown')}")
    print(f"   - Collection: {info.get('collection_name', 'Unknown')}")

    # Test search
    print("\nπŸ§ͺ Testing search functionality...")
    test_query = "blood test"
    results = vector_store.search(test_query, top_k=2)
    print(f"Test query: '{test_query}'")
    print(f"Found {len(results)} relevant documents")
    
    if results:
        print("Sample result:")
        print(f"   Source: {results[0]['metadata'].get('source', 'Unknown')}")
        print(f"   Text preview: {results[0]['text'][:100]}...")

    print("\nπŸŽ‰ Ready to run the DUTCH Test Assistant!")
    print("Run: uv run python app/interfaces/gradio_app.py")

if __name__ == "__main__":
    main()