Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Load the Milvus collection when opening a saved index

morgan-codedcfe2227f30ae
diff --git a/src/python/txtai/ann/dense/milvus.py b/src/python/txtai/ann/dense/milvus.py
index 6f4f6af8..14179b23 100644
--- a/src/python/txtai/ann/dense/milvus.py
+++ b/src/python/txtai/ann/dense/milvus.py
@@ -138,3 +138,6 @@ class Milvus(ANN):
self.backend = milvus_lite.MilvusLite(self.path)
self.collection = self.backend.get_collection("txtai")
+
+ # Reopened collections with an index start released, load to enable search
+ self.collection.load()
diff --git a/test/python/testann/testdense.py b/test/python/testann/testdense.py
index 19168129..a949b7d7 100644
--- a/test/python/testann/testdense.py
+++ b/test/python/testann/testdense.py
@@ -639,13 +639,21 @@ class TestDense(unittest.TestCase):
# Generate temp file path
index = os.path.join(tempfile.gettempdir(), "ann")
- # Save and close index
+ # Generate query vector
+ query = np.random.rand(240).astype(np.float32)
+ self.normalize(query)
+
+ # Save index and ensure it's still searchable
model.save(index)
- model.close()
+ self.assertGreater(model.search(np.array([query]), 1)[0][0][1], 0)
- # Reload index
+ # Close and reload index
+ model.close()
model.load(index)
+ # Ensure reloaded index is searchable
+ self.assertGreater(model.search(np.array([query]), 1)[0][0][1], 0)
+
return model
def search(self, name, params=None):