Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Code cleanup

davidmezzettid59c88424dff
diff --git a/src/python/txtai/ann/dense/milvus.py b/src/python/txtai/ann/dense/milvus.py
index 4dda303e..6f4f6af8 100644
--- a/src/python/txtai/ann/dense/milvus.py
+++ b/src/python/txtai/ann/dense/milvus.py
@@ -98,6 +98,7 @@ class Milvus(ANN):
self.backend.close()
self.collection = None
self.backend = None
+
archive = ArchiveFactory.create(self.directory)
archive.save(path, "tar")
self.open()
@@ -106,6 +107,7 @@ class Milvus(ANN):
# Release milvus-lite collection handles and the directory lock
if self.backend:
self.backend.close()
+
self.collection = None
super().close()
@@ -127,12 +129,12 @@ class Milvus(ANN):
if embeddings.shape[0]:
for start in range(0, embeddings.shape[0], 1024):
batch = embeddings[start : start + 1024]
- self.collection.insert(
- [{"id": offset + start + uid, "embedding": embedding.tolist()} for uid, embedding in enumerate(batch)]
- )
+ self.collection.insert([{"id": offset + start + uid, "embedding": embedding.tolist()} for uid, embedding in enumerate(batch)])
def open(self):
- """Opens the milvus-lite database and collection."""
+ """
+ Opens the milvus-lite database and collection
+ """
self.backend = milvus_lite.MilvusLite(self.path)
self.collection = self.backend.get_collection("txtai")
diff --git a/src/python/txtai/ann/dense/zvec.py b/src/python/txtai/ann/dense/zvec.py
index 48d8b9aa..06ac7fad 100644
--- a/src/python/txtai/ann/dense/zvec.py
+++ b/src/python/txtai/ann/dense/zvec.py
@@ -100,6 +100,7 @@ class Zvec(ANN):
def save(self, path):
self.backend.flush()
self.backend = None
+
archive = ArchiveFactory.create(self.directory)
archive.save(path, "tar")
self.backend = zvec.open(self.path)
diff --git a/test/python/testdatabase/testsql.py b/test/python/testdatabase/testsql.py
index cd9690cd..e4b3b752 100644
--- a/test/python/testdatabase/testsql.py
+++ b/test/python/testdatabase/testsql.py
@@ -282,11 +282,6 @@ class TestSQL(unittest.TestCase):
with self.assertRaises(SQLError):
self.db.search("select * from txtai where similar('abc'")
- def testMalformedExpression(self):
- """
- Test malformed select expressions raise a SQLError instead of an internal exception
- """
-
# Empty select components (stray commas) raised IndexError
with self.assertRaises(SQLError):
self.db.search("select a,,b from txtai")
diff --git a/test/python/testpipeline/testdata/testsegmentation.py b/test/python/testpipeline/testdata/testsegmentation.py
index 264c0d1e..9bdf72f8 100644
--- a/test/python/testpipeline/testdata/testsegmentation.py
+++ b/test/python/testpipeline/testdata/testsegmentation.py
@@ -12,29 +12,35 @@ class TestSegmentation(unittest.TestCase):
Segmentation tests.
"""
+ def testLines(self):
+ """
+ Test line segmentation tolerates CRLF
+ """
+
+ segment = Segmentation(lines=True)
+ self.assertEqual(segment("Line A.\r\nLine B."), ["Line A.", "Line B."])
+
def testParagraphs(self):
"""
- Test paragraph segmentation with both LF and CRLF blank lines.
+ Test paragraph segmentation with both LF and CRLF blank lines
"""
+
segment = Segmentation(paragraphs=True)
self.assertEqual(segment("Para A.\n\nPara B."), ["Para A.", "Para B."])
+
# Windows blank lines (\r\n\r\n) must split the same way as LF.
self.assertEqual(segment("Para A.\r\n\r\nPara B."), ["Para A.", "Para B."])
def testSections(self):
"""
- Test section segmentation with both LF and CRLF blank lines.
+ Test section segmentation with both LF and CRLF blank lines
"""
+
segment = Segmentation(sections=True)
+
self.assertEqual(segment("Sec A.\n\n\nSec B."), ["Sec A.", "Sec B."])
+
self.assertEqual(
segment("Sec A.\r\n\r\n\r\nSec B.\r\n\r\n\r\nSec C."),
["Sec A.", "Sec B.", "Sec C."],
)
-
- def testLines(self):
- """
- Test line segmentation tolerates CRLF.
- """
- segment = Segmentation(lines=True)
- self.assertEqual(segment("Line A.\r\nLine B."), ["Line A.", "Line B."])