Skip to main content

ClusterMap

Struct ClusterMap 

Source
pub struct ClusterMap { /* private fields */ }
Expand description

Pre-computed clustering of feature vectors for fast semantic grouping.

Implementations§

Source§

impl ClusterMap

Source

pub fn new(dimension: usize) -> Self

Create a new, empty cluster map.

Source

pub fn build(&mut self, nodes: &[(u64, &[f32])], max_iterations: usize)

Run k-means clustering on all feature vectors in the graph. k = min(sqrt(node_count), 256). Skips if node_count < 4.

Source

pub fn nearest_cluster(&self, query: &[f32]) -> Option<usize>

Find the nearest cluster for a query vector.

Source

pub fn get_cluster(&self, cluster_index: usize) -> &[u64]

Get all node IDs in a specific cluster.

Source

pub fn centroid(&self, cluster_index: usize) -> Option<&[f32]>

Get the centroid for a cluster.

Source

pub fn cluster_count(&self) -> usize

Number of clusters.

Source

pub fn assign_node(&mut self, node_id: u64, feature_vec: &[f32])

Assign a new node to the nearest cluster without rebuilding.

Source

pub fn clear(&mut self)

Clear the cluster map.

Source

pub fn is_empty(&self) -> bool

Whether the cluster map is empty.

Source

pub fn dimension(&self) -> usize

Get the dimension.

Source

pub fn centroids(&self) -> &[Vec<f32>]

Get centroids (for serialization).

Source

pub fn assignments(&self) -> &[Vec<u64>]

Get assignments (for serialization).

Trait Implementations§

Source§

impl Default for ClusterMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.