Skip to main content

CentroidGraph

Trait CentroidGraph 

Source
pub trait CentroidGraph: Send + Sync {
    // Required methods
    fn search(&self, query: &[f32], k: usize) -> Vec<u64>;
    fn add_centroid(&self, entry: &CentroidEntry) -> Result<()>;
    fn remove_centroid(&self, centroid_id: u64) -> Result<()>;
    fn get_centroid_vector(&self, centroid_id: u64) -> Option<Vec<f32>>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for HNSW-based centroid graph implementations.

The graph stores centroids and enables fast approximate nearest neighbor search to find relevant clusters during query execution.

Required Methods§

Source

fn search(&self, query: &[f32], k: usize) -> Vec<u64>

Search for k nearest centroids to a query vector.

§Arguments
  • query - Query vector
  • k - Number of nearest centroids to return
§Returns

Vector of centroid_ids sorted by similarity (closest first)

Source

fn add_centroid(&self, entry: &CentroidEntry) -> Result<()>

Add a centroid to the graph.

Uses interior mutability since the graph is behind Arc<dyn CentroidGraph>.

Source

fn remove_centroid(&self, centroid_id: u64) -> Result<()>

Remove a centroid from the graph by its ID.

Uses interior mutability since the graph is behind Arc<dyn CentroidGraph>.

Source

fn get_centroid_vector(&self, centroid_id: u64) -> Option<Vec<f32>>

Get the vector for a centroid by its ID.

Returns None if the centroid is not in the graph.

Source

fn len(&self) -> usize

Returns the number of centroids in the graph.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the graph has no centroids.

Implementors§