/ test / python / testvectors / testdense / testllama.py
testllama.py
 1  """
 2  Llama module tests
 3  """
 4  
 5  import os
 6  import unittest
 7  
 8  import numpy as np
 9  
10  from txtai.vectors import VectorsFactory
11  
12  
13  class TestLlamaCpp(unittest.TestCase):
14      """
15      llama.cpp vectors tests
16      """
17  
18      @classmethod
19      def setUpClass(cls):
20          """
21          Create LlamaCpp instance.
22          """
23  
24          cls.model = VectorsFactory.create({"path": "nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.Q2_K.gguf"}, None)
25  
26      def testIndex(self):
27          """
28          Test indexing with LlamaCpp vectors
29          """
30  
31          ids, dimension, batches, stream = self.model.index([(0, "test", None)])
32  
33          self.assertEqual(len(ids), 1)
34          self.assertEqual(dimension, 768)
35          self.assertEqual(batches, 1)
36          self.assertIsNotNone(os.path.exists(stream))
37  
38          # Test shape of serialized embeddings
39          with open(stream, "rb") as queue:
40              self.assertEqual(np.load(queue).shape, (1, 768))