💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Modify HNSW logic to initialize delete counter in index method
davidmezzettib1a3b9751491
diff --git a/src/python/txtai/ann/hnsw.py b/src/python/txtai/ann/hnsw.pyindex 71ba9428..35116627 100644--- a/src/python/txtai/ann/hnsw.py+++ b/src/python/txtai/ann/hnsw.py@@ -36,8 +36,9 @@ class HNSW(ANN):# Add itemsself.model.add_items(embeddings, np.arange(embeddings.shape[0]))- # Update id offset+ # Update id offset and set delete counterself.config["offset"] = embeddings.shape[0]+ self.config["deletes"] = 0def append(self, embeddings):new = embeddings.shape[0]@@ -56,7 +57,7 @@ class HNSW(ANN):for uid in ids:try:self.model.mark_deleted(uid)- self.config["deletes"] = self.config.get("deletes", 0) + 1+ self.config["deletes"] = self.config["deletes"] + 1except RuntimeError:# Ignore label not found errorcontinue@@ -81,7 +82,7 @@ class HNSW(ANN):return resultsdef count(self):- return self.model.get_current_count() - self.config.get("deletes", 0)+ return self.model.get_current_count() - self.config["deletes"]def save(self, path):# Write index