Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Switch SQLite ANN connections when load() is given a new path

kartsan03fe1fbbc933d2
diff --git a/src/python/txtai/ann/dense/sqlite.py b/src/python/txtai/ann/dense/sqlite.py
index 1ced45be..5f6970a3 100644
--- a/src/python/txtai/ann/dense/sqlite.py
+++ b/src/python/txtai/ann/dense/sqlite.py
@@ -35,6 +35,8 @@ class SQLite(ANN):
self.quantize = 8 if isinstance(self.quantize, bool) and self.quantize else int(self.quantize) if self.quantize else None
def load(self, path):
+ if self.path != path:
+ self.close()
self.path = path
def index(self, embeddings):
diff --git a/test/python/testann/testdense/testsqlite.py b/test/python/testann/testdense/testsqlite.py
index 756ee869..5ee29121 100644
--- a/test/python/testann/testdense/testsqlite.py
+++ b/test/python/testann/testdense/testsqlite.py
@@ -140,6 +140,8 @@ class TestSQLite(DenseTest):
# Load new copy and check that it has all the changes
model = ANNFactory.create(model.config)
+ model.load(index)
+ self.assertEqual(model.count(), 500)
model.load(new)
self.assertEqual(model.count(), 509)
self.assertEqual(len(model.search(np.random.rand(1, 240).astype(np.float32), 10)[0]), 10)