Skip to main content

HyperbolicEmbedding

Struct HyperbolicEmbedding 

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

Hyperbolic embedding manager for hierarchical data.

Provides a convenient interface for storing and querying hierarchical embeddings in Poincaré ball space.

Implementations§

Source§

impl HyperbolicEmbedding

Source

pub fn new(config: HyperbolicConfig) -> Self

Create a new hyperbolic embedding manager.

Source

pub fn from_pairs(pairs: Vec<(String, Vec<f32>)>) -> Self

Build a HyperbolicEmbedding from pre-existing (id, vector) pairs.

Useful for restoring from a serialized source (e.g. SQLite dream_state). The vectors are stored as-is — call sites must ensure they were previously projected to the Poincaré ball.

Source

pub fn with_dimensions(dimensions: usize) -> Self

Create with default configuration.

Source

pub fn add(&mut self, id: &str, euclidean: &[f32])

Add a Euclidean vector as a named embedding.

Converts to Poincaré ball coordinates.

Source

pub fn add_child( &mut self, parent_id: &str, child_id: &str, child_euclidean: &[f32], )

Add a parent-child relationship using Möbius addition.

The child is placed at parent ⊕ child_euclidean, which naturally positions it farther from the origin along the parent’s direction.

Source

pub fn get(&self, id: &str) -> Option<&[f32]>

Get the hyperbolic embedding for a given id.

Source

pub fn nearest_neighbors(&self, query_id: &str, k: usize) -> Vec<(String, f32)>

Find the k nearest neighbors in hyperbolic space.

Returns (id, distance) pairs sorted by distance.

Source

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

Find nearest neighbors for an arbitrary Euclidean query.

Source

pub fn hierarchical_distance(&self, id_a: &str, id_b: &str) -> f32

Compute the hierarchical distance between two embeddings.

In hierarchical data, nodes deeper in the tree are farther from the origin. This function returns the hyperbolic distance plus a depth penalty.

Source

pub fn len(&self) -> usize

Returns the number of stored embeddings.

Source

pub fn is_empty(&self) -> bool

Returns true if no embeddings stored.

Source

pub fn ids(&self) -> Vec<&str>

Returns all embedding ids.

Source

pub fn all_embeddings(&self) -> &[(String, Vec<f32>)]

Returns all embeddings as (id, vector) pairs.

Source

pub fn search_memories( &self, query_euclidean: &[f32], k: usize, ) -> Vec<(String, f32)>

Find memories near a query in hyperbolic space.

Returns (memory_id, hyperbolic_distance) pairs. Useful for hierarchical navigation: memories close to the root are general; those near the boundary are specific.

Source

pub fn hierarchical_rank(&self) -> Vec<(String, f32)>

Get the hierarchical depth rank of all memories.

Memories closer to the origin are more general/root-level. Memories farther from origin are more specific/leaf-level.

Returns (id, depth) pairs sorted by depth ascending.

Source

pub fn depth(&self, id: &str) -> f32

Get the hyperbolic distance of a point from the origin.

Points closer to the origin are “higher” in the hierarchy.

Source

pub fn rank_by_depth(&self) -> Vec<(String, f32)>

Rank all embeddings by depth (origin distance).

Returns (id, depth) pairs sorted by depth ascending. Items with lower depth are closer to the root of the hierarchy.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more