(
config: &Config,
hnsw_index: &HNSWIndex,
version: VersionNumber,
id: InternalId,
raw_emb: &RawVectorEmbedding,
)
| 1204 | } |
| 1205 | |
| 1206 | pub fn delete_embedding( |
| 1207 | config: &Config, |
| 1208 | hnsw_index: &HNSWIndex, |
| 1209 | version: VersionNumber, |
| 1210 | id: InternalId, |
| 1211 | raw_emb: &RawVectorEmbedding, |
| 1212 | ) -> Result<(), WaCustomError> { |
| 1213 | let Some(raw_vec) = &raw_emb.dense_values else { |
| 1214 | return Ok(()); |
| 1215 | }; |
| 1216 | |
| 1217 | let quantized_vec = hnsw_index.quantization_metric.read().unwrap().quantize( |
| 1218 | raw_vec, |
| 1219 | *hnsw_index.storage_type.read().unwrap(), |
| 1220 | *hnsw_index.values_range.read().unwrap(), |
| 1221 | )?; |
| 1222 | |
| 1223 | let mut cur_entry = hnsw_index.get_root_vec(); |
| 1224 | |
| 1225 | let hnsw_params = hnsw_index.hnsw_params.read().unwrap(); |
| 1226 | let distance_metric = *hnsw_index.distance_metric.read().unwrap(); |
| 1227 | let offset_counter = hnsw_index.offset_counter.read().unwrap(); |
| 1228 | let file_id = offset_counter.file_id(); |
| 1229 | |
| 1230 | for level in (0..=hnsw_params.num_layers).rev() { |
| 1231 | let mut skipm = PerformantFixedSet::new(if level == 0 { |
| 1232 | hnsw_params.level_0_neighbors_count |
| 1233 | } else { |
| 1234 | hnsw_params.neighbors_count |
| 1235 | }); |
| 1236 | let mut results = traverse_find_nearest( |
| 1237 | config, |
| 1238 | hnsw_index, |
| 1239 | cur_entry, |
| 1240 | &quantized_vec, |
| 1241 | Some(&id), |
| 1242 | None, |
| 1243 | &mut 0, |
| 1244 | &mut skipm, |
| 1245 | &distance_metric, |
| 1246 | false, |
| 1247 | 512, |
| 1248 | )?; |
| 1249 | |
| 1250 | if results.is_empty() { |
| 1251 | cur_entry = unsafe { &*(*cur_entry).latest } |
| 1252 | .try_get_data(&hnsw_index.cache)? |
| 1253 | .get_child(); |
| 1254 | continue; |
| 1255 | } else { |
| 1256 | cur_entry = unsafe { &*(*results[0].0).latest } |
| 1257 | .try_get_data(&hnsw_index.cache)? |
| 1258 | .get_child(); |
| 1259 | } |
| 1260 | |
| 1261 | let mut idx = None; |
| 1262 | |
| 1263 | for (i, (lazy_item_latest_ptr, _)) in results.iter().enumerate() { |
no test coverage detected