Spaces:
Sleeping
Sleeping
File size: 6,952 Bytes
c627f4d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | {
"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
}
|