From fe1fbbc933d21fba20e600e4962528cc658efe99 Mon Sep 17 00:00:00 2001 From: kartsan03 Date: Sat, 10 Oct 2026 11:11:24 +0000 Subject: [PATCH] Switch SQLite ANN connections when load() is given a new path --- src/python/txtai/ann/dense/sqlite.py | 2 ++ test/python/testann/testdense/testsqlite.py | 2 ++ 2 files changed, 4 insertions(+) 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)