dto
This commit is contained in:
parent
34cbc0c0eb
commit
8b5af5ec65
67
tests/test_explanation_smoke.py
Normal file
67
tests/test_explanation_smoke.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import argparse
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Testet die Explanation-Funktion des Retrievers.")
|
||||
parser.add_argument("--url", default="http://localhost:8002/query", help="URL zum Query Endpoint")
|
||||
parser.add_argument("--query", default="mindnet", help="Suchbegriff")
|
||||
args = parser.parse_args()
|
||||
|
||||
payload = {
|
||||
"mode": "hybrid",
|
||||
"query": args.query,
|
||||
"top_k": 1,
|
||||
"explain": True, # Das neue Flag aus WP-04b
|
||||
"expand": {
|
||||
"depth": 1,
|
||||
"edge_types": ["references", "belongs_to", "depends_on", "related_to"]
|
||||
}
|
||||
}
|
||||
|
||||
print(f"--- Sende Request an {args.url} ---")
|
||||
try:
|
||||
r = requests.post(args.url, json=payload)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
except Exception as e:
|
||||
print(f"FEHLER: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
hits = data.get("results", [])
|
||||
if not hits:
|
||||
print("Keine Treffer gefunden.")
|
||||
return
|
||||
|
||||
top_hit = hits[0]
|
||||
print(f"\nTop Treffer: {top_hit.get('node_id')}")
|
||||
print(f"Total Score: {top_hit.get('total_score'):.4f}")
|
||||
|
||||
# Explanation prüfen
|
||||
expl = top_hit.get("explanation")
|
||||
if not expl:
|
||||
print("\n[FAIL] Keine 'explanation' im Response erhalten!")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n--- EXPLANATION LAYER ---")
|
||||
|
||||
bd = expl.get("breakdown", {})
|
||||
print(f"Breakdown:")
|
||||
print(f" Semantic Contribution: {bd.get('semantic_contribution', 0):.4f}")
|
||||
print(f" Edge Contribution: {bd.get('edge_contribution', 0):.4f}")
|
||||
print(f" Centrality Contribution: {bd.get('centrality_contribution', 0):.4f}")
|
||||
print(f" Typ-Gewicht: {bd.get('node_weight', 0):.2f}")
|
||||
|
||||
print("\nReasons:")
|
||||
for reason in expl.get("reasons", []):
|
||||
kind = reason.get("kind", "").upper()
|
||||
msg = reason.get("message", "")
|
||||
impact = reason.get("score_impact")
|
||||
impact_str = f" ({impact:+.4f})" if impact is not None else ""
|
||||
print(f" [{kind}] {msg}{impact_str}")
|
||||
|
||||
print("\n[SUCCESS] Explanation Layer antwortet korrekt.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user