Skip to content

Instantly share code, notes, and snippets.

@tazarov
Created August 2, 2024 10:29
Show Gist options
  • Save tazarov/cbc541a94e65401186df11b06e6c71f8 to your computer and use it in GitHub Desktop.
Save tazarov/cbc541a94e65401186df11b06e6c71f8 to your computer and use it in GitHub Desktop.
Patches Chroma 0.5.5+ with replace deleted HNSW flag
Index: chromadb/segment/impl/vector/local_hnsw.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/chromadb/segment/impl/vector/local_hnsw.py b/chromadb/segment/impl/vector/local_hnsw.py
--- a/chromadb/segment/impl/vector/local_hnsw.py (revision Staged)
+++ b/chromadb/segment/impl/vector/local_hnsw.py (date 1722520928951)
@@ -202,6 +202,7 @@
max_elements=DEFAULT_CAPACITY,
ef_construction=self._params.construction_ef,
M=self._params.M,
+ allow_replace_deleted=True,
)
index.set_ef(self._params.search_ef)
index.set_num_threads(self._params.num_threads)
@@ -266,7 +267,7 @@
index = cast(hnswlib.Index, self._index)
# First, update the index
- index.add_items(vectors_to_write, labels_to_write)
+ index.add_items(vectors_to_write, labels_to_write, replace_deleted=True)
# If that succeeds, update the mappings
for i, id in enumerate(written_ids):
Index: chromadb/segment/impl/vector/local_persistent_hnsw.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/chromadb/segment/impl/vector/local_persistent_hnsw.py b/chromadb/segment/impl/vector/local_persistent_hnsw.py
--- a/chromadb/segment/impl/vector/local_persistent_hnsw.py (revision Staged)
+++ b/chromadb/segment/impl/vector/local_persistent_hnsw.py (date 1722519893022)
@@ -209,6 +209,7 @@
max_elements=int(
max(self.count() * self._params.resize_factor, DEFAULT_CAPACITY)
),
+ allow_replace_deleted=True,
)
else:
index.init_index(
@@ -217,6 +218,7 @@
M=self._params.M,
is_persistent_index=True,
persistence_location=self._get_storage_folder(),
+ allow_replace_deleted=True,
)
index.set_ef(self._params.search_ef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment