mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-04 07:30:21 +00:00
test(search): keep zero embedding rankings finite
Add tests for zero embeddings in vector search and legacy JSON loading.
This commit is contained in:
parent
c70d22f2ad
commit
4a492c5355
1 changed files with 21 additions and 0 deletions
|
|
@ -522,6 +522,27 @@ async def test_vector_search_batches_candidates_and_preserves_stable_ties(monkey
|
|||
assert [result.id for result in results] == ["0", "1", "2"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("zero_query", [False, True])
|
||||
async def test_vector_search_zero_embeddings_have_finite_scores(zero_query):
|
||||
"""Zero float16 embeddings do not leak NaN scores into local search ranking."""
|
||||
store = LocalFileStore(name="t_vector_zero", embedding_store="")
|
||||
store.embedding_store = FakeEmbeddingStore()
|
||||
query = np.array([0.0, 0.0] if zero_query else [1.0, 0.0], dtype=np.float16)
|
||||
store.embedding_store.get_embedding = AsyncMock(return_value=query)
|
||||
for chunk_id, embedding in [("zero", [0.0, 0.0]), ("match", [1.0, 0.0])]:
|
||||
candidate = chunk(chunk_id, f"{chunk_id}.md", "alpha")
|
||||
candidate.embedding = np.array(embedding, dtype=np.float16)
|
||||
store.file_chunks[candidate.id] = candidate
|
||||
|
||||
with np.errstate(invalid="raise", divide="raise"):
|
||||
results = await store.vector_search("alpha", 2, {})
|
||||
|
||||
expected_ids = ["zero", "match"] if zero_query else ["match", "zero"]
|
||||
assert [result.id for result in results] == expected_ids
|
||||
assert [result.scores["vector"] for result in results] == ([0.0, 0.0] if zero_query else [1.0, 0.0])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chunk_persistence_loads_legacy_json_embedding_list():
|
||||
"""Existing indexes with JSON float-list embeddings remain readable."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue