""" 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()