Skip to content

Commit ea8e691

Browse files
committed
more debug statements
1 parent 88c48fc commit ea8e691

2 files changed

Lines changed: 62 additions & 18 deletions

File tree

backend/app.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,46 @@ async def options_handler(path: str):
112112
"""Handle CORS preflight requests"""
113113
return {"message": "CORS preflight handled"}
114114

115+
@app.get("/debug/vectorstore")
116+
def debug_vectorstore():
117+
"""Debug endpoint to check vector store status."""
118+
try:
119+
from rag import _get_vectorstore, get_document_count
120+
from vectorstore import vector_count
121+
122+
# Get vector store
123+
vs = _get_vectorstore()
124+
125+
if vs is None:
126+
return {
127+
"status": "error",
128+
"message": "Vector store is None",
129+
"vectorstore_available": False
130+
}
131+
132+
# Get count using different methods
133+
count_method1 = get_document_count()
134+
count_method2 = vector_count(vs)
135+
136+
return {
137+
"status": "ok",
138+
"vectorstore_available": True,
139+
"collection_name": getattr(vs, 'collection_name', 'unknown'),
140+
"client_type": type(vs.client).__name__ if hasattr(vs, 'client') else 'unknown',
141+
"count_method1": count_method1,
142+
"count_method2": count_method2,
143+
"embedding_function_set": hasattr(vs, 'embedding_function') and vs.embedding_function is not None,
144+
"embeddings_set": hasattr(vs, 'embeddings') and vs.embeddings is not None,
145+
"vectorstore_attributes": [attr for attr in dir(vs) if not attr.startswith('_')]
146+
}
147+
148+
except Exception as e:
149+
return {
150+
"status": "error",
151+
"error": str(e),
152+
"vectorstore_available": False
153+
}
154+
115155
@app.get("/debug/env")
116156
def debug_env():
117157
"""Debug endpoint to check environment variables."""

backend/vectorstore.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,47 +174,51 @@ def vector_count(store: Qdrant) -> int:
174174
"""
175175
try:
176176
if store is None:
177+
print("⚠️ Store is None, returning 0")
177178
return 0
178179

180+
print(f"🔍 Getting count for collection: {store.collection_name}")
181+
179182
# Get collection info
180183
collection_info = store.client.get_collection(store.collection_name)
184+
print(f"🔍 Collection info type: {type(collection_info)}")
185+
print(f"🔍 Collection info attributes: {[attr for attr in dir(collection_info) if not attr.startswith('_')]}")
181186

182187
# Try different attributes for count
183188
if hasattr(collection_info, 'vectors_count'):
184189
count = collection_info.vectors_count
185-
print(f"Vector count (vectors_count): {count}")
190+
print(f"Vector count (vectors_count): {count}")
186191
return count
187192
elif hasattr(collection_info, 'points_count'):
188193
count = collection_info.points_count
189-
print(f"Vector count (points_count): {count}")
194+
print(f"Vector count (points_count): {count}")
190195
return count
191196
elif hasattr(collection_info, 'status') and hasattr(collection_info.status, 'vectors_count'):
192197
count = collection_info.status.vectors_count
193-
print(f"Vector count (status.vectors_count): {count}")
198+
print(f"Vector count (status.vectors_count): {count}")
194199
return count
195200
else:
196-
print(f"⚠️ Collection info attributes: {dir(collection_info)}")
197-
return 0
198-
199-
except Exception as e:
200-
print(f"⚠️ Could not get vector count: {e}")
201-
# Try alternative method using search
202-
try:
203-
if hasattr(store, 'client') and hasattr(store, 'collection_name'):
204-
# Try to search for all points to get count
201+
print(f"⚠️ No count attribute found, trying scroll method")
202+
# Try scroll method
203+
try:
205204
result = store.client.scroll(
206205
collection_name=store.collection_name,
207-
limit=10000 # Large limit to get all points
206+
limit=10000
208207
)
209208
if result and hasattr(result, 'points'):
210209
count = len(result.points)
211-
print(f"Vector count (scroll method): {count}")
210+
print(f"Vector count (scroll method): {count}")
212211
return count
213-
except Exception as e2:
214-
print(f"⚠️ Alternative count method failed: {e2}")
212+
except Exception as e3:
213+
print(f"⚠️ Scroll method failed: {e3}")
214+
215+
print(f"⚠️ All count methods failed, returning 0")
216+
return 0
215217

216-
# Final fallback - return 0 if we can't get count
217-
print("⚠️ Using fallback count: 0")
218+
except Exception as e:
219+
print(f"❌ Could not get vector count: {e}")
220+
import traceback
221+
traceback.print_exc()
218222
return 0
219223

220224
def ensure_embedding_function(store: Qdrant, embedding) -> Qdrant:

0 commit comments

Comments
 (0)