Spaces:
Sleeping
Sleeping
| """ | |
| Quick test script for the enhanced dual RAG pipeline | |
| Run this to verify everything works before starting the full app | |
| """ | |
| import sys | |
| from pathlib import Path | |
| # Add src to path | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| from src.core.dual_rag_pipeline import DualStoreRAGPipeline | |
| from src.utils.logger import get_logger | |
| logger = get_logger(__name__) | |
| def main(): | |
| print("="*70) | |
| print("π§ͺ TESTING ENHANCED RAG PIPELINE") | |
| print("="*70) | |
| print() | |
| # Initialize pipeline | |
| print("π¦ Initializing pipeline...") | |
| pipeline = DualStoreRAGPipeline() | |
| print("β Pipeline initialized\n") | |
| # Build vector stores | |
| print("ποΈ Building vector stores...") | |
| print(" - Loading support_faqs.csv") | |
| print(" - Loading HuggingFace dataset (this may take a minute...)") | |
| print(" - Loading support_tickets.csv") | |
| print() | |
| try: | |
| pipeline.build_vector_stores() | |
| print("β Vector stores built successfully\n") | |
| except Exception as e: | |
| print(f"β Error building stores: {e}") | |
| return | |
| # Save stores | |
| print("πΎ Saving vector stores to disk...") | |
| pipeline.save_vector_stores() | |
| print("β Stores saved to data/vector_stores/\n") | |
| # Test queries | |
| test_queries = [ | |
| ("How do I track my order?", "FAQ"), | |
| ("My refund hasn't arrived after 12 days", "Ticket"), | |
| ("I can't log into my account", "Ticket/FAQ"), | |
| ] | |
| print("="*70) | |
| print("π RUNNING TEST QUERIES") | |
| print("="*70) | |
| print() | |
| for i, (query, expected_source) in enumerate(test_queries, 1): | |
| print(f"\n{'β'*70}") | |
| print(f"Test {i}/3: {query}") | |
| print(f"Expected Source: {expected_source}") | |
| print(f"{'β'*70}") | |
| try: | |
| result = pipeline.query(query, top_k=3) | |
| # Display results | |
| print(f"\nπ Answer:") | |
| print(f" {result['answer'][:200]}{'...' if len(result['answer']) > 200 else ''}") | |
| print(f"\nπ Metadata:") | |
| print(f" Source: {result['source']}") | |
| print(f" Confidence: {result['confidence']:.2%}") | |
| print(f" Latency: {result['latency_ms']:.0f}ms") | |
| print(f"\nπ Top Citation:") | |
| if result['citations']: | |
| top = result['citations'][0] | |
| print(f" [{top['source']}] {top['category']}") | |
| print(f" Similarity: {top['similarity']:.2%}") | |
| if 'resolution_status' in top: | |
| print(f" Status: {top['resolution_status']}") | |
| # Verify | |
| if result['source'] in expected_source: | |
| print(f"\nβ PASS: Correct source ({result['source']})") | |
| else: | |
| print(f"\nβ οΈ NOTE: Got {result['source']}, expected {expected_source}") | |
| print(f" (This is OK if confidence was close to threshold)") | |
| except Exception as e: | |
| print(f"\nβ ERROR: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| print(f"\n{'='*70}") | |
| print("β ALL TESTS COMPLETED!") | |
| print("="*70) | |
| print() | |
| print("π Files created:") | |
| print(" β data/vector_stores/faq_store/") | |
| print(" β data/vector_stores/ticket_store/") | |
| print(" β logs/query_logs.jsonl") | |
| print() | |
| print("π Ready to start the application:") | |
| print(" 1. Terminal 1: .\\start_api_enhanced.ps1") | |
| print(" 2. Terminal 2: .\\start_frontend_enhanced.ps1") | |
| print(" 3. Browser: http://localhost:8501") | |
| print() | |
| if __name__ == "__main__": | |
| main() | |