Download scripts/setup_vector_db.py from bmayfield/dutch_test_assistant: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/spaces/bmayfield/dutch_test_assistant/resolve/main/scripts/setup_vector_db.py
- Command line
-
hf download hf://spaces/bmayfield/dutch_test_assistant/scripts/setup_vector_db.py
-
curl -L -o setup_vector_db.py https://huggingface.co/spaces/bmayfield/dutch_test_assistant/resolve/main/scripts/setup_vector_db.py
3.08 kB
| """ | |
| 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() |