SupportRAG / tests /test_rag.py
Sakshamyadav15's picture
Revision
e7dfc31
"""
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()