diff --git a/pgvectorscale/src/access_method/sbq/mod.rs b/pgvectorscale/src/access_method/sbq/mod.rs index ab98af14..8a46a3df 100644 --- a/pgvectorscale/src/access_method/sbq/mod.rs +++ b/pgvectorscale/src/access_method/sbq/mod.rs @@ -197,7 +197,7 @@ impl<'a> SbqNodeDistanceMeasure<'a> { index_pointer: IndexPointer, stats: &mut T, ) -> Self { - let cache = &mut storage.qv_cache.borrow_mut(); + let cache = &mut storage.qv_cache.as_ref().unwrap().borrow_mut(); let vec = cache.get(index_pointer, storage, stats); Self { vec: vec.to_vec(), @@ -212,7 +212,7 @@ impl NodeDistanceMeasure for SbqNodeDistanceMeasure<'_> { index_pointer: IndexPointer, stats: &mut T, ) -> f32 { - let cache = &mut self.storage.qv_cache.borrow_mut(); + let cache = &mut self.storage.qv_cache.as_ref().unwrap().borrow_mut(); let vec1 = cache.get(index_pointer, self.storage, stats); distance_xor_optimized(vec1, self.vec.as_slice()) as f32 } diff --git a/pgvectorscale/src/access_method/sbq/storage.rs b/pgvectorscale/src/access_method/sbq/storage.rs index 2f38e04d..5c12a1b0 100644 --- a/pgvectorscale/src/access_method/sbq/storage.rs +++ b/pgvectorscale/src/access_method/sbq/storage.rs @@ -36,7 +36,7 @@ pub struct SbqSpeedupStorage<'a> { quantizer: SbqQuantizer, heap_rel: &'a PgRelation, heap_attr: AttrNumber, - pub qv_cache: RefCell, + pub qv_cache: Option>, has_labels: bool, } @@ -52,7 +52,7 @@ impl<'a> SbqSpeedupStorage<'a> { quantizer: SbqQuantizer::new(meta_page), heap_rel, heap_attr: get_index_vector_attribute(index), - qv_cache: RefCell::new(QuantizedVectorCache::new(1000)), + qv_cache: Some(RefCell::new(QuantizedVectorCache::new(1000))), has_labels: meta_page.has_labels(), } } @@ -77,7 +77,7 @@ impl<'a> SbqSpeedupStorage<'a> { quantizer: Self::load_quantizer(index_relation, meta_page, stats), heap_rel, heap_attr: get_index_vector_attribute(index_relation), - qv_cache: RefCell::new(QuantizedVectorCache::new(1000)), + qv_cache: Some(RefCell::new(QuantizedVectorCache::new(1000))), has_labels: meta_page.has_labels(), } } @@ -95,7 +95,7 @@ impl<'a> SbqSpeedupStorage<'a> { quantizer: quantizer.clone(), heap_rel: heap_relation, heap_attr: get_index_vector_attribute(index_relation), - qv_cache: RefCell::new(QuantizedVectorCache::new(1000)), + qv_cache: None, has_labels: meta_page.has_labels(), } } @@ -205,7 +205,7 @@ impl<'a> SbqSpeedupStorage<'a> { } } - let mut cache = self.qv_cache.borrow_mut(); + let mut cache = self.qv_cache.as_ref().unwrap().borrow_mut(); let bq_vector = cache.get(neighbor_index_pointer, self, &mut lsr.stats); let distance = lsr .sdm @@ -280,7 +280,7 @@ impl Storage for SbqSpeedupStorage<'_> { neighbors: &[NeighborWithDistance], stats: &mut S, ) { - let mut cache = self.qv_cache.borrow_mut(); + let mut cache = self.qv_cache.as_ref().unwrap().borrow_mut(); /* It's important to preload cache with all the items since you can run into deadlocks if you try to fetch a quantized vector while holding the SbqNode::modify lock */ let iter = neighbors