forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rag

Clone
★ 0

0 watching0 forksPython2.4 MiB184b84dAhmet Kaan Gümüş2 months ago189 commits

test_embed.py42 lines, 1.4 KiBHistoryRawDownload
1"""Faz 1.2 birim testleri — cosine yardımcıları + embedder lazy-load (model gerekmez)."""
2import unittest
3
4import numpy as np
5
6from src.embed import cosine_sim, cosine_matrix, BGEM3Embedder
7
8
9class CosineTests(unittest.TestCase):
10 def test_identical(self):
11 self.assertAlmostEqual(cosine_sim([1, 2, 3], [1, 2, 3]), 1.0, places=6)
12
13 def test_orthogonal(self):
14 self.assertAlmostEqual(cosine_sim([1, 0], [0, 1]), 0.0, places=6)
15
16 def test_zero_vector(self):
17 self.assertEqual(cosine_sim([0, 0], [1, 1]), 0.0)
18
19 def test_matrix_shape_and_order(self):
20 q = [1.0, 0.0]
21 m = np.array([[1.0, 0.0], [0.0, 1.0], [0.9, 0.1]])
22 scores = cosine_matrix(q, m)
23 self.assertEqual(scores.shape, (3,))
24 self.assertEqual(int(np.argmax(scores)), 0) # en benzer satır 0
25 self.assertGreater(scores[2], scores[1]) # [0.9,0.1] > [0,1]
26
27
28class BGEM3LazyTests(unittest.TestCase):
29 def test_lazy_no_load_on_construct(self):
30 e = BGEM3Embedder()
31 self.assertFalse(e.loaded) # model import/indirme yok
32 self.assertEqual(e.dim, 1024)
33
34 def test_empty_embed_no_model(self):
35 e = BGEM3Embedder()
36 v = e.embed([]) # boş → model yüklenmez
37 self.assertEqual(v.shape, (0, 1024))
38 self.assertFalse(e.loaded)
39
40
41if __name__ == "__main__":
42 unittest.main()