streamsearch / tests /test_embed.py
sharmaaryan's picture
Phase 0: shared search core + reproducible corpus
61d5e4e
Raw
History Blame Contribute Delete
984 Bytes
import numpy as np
from streamsearch import embed
from streamsearch.schema import EMBED_DIM
def test_embed_shape_and_norm():
vecs = embed.embed_texts(["hello world", "a second document"])
assert vecs.shape == (2, EMBED_DIM)
assert vecs.dtype == np.float32
# normalize_embeddings=True -> unit vectors
norms = np.linalg.norm(vecs, axis=1)
np.testing.assert_allclose(norms, 1.0, atol=1e-4)
def test_embed_is_deterministic():
a = embed.embed_texts(["reproducible embedding"])
b = embed.embed_texts(["reproducible embedding"])
np.testing.assert_allclose(a, b, atol=1e-6)
def test_empty_input_returns_empty():
vecs = embed.embed_texts([])
assert vecs.shape == (0, EMBED_DIM)
def test_model_loads_only_once():
# get_model is lru_cached: repeated calls return the same object.
embed.get_model.cache_clear()
m1 = embed.get_model()
m2 = embed.get_model()
assert m1 is m2
assert embed.get_model.cache_info().hits >= 1