Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Evict other versions of hnsw index of the collection when another version is fetched #2707

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions rust/index/src/hnsw_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use chroma_types::Segment;
use futures::stream;
use futures::stream::StreamExt;
use parking_lot::RwLock;
use rand::seq::index;
use std::fmt::Debug;
use std::path::Path;
use std::{path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -79,9 +80,16 @@ impl HnswIndexProvider {
}
}

pub fn get(&self, id: &Uuid) -> Option<Arc<RwLock<HnswIndex>>> {
match self.cache.get(id) {
Some(index) => Some(index.clone()),
pub fn get(&self, index_id: &Uuid, collection_id: &Uuid) -> Option<Arc<RwLock<HnswIndex>>> {
match self.cache.get(collection_id) {
Some(index) => {
let index_with_lock = index.read();
if index_with_lock.id == *index_id {
// Clone is cheap because we are just cloning the Arc.
return Some(index.clone());
}
return None;
}
None => None,
}
}
Expand Down Expand Up @@ -144,7 +152,7 @@ impl HnswIndexProvider {
match HnswIndex::load(storage_path_str, &index_config, new_id) {
Ok(index) => {
let index = Arc::new(RwLock::new(index));
self.cache.insert(new_id, index.clone());
self.cache.insert(segment.collection, index.clone());
Ok(index)
}
Err(e) => Err(Box::new(HnswIndexProviderForkError::IndexLoadError(e))),
Expand Down Expand Up @@ -262,7 +270,7 @@ impl HnswIndexProvider {
match HnswIndex::load(index_storage_path.to_str().unwrap(), &index_config, *id) {
Ok(index) => {
let index = Arc::new(RwLock::new(index));
self.cache.insert(*id, index.clone());
self.cache.insert(segment.collection, index.clone());
Ok(index)
}
Err(e) => Err(Box::new(HnswIndexProviderOpenError::IndexLoadError(e))),
Expand Down Expand Up @@ -316,7 +324,7 @@ impl HnswIndexProvider {
}
};
let index = Arc::new(RwLock::new(index));
self.cache.insert(id, index.clone());
self.cache.insert(segment.collection, index.clone());
Ok(index)
}

Expand Down
2 changes: 1 addition & 1 deletion rust/worker/src/segment/distributed_hnsw_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl DistributedHNSWSegmentReader {
};

let index =
match hnsw_index_provider.get(&index_uuid) {
match hnsw_index_provider.get(&index_uuid, &segment.collection) {
Some(index) => index,
None => {
match hnsw_index_provider
Expand Down
Loading