Trainer_LLM/scripts/search_documents.py

32 lines
704 B
Python

import sys
import requests
API_URL = "http://localhost:8000/search"
if len(sys.argv) < 3:
print("❌ Verwendung: python search_documents.py <collection> <suchfrage>")
sys.exit(1)
collection = sys.argv[1]
query = " ".join(sys.argv[2:])
params = {
"query": query,
"collection": collection,
"limit": 5
}
print(f"🔍 Suche in Collection '{collection}': {query}")
try:
response = requests.get(API_URL, params=params)
response.raise_for_status()
results = response.json()
except Exception as e:
print(f"❌ Fehler bei der Anfrage: {e}")
sys.exit(1)
print("📚 Ergebnisse:")
for r in results:
print(f"\n✅ Score: {r['score']:.4f}")
print(f"{r['text']}")