All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 4s
142 lines
4.0 KiB
Python
142 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
FILE: scripts/wp04_smoketest.py
|
|
VERSION: 2.1.0 (2025-12-15)
|
|
STATUS: Active (Test-Tool)
|
|
COMPATIBILITY: v2.9.1 (Post-WP14/WP-15b)
|
|
|
|
Zweck:
|
|
-------
|
|
E2E-Schnelltest der WP-04 Endpunkte (/query und /graph).
|
|
Validiert grundlegende Funktionalität der Retrieval- und Graph-APIs.
|
|
|
|
Funktionsweise:
|
|
---------------
|
|
1. Holt exemplarischen Chunk-Vektor aus Qdrant
|
|
2. Ruft POST /query mit Test-Query auf
|
|
3. Ruft GET /graph/<note_id> für Top-Note auf
|
|
4. Gibt Kurzresultate aus
|
|
|
|
Ergebnis-Interpretation:
|
|
------------------------
|
|
- Ausgabe: Test-Ergebnisse
|
|
* query_result: Ergebnis des /query Aufrufs
|
|
* graph_result: Ergebnis des /graph Aufrufs
|
|
* status: ok/error
|
|
- Exit-Code 0: Alle Tests bestanden
|
|
- Exit-Code 1: Fehler (z.B. API nicht erreichbar, keine Daten)
|
|
|
|
Verwendung:
|
|
-----------
|
|
- Schnelle Validierung nach Deployment
|
|
- CI/CD-Tests
|
|
- Debugging von API-Problemen
|
|
|
|
Hinweise:
|
|
---------
|
|
- Benötigt vorhandene Daten in Qdrant
|
|
- Testet nur grundlegende Funktionalität
|
|
|
|
Aufruf:
|
|
-------
|
|
python3 scripts/wp04_smoketest.py --api http://localhost:8000
|
|
|
|
Parameter:
|
|
----------
|
|
--api URL Base-URL der mindnet API (Default: http://localhost:8000)
|
|
|
|
Umgebungsvariablen:
|
|
-------------------
|
|
QDRANT_URL (Default: http://localhost:6333)
|
|
MINDNET_PREFIX (Default: mindnet)
|
|
|
|
Änderungen:
|
|
-----------
|
|
v2.1.0 (2025-12-15): Dokumentation aktualisiert
|
|
v0.1.0 (2025-10-07): Initial Release
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
import os
|
|
import sys
|
|
import json
|
|
import argparse
|
|
import requests
|
|
from qdrant_client import QdrantClient
|
|
|
|
|
|
def get_any_chunk_vector(client: QdrantClient, prefix: str):
|
|
"""Holt eine beliebige Chunk-Vector/Note-ID-Kombi aus Qdrant (falls vorhanden)."""
|
|
col = f"{prefix}_chunks"
|
|
pts, _ = client.scroll(collection_name=col, limit=1, with_vectors=True, with_payload=True)
|
|
if not pts:
|
|
return None, None, None
|
|
p = pts[0]
|
|
vec = p.vector
|
|
payload = p.payload or {}
|
|
node_id = str(p.id)
|
|
note_id = payload.get("note_id")
|
|
return vec, node_id, note_id
|
|
|
|
|
|
def run(api_base: str, qdrant_url: str, prefix: str) -> int:
|
|
print(f"[i] API: {api_base}")
|
|
print(f"[i] Qdrant: {qdrant_url}")
|
|
client = QdrantClient(url=qdrant_url)
|
|
|
|
vec, node_id, note_id = get_any_chunk_vector(client, prefix)
|
|
if vec is None:
|
|
print("[!] Keine Chunks mit Vektoren gefunden. Bitte Import (WP-03) prüfen.")
|
|
return 2
|
|
|
|
print(f"[i] Beispiel-Chunk-ID: {node_id}, Note-ID: {note_id}")
|
|
print("[i] Rufe /query (hybrid) mit Beispielvektor auf ...")
|
|
|
|
q_payload = {
|
|
"mode": "hybrid",
|
|
"query_vector": vec, # 384d
|
|
"top_k": 5,
|
|
"expand": {"depth": 1, "edge_types": ["references", "belongs_to", "prev", "next"]},
|
|
}
|
|
r = requests.post(f"{api_base.rstrip('/')}/query", json=q_payload, timeout=60)
|
|
print(f"[i] /query Status: {r.status_code}")
|
|
if r.status_code != 200:
|
|
print(r.text)
|
|
return 3
|
|
|
|
data = r.json()
|
|
hits = data.get("results", [])
|
|
print(f"[i] Treffer: {len(hits)}")
|
|
for i, h in enumerate(hits, 1):
|
|
print(f" {i:02d}. node_id={h['node_id']} note_id={h.get('note_id')} total={h['total_score']:.3f}")
|
|
|
|
# Graph-Test (wenn Note-ID vorhanden)
|
|
gid = note_id or (hits[0].get("note_id") if hits else None)
|
|
if gid:
|
|
print(f"[i] Rufe /graph/{gid} ...")
|
|
r2 = requests.get(f"{api_base.rstrip('/')}/graph/{gid}?depth=1", timeout=60)
|
|
print(f"[i] /graph Status: {r2.status_code}")
|
|
if r2.status_code == 200:
|
|
g = r2.json()
|
|
print(f" Nodes: {len(g.get('nodes', []))}, Edges: {len(g.get('edges', []))}")
|
|
else:
|
|
print(r2.text)
|
|
|
|
print("[✔] Smoke-Test abgeschlossen.")
|
|
return 0
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--api", default="http://localhost:8000", help="Basis-URL der FastAPI.")
|
|
args = ap.parse_args()
|
|
|
|
qdrant_url = os.getenv("QDRANT_URL", "http://127.0.0.1:6333")
|
|
prefix = os.getenv("MINDNET_PREFIX", "mindnet")
|
|
sys.exit(run(args.api, qdrant_url, prefix))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|