import logging import os import sys from datetime import datetime # Adjust the path to import from the root directory sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from retrieval_manager import RetrievalManager # Configure logging logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') # --- Test Configuration --- DB_PATH = "./chroma_db" EMBEDDING_MODEL = 'BAAI/bge-large-en-v1.5' REPORT_DIR = "./logs" REPORT_FILE = os.path.join(REPORT_DIR, f"retrieval_evaluation_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.html") # The test set of queries from the retrieval plan EVALUATION_QUERIES = [ { "id": 1, "query": "What laptops do you have?", "expected_collections": ["products"], "notes": "Should return a variety of laptops from the products collection." }, { "id": 2, "query": "Do you have any Gaming laptops?", "expected_collections": ["products"], "notes": "Should return laptops with 'gaming' in their description or specs." }, { "id": 3, "query": "What Lightweight laptops do you have", "expected_collections": ["products"], "notes": "Pure semantic search. Should find laptops described as lightweight, portable, etc." }, { "id": 4, "query": "Budget camera under $300", "expected_collections": ["products"], "notes": "Filters by price (< 300) and performs semantic search for 'Budget camera'." }, { "id": 5, "query": "Share more details on SmartX ProPhone camera reviews", "expected_collections": ["reviews"], "notes": "Should retrieve reviews specifically for the 'SmartX ProPhone'." }, { "id": 6, "query": "What do customers say about battery life of TechPro Ultrabook?", "expected_collections": ["reviews"], "notes": "Semantic search on reviews. Should find reviews mentioning battery about TechPro Ultrabook." }, { "id": 7, "query": "What TV under $500 do you have?", "expected_collections": ["products"], "notes": "Filters by price (< 500) and performs semantic search for 'What TV do you have?'." }, { "id": 8, "query": "What Audio products do you have", "expected_collections": ["products"], "notes": "Should retrieve products from the 'Audio' category." }, { "id": 9, "query": "Customer complaints about Ultrabook", "expected_collections": ["reviews"], "notes": "Should find negative reviews (complaints) for products named 'Ultrabook'." }, { "id": 10, "query": "Compare GameSphere X and Y", "expected_collections": ["products", "reviews"], "notes": "Should retrieve specs for both products and potentially reviews comparing them." } ] def generate_report_header(): """Generates the header for the HTML report.""" header = f"""
Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
Database Path: {DB_PATH}
Embedding Model: {EMBEDDING_MODEL}
The Dist. value represents the dissimilarity between the query and the retrieved document. A lower value is better, indicating higher semantic relevance.
| Query ID | Query | Expected | Retrieved | Pass/Fail | Notes |
|---|