feat(hierarchy): supporto metadati strutturati e gerarchici su Qdrant (parent_id, level, topic, links)
This commit is contained in:
@@ -216,3 +216,97 @@ def test_status_espone_git_commit(client):
|
||||
assert "git_commit" in data
|
||||
assert "version" in data
|
||||
assert "guardrail_version" in data
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Struttura Gerarchica e Relazionale
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_create_and_retrieve_hierarchical_record(client):
|
||||
"""Crea un nodo Root L1 e un nodo Figlio L2 con links, parent_id, level, topic."""
|
||||
# 1. Crea Root L1
|
||||
r_root = client.post(
|
||||
"/v1/memories",
|
||||
json=make_record(
|
||||
text="Master Topic Alfa Romeo",
|
||||
level="L1_ROOT",
|
||||
topic="ALFA-ROMEO/ROOT",
|
||||
),
|
||||
headers=auth_headers(),
|
||||
)
|
||||
assert r_root.status_code == 200
|
||||
root_id = r_root.json()["memory_id"]
|
||||
|
||||
# 2. Crea Figlio L2 collegato
|
||||
r_child = client.post(
|
||||
"/v1/memories",
|
||||
json=make_record(
|
||||
text="Scheda Tecnica Bialbero 1.3",
|
||||
parent_id=root_id,
|
||||
level="L2_SUBTOPIC",
|
||||
topic="ALFA-ROMEO/SPECS",
|
||||
links=[{"target_id": root_id, "predicate": "part_of", "weight": 1.0}],
|
||||
),
|
||||
headers=auth_headers(),
|
||||
)
|
||||
assert r_child.status_code == 200
|
||||
child_id = r_child.json()["memory_id"]
|
||||
|
||||
# 3. Recupera e verifica payload strutturato
|
||||
g = client.get(f"/v1/memories/{child_id}", headers=auth_headers())
|
||||
assert g.status_code == 200
|
||||
data = g.json()
|
||||
assert data["parent_id"] == root_id
|
||||
assert data["level"] == "L2_SUBTOPIC"
|
||||
assert data["topic"] == "ALFA-ROMEO/SPECS"
|
||||
assert len(data["links"]) == 1
|
||||
assert data["links"][0]["target_id"] == root_id
|
||||
|
||||
|
||||
def test_search_filters_hierarchical(client):
|
||||
"""Filtra per parent_id, level e topic."""
|
||||
r_root = client.post(
|
||||
"/v1/memories",
|
||||
json=make_record(text="Root doc", level="L1_ROOT", topic="TOPIC/ROOT"),
|
||||
headers=auth_headers(),
|
||||
)
|
||||
root_id = r_root.json()["memory_id"]
|
||||
|
||||
client.post(
|
||||
"/v1/memories",
|
||||
json=make_record(text="Child A", parent_id=root_id, level="L2_SUBTOPIC", topic="TOPIC/A"),
|
||||
headers=auth_headers(),
|
||||
)
|
||||
client.post(
|
||||
"/v1/memories",
|
||||
json=make_record(text="Child B", parent_id=root_id, level="L2_SUBTOPIC", topic="TOPIC/B"),
|
||||
headers=auth_headers(),
|
||||
)
|
||||
|
||||
# Cerca solo L1_ROOT
|
||||
s1 = client.post(
|
||||
"/v1/memories:search",
|
||||
json={"query": "doc", "level": "L1_ROOT", "top_k": 5, "min_score": 0.0},
|
||||
headers=auth_headers(),
|
||||
)
|
||||
assert s1.status_code == 200
|
||||
assert len(s1.json()["results"]) == 1
|
||||
assert s1.json()["results"][0]["level"] == "L1_ROOT"
|
||||
|
||||
# Cerca per parent_id
|
||||
s2 = client.post(
|
||||
"/v1/memories:search",
|
||||
json={"query": "Child", "parent_id": root_id, "top_k": 5, "min_score": 0.0},
|
||||
headers=auth_headers(),
|
||||
)
|
||||
assert s2.status_code == 200
|
||||
assert len(s2.json()["results"]) == 2
|
||||
|
||||
# Cerca per topic specifico
|
||||
s3 = client.post(
|
||||
"/v1/memories:search",
|
||||
json={"query": "Child", "topic": "TOPIC/A", "top_k": 5, "min_score": 0.0},
|
||||
headers=auth_headers(),
|
||||
)
|
||||
assert s3.status_code == 200
|
||||
assert len(s3.json()["results"]) == 1
|
||||
assert s3.json()["results"][0]["topic"] == "TOPIC/A"
|
||||
|
||||
Reference in New Issue
Block a user