Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add tests

davidmezzettiaed1b225b106
diff --git a/test/python/testscoring.py b/test/python/testscoring.py
index cb0f6a28..6ccc780d 100644
--- a/test/python/testscoring.py
+++ b/test/python/testscoring.py
@@ -56,7 +56,7 @@ class TestScoring(unittest.TestCase):
# Generate temp file path
index = os.path.join(tempfile.gettempdir(), "bm25")
- os.makedirs(index)
+ os.makedirs(index, exist_ok=True)
model = self.method("bm25")
model.save(index)
diff --git a/test/python/testvectors.py b/test/python/testvectors.py
index 2e4562b9..02987ad4 100644
--- a/test/python/testvectors.py
+++ b/test/python/testvectors.py
@@ -6,17 +6,31 @@ import os
import tempfile
import unittest
-from txtai.vectors import WordVectors
+from txtai.vectors import WordVectors, Vectors
class TestVectors(unittest.TestCase):
"""
Vectors tests
"""
- def testBuild(self):
+ def setUp(self):
"""
Test a WordVectors build.
"""
+ # Word vectors path
+ path = os.path.join(tempfile.gettempdir(), "vectors")
+
# Build word vectors on README file
- WordVectors.build("README.md", 300, 3, os.path.join(tempfile.gettempdir(), "vectors"))
+ WordVectors.build("README.md", 300, 3, path)
+
+ # Save model path
+ self.path = path + ".magnitude"
+
+ def testLoad(self):
+ model = Vectors.create("words", self.path, True, None)
+ self.assertEqual(len(model.transform((None, ["txtai"], None))), 300)
+
+ def testLookup(self):
+ model = Vectors.create("words", self.path, True, None)
+ self.assertEqual(model.lookup(["txtai", "embeddings", "sentence"]).shape, (3, 300))