All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 4s
39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
from fastapi.testclient import TestClient
|
|
from app.main import create_app
|
|
import app.core.database.qdrant_points as qp
|
|
import app.core.graph.graph_subgraph as ga
|
|
|
|
def _fake_search_chunks_by_vector(client, prefix, vector, top=10, filters=None):
|
|
return [
|
|
("chunk:1", 0.8, {"note_id":"note:1","path":"a.md","section_title":"S1"}),
|
|
("chunk:2", 0.6, {"note_id":"note:2","path":"b.md","section_title":"S2"}),
|
|
("chunk:3", 0.4, {"note_id":"note:3","path":"c.md","section_title":"S3"}),
|
|
]
|
|
|
|
def _fake_get_edges_for_sources(client, prefix, source_ids, edge_types=None, limit=2048):
|
|
# Erzeuge ein paar Edges von den Seeds weg
|
|
out=[]
|
|
for sid in source_ids:
|
|
out.append({"source_id":sid,"target_id":f"{sid}->n1","kind":"references","weight":0.2})
|
|
out.append({"source_id":sid,"target_id":f"{sid}->n2","kind":"belongs_to","weight":0.1})
|
|
return out
|
|
|
|
def test_query_hybrid_with_monkeypatch(monkeypatch):
|
|
monkeypatch.setattr(qp, "search_chunks_by_vector", _fake_search_chunks_by_vector)
|
|
monkeypatch.setattr(qp, "get_edges_for_sources", _fake_get_edges_for_sources) # falls indirekt genutzt
|
|
# graph_adapter.expand ruft get_edges_for_sources via qp; wir patchen direkt dort:
|
|
monkeypatch.setattr(ga, "get_edges_for_sources", _fake_get_edges_for_sources, raising=False)
|
|
|
|
app = create_app()
|
|
with TestClient(app) as c:
|
|
payload = {"mode":"hybrid","query_vector":[0.0]*384,"top_k":2,
|
|
"expand":{"depth":1,"edge_types":["references","belongs_to"]}}
|
|
r = c.post("/query", json=payload)
|
|
assert r.status_code == 200, r.text
|
|
data = r.json()
|
|
assert data["used_mode"] == "hybrid"
|
|
assert len(data["results"]) == 2
|
|
# Scores absteigend
|
|
tots = [h["total_score"] for h in data["results"]]
|
|
assert tots[0] >= tots[1]
|