MCPcopy Create free account
hub / github.com/cosdata/cosdata / create_node_edges

Function create_node_edges

src/vector_store.rs:976–1109  ·  view source on GitHub ↗
(
    hnsw_index: &HNSWIndex,
    lazy_item_latest_ptr: SharedLatestNode,
    neighbors: Vec<(SharedLatestNode, MetricResult)>,
    version: VersionNumber,
    file_id: IndexFileId,
    max_edges: usi

Source from the content-addressed store, hash-verified

974
975#[allow(clippy::too_many_arguments)]
976fn create_node_edges(
977 hnsw_index: &HNSWIndex,
978 lazy_item_latest_ptr: SharedLatestNode,
979 neighbors: Vec<(SharedLatestNode, MetricResult)>,
980 version: VersionNumber,
981 file_id: IndexFileId,
982 max_edges: usize,
983 offset_counter: &HNSWIndexFileOffsetCounter,
984 distance_metric: DistanceMetric,
985) -> Result<(), WaCustomError> {
986 let mut successful_edges = 0;
987 let mut neighbors_to_update = Vec::new();
988
989 let lazy_item = unsafe { &*lazy_item_latest_ptr }.latest;
990 let node = unsafe { &*lazy_item }.try_get_data(&hnsw_index.cache)?;
991
992 let node_id = node.get_id();
993
994 // First loop: Handle neighbor connections and collect updates
995 for (neighbor_lazy_item_latest_ptr, dist) in neighbors {
996 if successful_edges >= max_edges {
997 break;
998 }
999
1000 let (neighbor_lazy_item, newly_created) = LatestNode::get_or_create_version(
1001 neighbor_lazy_item_latest_ptr,
1002 version,
1003 &hnsw_index.versions_synchronization_map,
1004 &hnsw_index.cache,
1005 file_id,
1006 offset_counter,
1007 )?;
1008
1009 let neighbor_node = unsafe { &*neighbor_lazy_item }.try_get_data(&hnsw_index.cache)?;
1010 let neighbor_node_id = neighbor_node.get_id();
1011
1012 assert_eq!(neighbor_node.version.load(Ordering::Relaxed), *version);
1013
1014 // Ensure that a metadata node gets connected to a pseudo node
1015 // only if there's a perfect match
1016 match (
1017 neighbor_node.replica_node_kind(),
1018 node.replica_node_kind(),
1019 &dist,
1020 ) {
1021 (
1022 ReplicaNodeKind::Pseudo,
1023 ReplicaNodeKind::Metadata,
1024 MetricResult::CosineSimilarity(cs),
1025 ) => {
1026 if cs.0 != 1.0 {
1027 continue;
1028 }
1029 }
1030 (
1031 ReplicaNodeKind::Metadata,
1032 ReplicaNodeKind::Metadata,
1033 MetricResult::CosineSimilarity(cs),

Callers 2

index_embeddingFunction · 0.85
delete_embeddingFunction · 0.85

Calls 15

write_lazy_item_to_fileFunction · 0.85
try_get_dataMethod · 0.80
get_idMethod · 0.80
add_neighborMethod · 0.80
open_cursorMethod · 0.80
get_tag_and_valueMethod · 0.80
seek_with_cursorMethod · 0.80
update_with_cursorMethod · 0.80
close_cursorMethod · 0.80
replica_node_kindMethod · 0.45

Tested by

no test coverage detected