sagar008 commited on
Commit
6b496b9
·
verified ·
1 Parent(s): 113cf8e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -3
main.py CHANGED
@@ -184,22 +184,43 @@ async def debug_pinecone_storage(document_id: str):
184
  include_metadata=True
185
  )
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  return {
188
  "document_id": document_id,
189
  "pinecone_index": vector_store.index_name,
190
  "vectors_found": len(query_response.matches),
191
- "index_stats": index.describe_index_stats(),
192
  "matches": [
193
  {
194
  "id": match.id,
195
- "score": match.score,
196
- "metadata": match.metadata
197
  }
198
  for match in query_response.matches[:3]
199
  ]
200
  }
201
 
202
  except Exception as e:
 
203
  return {"error": f"Pinecone debug failed: {str(e)}"}
204
 
205
  @app.post("/debug_retrieval")
 
184
  include_metadata=True
185
  )
186
 
187
+ # Get index stats separately and extract only serializable data
188
+ try:
189
+ stats = index.describe_index_stats()
190
+ index_info = {
191
+ "total_vector_count": getattr(stats, 'total_vector_count', 0),
192
+ "dimension": getattr(stats, 'dimension', 768),
193
+ "index_fullness": getattr(stats, 'index_fullness', 0.0),
194
+ "namespaces": {}
195
+ }
196
+
197
+ # Safely extract namespace info if it exists
198
+ if hasattr(stats, 'namespaces') and stats.namespaces:
199
+ for ns_name, ns_data in stats.namespaces.items():
200
+ index_info["namespaces"][ns_name] = {
201
+ "vector_count": getattr(ns_data, 'vector_count', 0)
202
+ }
203
+ except Exception as stats_error:
204
+ print(f"⚠️ Stats extraction failed: {stats_error}")
205
+ index_info = {"error": "Could not retrieve index stats"}
206
+
207
  return {
208
  "document_id": document_id,
209
  "pinecone_index": vector_store.index_name,
210
  "vectors_found": len(query_response.matches),
211
+ "index_stats": index_info,
212
  "matches": [
213
  {
214
  "id": match.id,
215
+ "score": float(match.score) if match.score else 0.0,
216
+ "metadata": dict(match.metadata) if match.metadata else {}
217
  }
218
  for match in query_response.matches[:3]
219
  ]
220
  }
221
 
222
  except Exception as e:
223
+ print(f"❌ Pinecone debug error: {e}")
224
  return {"error": f"Pinecone debug failed: {str(e)}"}
225
 
226
  @app.post("/debug_retrieval")