test(entities): add zero vector validation tests

Add comprehensive test coverage for zero and near-zero vector
detection in SemanticChunk embedding validation.

Solution-ID: SOL-20251228113612
Issue-ID: ISS-1766921318981-7
Task-ID: T2
This commit is contained in:
catlog22
2025-12-29 19:03:20 +08:00
parent c859af1abf
commit 76ab4d67fe

View File

@@ -84,6 +84,24 @@ class TestSemanticChunk:
chunk = SemanticChunk(content="code", embedding=embedding)
assert chunk.embedding == embedding
def test_chunk_zero_vector_validation(self):
"""Test that zero vector embeddings are rejected."""
with pytest.raises(ValidationError) as exc:
SemanticChunk(content="code", embedding=[0.0, 0.0, 0.0, 0.0])
assert "zero vector" in str(exc.value).lower()
def test_chunk_near_zero_vector_validation(self):
"""Test that near-zero vector embeddings are rejected."""
with pytest.raises(ValidationError) as exc:
SemanticChunk(content="code", embedding=[1e-11, 1e-11, 1e-11])
assert "zero vector" in str(exc.value).lower()
def test_chunk_small_nonzero_vector_validation(self):
"""Test that small but non-zero embeddings are allowed."""
embedding = [0.001, 0.001, 0.001]
chunk = SemanticChunk(content="code", embedding=embedding)
assert chunk.embedding == embedding
class TestIndexedFile:
"""Tests for IndexedFile entity."""