Skip to content

Commit

Permalink
[BUG] fix invalid operation persist check (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb authored Jul 15, 2024
1 parent 37c54df commit 02b08c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions chromadb/segment/impl/vector/local_persistent_hnsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
from overrides import override
import pickle
from typing import Dict, List, Optional, Sequence, Set, cast
from typing import Any, Dict, List, Optional, Sequence, Set, cast
from chromadb.config import System
from chromadb.segment.impl.vector.batch import Batch
from chromadb.segment.impl.vector.hnsw_params import PersistentHnswParams
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(
self.label_to_id = label_to_id
self.id_to_seq_id = id_to_seq_id

def __setstate__(self, state):
def __setstate__(self, state: Any) -> None:
# Fields were added after the initial implementation
self.total_elements_updated = 0
self.total_invalid_operations = 0
Expand Down Expand Up @@ -305,8 +305,13 @@ def _write_records(self, records: Sequence[LogRecord]) -> None:
self._curr_batch.apply(record, exists_in_index)
self._brute_force_index.upsert([record])

num_invalid_operations_since_last_persist = (
self._total_invalid_operations
- self._persist_data.total_invalid_operations
)

if (
len(self._curr_batch) + self._total_invalid_operations
len(self._curr_batch) + num_invalid_operations_since_last_persist
>= self._batch_size
):
self._apply_batch(self._curr_batch)
Expand Down

0 comments on commit 02b08c4

Please sign in to comment.