Files
railseek6/debug_documents_response.py

107 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""
Debug the documents endpoint response format
"""
import requests
import json
# Configuration
BASE_URL = "http://localhost:3015"
API_KEY = "jleu1212"
HEADERS = {"X-API-Key": API_KEY}
def debug_documents():
"""Debug the documents endpoint response"""
print("=== DEBUGGING DOCUMENTS ENDPOINT ===")
try:
docs_url = f"{BASE_URL}/documents"
response = requests.get(docs_url, headers=HEADERS)
print(f"Response status: {response.status_code}")
print(f"Response headers: {response.headers}")
print(f"Response content type: {response.headers.get('content-type', 'Unknown')}")
# Try to parse as JSON
try:
data = response.json()
print(f"JSON response type: {type(data)}")
print(f"JSON response: {json.dumps(data, indent=2)}")
# Check if it's a list or dict
if isinstance(data, list):
print(f"Found {len(data)} documents in list")
for i, doc in enumerate(data):
print(f"Document {i}: {doc}")
elif isinstance(data, dict):
print(f"Found dictionary response with keys: {list(data.keys())}")
else:
print(f"Unexpected response type: {type(data)}")
except json.JSONDecodeError as e:
print(f"JSON decode error: {e}")
print(f"Raw response text: {response.text[:500]}...")
except Exception as e:
print(f"Exception: {e}")
def perform_search_directly():
"""Perform search directly without checking documents first"""
print("\n=== PERFORMING SEARCH DIRECTLY ===")
search_queries = [
"artificial intelligence",
"machine learning",
"neural networks",
"computer vision"
]
search_url = f"{BASE_URL}/api/search"
for query in search_queries:
print(f"\n--- Searching: '{query}' ---")
search_data = {
"query": query,
"top_k": 5,
"mode": "hybrid"
}
try:
response = requests.post(search_url, json=search_data, headers=HEADERS)
if response.status_code == 200:
results = response.json()
if "results" in results and results["results"]:
print(f"✅ Found {len(results['results'])} results:")
for i, result in enumerate(results["results"], 1):
score = result.get('score', 0)
text = result.get('text', '')[:200]
source = result.get('metadata', {}).get('source', 'Unknown')
print(f" {i}. Score: {score:.4f}")
print(f" Text: {text}...")
print(f" Source: {source}")
else:
print(" No results found")
else:
print(f" Search failed: {response.status_code} - {response.text}")
except Exception as e:
print(f" Search error: {e}")
def main():
print("Debugging LightRAG Documents and Search")
print("=" * 50)
# Debug documents endpoint
debug_documents()
# Try search directly
perform_search_directly()
if __name__ == "__main__":
main()