pub struct HnswGraph {
pub nodes: HashMap<EntityId, HnswNode>,
pub entry_point: Option<EntityId>,
pub max_layer: usize,
pub distance_metric: DistanceMetric,
pub dimension: usize,
}Expand description
The HNSW graph structure.
Fields§
§nodes: HashMap<EntityId, HnswNode>All nodes in the graph, keyed by entity ID.
entry_point: Option<EntityId>The entry point node (highest level node).
max_layer: usizeThe current maximum layer in the graph.
distance_metric: DistanceMetricThe distance metric used for similarity.
dimension: usizeThe dimension of embeddings in this graph.
Implementations§
Source§impl HnswGraph
impl HnswGraph
Sourcepub fn new(dimension: usize, distance_metric: DistanceMetric) -> Self
pub fn new(dimension: usize, distance_metric: DistanceMetric) -> Self
Create a new empty HNSW graph.
Sourcepub fn get_node_mut(&mut self, entity_id: EntityId) -> Option<&mut HnswNode>
pub fn get_node_mut(&mut self, entity_id: EntityId) -> Option<&mut HnswNode>
Get a mutable node by entity ID.
Sourcepub fn distance(&self, a: &Embedding, b: &Embedding) -> f32
pub fn distance(&self, a: &Embedding, b: &Embedding) -> f32
Calculate the distance between two embeddings.
Sourcepub fn distance_to_node(
&self,
query: &Embedding,
entity_id: EntityId,
) -> Option<f32>
pub fn distance_to_node( &self, query: &Embedding, entity_id: EntityId, ) -> Option<f32>
Calculate the distance from a query to a node.
Sourcepub fn insert_node(&mut self, node: HnswNode)
pub fn insert_node(&mut self, node: HnswNode)
Insert a node into the graph.
Sourcepub fn remove_node(&mut self, entity_id: EntityId) -> Option<HnswNode>
pub fn remove_node(&mut self, entity_id: EntityId) -> Option<HnswNode>
Remove a node from the graph.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HnswGraph
impl RefUnwindSafe for HnswGraph
impl Send for HnswGraph
impl Sync for HnswGraph
impl Unpin for HnswGraph
impl UnwindSafe for HnswGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more