Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Keep subindex results aligned after loading a dense index

kartsan03aec875045fae
diff --git a/src/python/txtai/embeddings/index/indexes.py b/src/python/txtai/embeddings/index/indexes.py
index 721e945f..fd5983c7 100644
--- a/src/python/txtai/embeddings/index/indexes.py
+++ b/src/python/txtai/embeddings/index/indexes.py
@@ -32,9 +32,6 @@ class Indexes:
self.text = columns.get("text", "text")
self.object = columns.get("object", "object")
- # Check if top-level indexing is enabled for this embeddings instance
- self.indexing = embeddings.model or embeddings.scoring
-
def __contains__(self, name):
"""
Returns True if name is in this instance, False otherwise.
@@ -113,6 +110,10 @@ class Indexes:
self.documents = Documents()
self.checkpoint = checkpoint
+ # Check if top-level indexing is enabled for this embeddings instance. Checked here since load() creates
+ # subindexes before the vector model.
+ indexing = self.embeddings.model or self.embeddings.scoring
+
# Create batch containing documents added to parent index
batch = []
for _, document, _ in documents:
@@ -122,7 +123,7 @@ class Indexes:
parent = parent.get(self.text, document.get(self.object))
# Add if field is available or top-level indexing is disabled
- if parent is not None or not self.indexing:
+ if parent is not None or not indexing:
batch.append((index, document, None))
index += 1
diff --git a/test/python/testembeddings.py b/test/python/testembeddings.py
index 9f128731..555027c6 100644
--- a/test/python/testembeddings.py
+++ b/test/python/testembeddings.py
@@ -724,6 +724,18 @@ class TestEmbeddings(unittest.TestCase):
# Close embeddings
embeddings.close()
+ # Check documents without a vector are skipped by subindexes after a dense index is loaded
+ config = {"method": "external", "content": True, "indexes": {"labels": {"keyword": True, "columns": {"text": "label"}}}}
+ vector = np.array([1, 0], dtype=np.float32)
+ with Embeddings(config) as embeddings:
+ embeddings.index([("first", {"object": vector, "label": "red"})])
+ embeddings.save(index)
+
+ with Embeddings().load(index) as embeddings:
+ embeddings.upsert([("novector", {"label": "green"}), ("second", {"object": vector, "label": "blue"})])
+ self.assertEqual(embeddings.search("green", index="labels"), [])
+ self.assertEqual([row["id"] for row in embeddings.search("blue", index="labels")], ["second"])
+
def testSubindexVectors(self):
"""
Test subindexes with the same model path and different vectors settings