(
quantization_metric: &QuantizationMetric,
storage_type: StorageType,
prop_file: &RwLock<File>,
version_hash: VersionNumber,
offset_counter: &HNSWIndexFileOffsetCounter,
cache
| 158 | /// the root when traversing the index. |
| 159 | #[allow(clippy::too_many_arguments)] |
| 160 | pub fn create_pseudo_root_node( |
| 161 | quantization_metric: &QuantizationMetric, |
| 162 | storage_type: StorageType, |
| 163 | prop_file: &RwLock<File>, |
| 164 | version_hash: VersionNumber, |
| 165 | offset_counter: &HNSWIndexFileOffsetCounter, |
| 166 | cache: &HNSWIndexCache, |
| 167 | values_range: (f32, f32), |
| 168 | hnsw_params: &HNSWHyperParams, |
| 169 | distance_metric: DistanceMetric, |
| 170 | metadata_schema: &MetadataSchema, |
| 171 | vec: Vec<f32>, |
| 172 | vec_hash: InternalId, |
| 173 | ) -> Result<SharedLatestNode, WaCustomError> { |
| 174 | let vector_list = Arc::new(quantization_metric.quantize(&vec, storage_type, values_range)?); |
| 175 | |
| 176 | let mut prop_file_guard = prop_file.write().unwrap(); |
| 177 | let location = write_prop_value_to_file(&vec_hash, &vector_list, &mut prop_file_guard)?; |
| 178 | |
| 179 | let prop_value = Arc::new(NodePropValue { |
| 180 | id: vec_hash, |
| 181 | vec: vector_list, |
| 182 | location, |
| 183 | }); |
| 184 | |
| 185 | let prop_metadata = { |
| 186 | let mbits = metadata_schema.pseudo_root_dimensions(HIGH_WEIGHT); |
| 187 | let metadata = Arc::new(Metadata::from(mbits)); |
| 188 | // A pseudo root node is similar to a base replica node. Hence |
| 189 | // the replica_id and prop_value's id are same. |
| 190 | let replica_id = vec_hash; |
| 191 | let location = |
| 192 | write_prop_metadata_to_file(replica_id, metadata.clone(), &mut prop_file_guard)?; |
| 193 | Some(Arc::new(NodePropMetadata { |
| 194 | replica_id: vec_hash, |
| 195 | vec: metadata, |
| 196 | location, |
| 197 | })) |
| 198 | }; |
| 199 | |
| 200 | drop(prop_file_guard); |
| 201 | |
| 202 | let file_id = offset_counter.file_id(); |
| 203 | |
| 204 | let mut root = LazyItem::new( |
| 205 | ProbNode::new( |
| 206 | HNSWLevel(0), |
| 207 | version_hash, |
| 208 | prop_value.clone(), |
| 209 | prop_metadata.clone(), |
| 210 | ptr::null_mut(), |
| 211 | ptr::null_mut(), |
| 212 | hnsw_params.level_0_neighbors_count, |
| 213 | distance_metric, |
| 214 | ), |
| 215 | file_id, |
| 216 | offset_counter.next_level_0_offset(), |
| 217 | ); |
no test coverage detected