79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Debug script to examine search results in detail
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
LIGHTRAG_URL = 'http://localhost:3015'
|
|
API_KEY = 'jleu1212'
|
|
|
|
def debug_search():
|
|
"""Debug search results to understand what's being returned"""
|
|
print("🔍 Debugging Search Results")
|
|
print("=" * 40)
|
|
|
|
headers = {'Content-Type': 'application/json', 'X-API-Key': API_KEY}
|
|
|
|
# Test search for "bee"
|
|
payload = {'query': 'bee', 'top_k': 10, 'mode': 'local'}
|
|
|
|
try:
|
|
response = requests.post(f'{LIGHTRAG_URL}/search', json=payload, headers=headers, timeout=10)
|
|
if response.status_code == 200:
|
|
search_data = response.json()
|
|
print(f"✅ Search response structure: {list(search_data.keys())}")
|
|
|
|
results = search_data.get('results', [])
|
|
print(f"📊 Found {len(results)} results")
|
|
|
|
for i, result in enumerate(results):
|
|
print(f"\n--- Result {i+1} ---")
|
|
print(f"Full result keys: {list(result.keys())}")
|
|
print(f"Score: {result.get('score', 'N/A')}")
|
|
print(f"Source: {result.get('source', 'N/A')}")
|
|
print(f"Document ID: {result.get('document_id', 'N/A')}")
|
|
|
|
content = result.get('content', '')
|
|
print(f"Content length: {len(content)}")
|
|
if content:
|
|
print(f"Content preview: {content[:500]}")
|
|
else:
|
|
print("❌ Content is empty!")
|
|
|
|
else:
|
|
print(f"❌ Search failed: {response.status_code}")
|
|
print(f"Response: {response.text}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
|
|
def check_documents():
|
|
"""Check what documents are in the system"""
|
|
print("\n📄 Checking Document Status")
|
|
print("=" * 40)
|
|
|
|
headers = {'X-API-Key': API_KEY}
|
|
try:
|
|
response = requests.get(f"{LIGHTRAG_URL}/documents", headers=headers)
|
|
if response.status_code == 200:
|
|
doc_data = response.json()
|
|
print(f"Document status keys: {list(doc_data.keys())}")
|
|
|
|
statuses = doc_data.get('statuses', {})
|
|
for status, docs in statuses.items():
|
|
print(f"\n{status}: {len(docs)} documents")
|
|
for doc in docs:
|
|
print(f" - File: {doc.get('file_path', 'Unknown')}")
|
|
print(f" ID: {doc.get('id', 'Unknown')}")
|
|
print(f" Status: {doc.get('status', 'Unknown')}")
|
|
else:
|
|
print(f"❌ Failed to get documents: {response.status_code}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error checking documents: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
debug_search()
|
|
check_documents() |