Chunks preview

This commit is contained in:
Pavel committed 2026-07-13 23:22:17 +03:00
1 parent 73c3dfb5c4
commit 0447eb9b8d
33 files changed
+1961 -109

No files matched your search

+37
View File
@@ -287,3 +287,40 @@ class TestMongoDBVectorStoreDeleteChunk:
result = store.delete_chunk("bad_id")
assert result is False
@pytest.mark.unit
class TestMongoDBSearchWithScores:
def test_reports_vector_search_score(self):
store, mock_collection, _ = _make_mongodb_store()
mock_collection.aggregate.return_value = iter(
[
{
"_id": "id1",
"text": "hello",
"embedding": [0.1],
"source": "a",
"_score": 0.83,
}
]
)
results = store.search_with_scores("query", k=1)
assert store.score_kind == "cosine_similarity"
assert results[0][0].page_content == "hello"
assert results[0][1] == pytest.approx(0.83)
# The score must not leak into metadata — it rides alongside the doc.
assert "_score" not in results[0][0].metadata
def test_score_is_added_even_without_a_threshold(self):
"""The $addFields stage is unconditional, so an unfiltered search still
carries a score (the whole point of the retrieval tester)."""
store, mock_collection, _ = _make_mongodb_store()
mock_collection.aggregate.return_value = iter([])
store.search_with_scores("query", k=1)
pipeline = mock_collection.aggregate.call_args[0][0]
assert any("$addFields" in stage for stage in pipeline)
assert not any("$match" in stage for stage in pipeline)