{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import logging\n", "from qa_backend import DogFoodQASystem\n", "\n", "# Configure logging to show everything\n", "logging.basicConfig(\n", " level=logging.INFO,\n", " format='%(asctime)s - %(levelname)s - %(message)s'\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-01-19 17:56:19,823 - INFO - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Initializing QA System...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-01-19 17:56:20,074 - INFO - \n", "Diagnosing Vector Store:\n", "2025-01-19 17:56:20,082 - INFO - Collection name: dog_food_descriptions\n", "2025-01-19 17:56:20,082 - INFO - Number of documents: 84\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Running Vector Store Diagnostics...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-01-19 17:56:21,233 - INFO - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "2025-01-19 17:56:21,259 - INFO - ✅ Vector store test query successful\n" ] } ], "source": [ "# Initialize the QA system\n", "print(\"Initializing QA System...\")\n", "qa_system = DogFoodQASystem()\n", "\n", "# Run diagnostics\n", "print(\"\\nRunning Vector Store Diagnostics...\")\n", "vector_store_status = qa_system.diagnose_vector_store()\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Testing with query: What's the best premium food for adult dogs?\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-01-19 17:56:37,332 - INFO - \n", "==================================================\n", "Starting hybrid search for query: What's the best premium food for adult dogs?\n", "2025-01-19 17:56:37,335 - INFO - ChromaDB collection info:\n", "2025-01-19 17:56:37,336 - INFO - - Number of documents: 84\n", "2025-01-19 17:56:37,336 - INFO - - Collection name: dog_food_descriptions\n", "2025-01-19 17:56:37,341 - INFO - \n", "BM25 Search Results:\n", "2025-01-19 17:56:37,342 - INFO - Found 5 results\n", "2025-01-19 17:56:37,342 - INFO - \n", "Generating embedding for query...\n", "2025-01-19 17:56:38,091 - INFO - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "2025-01-19 17:56:38,093 - INFO - Embedding generated successfully. Dimension: 1536\n", "2025-01-19 17:56:38,094 - INFO - \n", "Performing ChromaDB search...\n", "2025-01-19 17:56:38,099 - INFO - ChromaDB raw results:\n", "2025-01-19 17:56:38,100 - INFO - - Number of results: 5\n", "2025-01-19 17:56:38,100 - INFO - - Keys in results: dict_keys(['ids', 'distances', 'metadatas', 'embeddings', 'documents', 'uris', 'data'])\n", "2025-01-19 17:56:38,100 - INFO - \n", "Vector result 1:\n", "2025-01-19 17:56:38,100 - INFO - - Score: 0.6637\n", "2025-01-19 17:56:38,100 - INFO - - Text preview: **Introducing Dowolf Snack Para Perro Galletas - The Premium Treat for Your Adult Dog!**\n", "\n", "**Brand:**...\n", "2025-01-19 17:56:38,101 - INFO - \n", "Vector result 2:\n", "2025-01-19 17:56:38,101 - INFO - - Score: 0.6391\n", "2025-01-19 17:56:38,101 - INFO - - Text preview: ### Dogourmet Alimento Seco Para Perro Adulto Carne Parrilla 4kg\n", "\n", "**Elevate Your Dog’s Dining Experi...\n", "2025-01-19 17:56:38,102 - INFO - \n", "Vector result 3:\n", "2025-01-19 17:56:38,102 - INFO - - Score: 0.6388\n", "2025-01-19 17:56:38,102 - INFO - - Text preview: ### Discover the Ultimate in Canine Nutrition with Chunky Alimento Seco Para Perro Adulto Nuggets De...\n", "2025-01-19 17:56:38,103 - INFO - \n", "Vector result 4:\n", "2025-01-19 17:56:38,103 - INFO - - Score: 0.6338\n", "2025-01-19 17:56:38,103 - INFO - - Text preview: **Unleash the Gourmet Experience with Dogourmet Alimento Seco Para Perros Pavo Y Pollo**\n", "\n", "Elevate yo...\n", "2025-01-19 17:56:38,104 - INFO - \n", "Vector result 5:\n", "2025-01-19 17:56:38,104 - INFO - - Score: 0.6328\n", "2025-01-19 17:56:38,104 - INFO - - Text preview: **Introducing Chunky Snack Para Perro Bombonera Deli Dent – The Ultimate Gourmet Snack for Adult Dog...\n", "2025-01-19 17:56:38,105 - INFO - \n", "Processed 5 vector results\n", "2025-01-19 17:56:38,105 - INFO - \n", "Final results distribution:\n", "2025-01-19 17:56:38,105 - INFO - - BM25 results: 5\n", "2025-01-19 17:56:38,106 - INFO - - Vector results: 0\n", "2025-01-19 17:56:38,106 - INFO - ==================================================\n", "2025-01-19 17:56:39,662 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Results Distribution:\n", "- BM25 Results: 5\n", "- Vector Results: 0\n" ] } ], "source": [ "# Test with a sample query\n", "test_query = \"What's the best premium food for adult dogs?\"\n", "print(f\"\\nTesting with query: {test_query}\")\n", "\n", "result = qa_system.process_query(test_query)\n", "\n", "# Display results statistics\n", "bm25_count = sum(1 for r in result['search_results'] if r['source'] == 'BM25')\n", "vector_count = sum(1 for r in result['search_results'] if r['source'] == 'Vector')\n", "\n", "print(f\"\\nResults Distribution:\")\n", "print(f\"- BM25 Results: {bm25_count}\")\n", "print(f\"- Vector Results: {vector_count}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "chats_langchain", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }