From 4d5d7847e5725a8924e273ec2f7714af3e720cdc Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 3 Dec 2025 10:39:24 +0100 Subject: [PATCH] Dateien nach "tests" hochladen --- tests/test_retriever_weight.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test_retriever_weight.py diff --git a/tests/test_retriever_weight.py b/tests/test_retriever_weight.py new file mode 100644 index 0000000..c08fb40 --- /dev/null +++ b/tests/test_retriever_weight.py @@ -0,0 +1,48 @@ +from app.core import retriever as r +from app.models.dto import QueryRequest +import app.core.qdrant as qdr +import app.core.qdrant_points as qp +import app.services.embeddings_client as ec + + +class _DummyClient: + pass + + +def _fake_get_client(cfg): + return _DummyClient() + + +def _fake_embed_text(text: str): + # Dimension egal, da wir search_chunks_by_vector faken + return [0.0] * 384 + + +def _fake_search_chunks_by_vector_weights(client, prefix, vector, top=10, filters=None): + # Zwei Treffer mit unterschiedlichem retriever_weight + return [ + ("chunk:low", 0.9, {"note_id": "note:low", "path": "low.md", "section_title": "S1", "retriever_weight": 0.2}), + ("chunk:high", 0.8, {"note_id": "note:high", "path": "high.md", "section_title": "S2", "retriever_weight": 1.5}), + ] + + +def test_retriever_weight_influences_ranking(monkeypatch): + # Konfiguration: Qdrant & Embedding faken + monkeypatch.setattr(qdr, "get_client", _fake_get_client) + monkeypatch.setattr(ec, "embed_text", _fake_embed_text) + monkeypatch.setattr(qp, "search_chunks_by_vector", _fake_search_chunks_by_vector_weights) + + req = QueryRequest(mode="semantic", query="karate", top_k=2) + resp = r.semantic_retrieve(req) + + assert len(resp.results) == 2 + + first = resp.results[0] + second = resp.results[1] + + # Semantic Scores: 0.9 (low), 0.8 (high) + # Total Scores: 0.9 * 0.2 = 0.18 vs. 0.8 * 1.5 = 1.2 -> high sollte oben liegen + assert first.note_id == "note:high" + assert second.note_id == "note:low" + + assert first.total_score > second.total_score