Struct ConcurrentTemporalHnsw

Source
pub struct ConcurrentTemporalHnsw<D: DistanceMetric> {
    inner: RwLock<TemporalHnsw<D>>,
    insert_queue: Mutex<Vec<PendingInsert>>,
}
Expand description

Thread-safe spatiotemporal HNSW index with insert queue (RFC-002-04).

Uses a two-tier approach to reduce write lock contention:

  • Inserts are queued into a Mutex<Vec<...>> (sub-microsecond)
  • flush_inserts() drains the queue under a single write lock
  • Searches always acquire a read lock (concurrent, unblocked during queue drain)

For immediate visibility, use insert() which still takes the write lock directly. For high-throughput ingestion, use queue_insert() + flush_inserts().

Fields§

§inner: RwLock<TemporalHnsw<D>>§insert_queue: Mutex<Vec<PendingInsert>>

Insert queue for batched commits (RFC-002-04, Option A).

Implementations§

Source§

impl<D: DistanceMetric> ConcurrentTemporalHnsw<D>

Source

pub fn new(config: HnswConfig, metric: D) -> Self

Create a new empty concurrent index.

Source

pub fn len(&self) -> usize

Number of points in the index.

Source

pub fn is_empty(&self) -> bool

Whether the index is empty.

Source

pub fn insert(&self, entity_id: u64, timestamp: i64, vector: &[f32]) -> u32

Insert a temporal point (exclusive write lock).

Source

pub fn search( &self, query: &[f32], k: usize, filter: TemporalFilter, alpha: f32, query_timestamp: i64, ) -> Vec<(u32, f32)>

Search with temporal filtering (shared read lock).

Source

pub fn trajectory( &self, entity_id: u64, filter: TemporalFilter, ) -> Vec<(i64, u32)>

Retrieve trajectory for an entity (shared read lock).

Source

pub fn timestamp(&self, node_id: u32) -> i64

Get timestamp for a node (shared read lock).

Source

pub fn entity_id(&self, node_id: u32) -> u64

Get entity_id for a node (shared read lock).

Source

pub fn vector(&self, node_id: u32) -> Vec<f32>

Get vector for a node (shared read lock).

Source

pub fn compute_centroid(&self) -> Option<Vec<f32>>

Compute the centroid (mean vector) of all indexed vectors.

Source

pub fn set_centroid(&self, centroid: Vec<f32>)

Set the centroid for anisotropy correction (write lock).

Source

pub fn clear_centroid(&self)

Clear the centroid (write lock).

Source

pub fn centroid(&self) -> Option<Vec<f32>>

Get the current centroid, if set.

Source

pub fn centered_vector(&self, vec: &[f32]) -> Vec<f32>

Return a centered copy of the given vector (vec - centroid).

Source

pub fn queue_insert(&self, entity_id: u64, timestamp: i64, vector: Vec<f32>)

Queue an insert for batched processing (RFC-002-04).

This only takes a Mutex (sub-microsecond), NOT the write lock. The insert becomes visible after flush_inserts() is called.

Source

pub fn pending_inserts(&self) -> usize

Number of pending inserts in the queue.

Source

pub fn flush_inserts(&self) -> usize

Flush all queued inserts, applying them under a single write lock.

Returns the number of inserts applied.

Trait Implementations§

Source§

impl<D: DistanceMetric> IndexBackend for ConcurrentTemporalHnsw<D>

Source§

fn insert( &self, entity_id: u64, vector: &[f32], timestamp: i64, ) -> Result<u32, IndexError>

Insert a point into the index.
Source§

fn search( &self, query: &[f32], k: usize, filter: TemporalFilter, alpha: f32, query_timestamp: i64, ) -> Result<Vec<ScoredResult>, QueryError>

Search for the k nearest neighbors with temporal filtering. Read more
Source§

fn remove(&self, _point_id: u64) -> Result<(), IndexError>

Remove a point from the index.
Source§

fn len(&self) -> usize

Number of points in the index.
Source§

fn is_empty(&self) -> bool

Whether the index is empty.
Source§

impl<D: DistanceMetric> TemporalIndexAccess for ConcurrentTemporalHnsw<D>

Source§

fn search_raw( &self, query: &[f32], k: usize, filter: TemporalFilter, alpha: f32, query_timestamp: i64, ) -> Vec<(u32, f32)>

Search with temporal filtering, returning (node_id, score) pairs.
Source§

fn trajectory(&self, entity_id: u64, filter: TemporalFilter) -> Vec<(i64, u32)>

Retrieve trajectory for an entity: (timestamp, node_id) pairs.
Source§

fn vector(&self, node_id: u32) -> Vec<f32>

Get the vector for a node. Returns owned vec for thread safety.
Source§

fn entity_id(&self, node_id: u32) -> u64

Get the entity_id for a node.
Source§

fn timestamp(&self, node_id: u32) -> i64

Get the timestamp for a node.
Source§

fn len(&self) -> usize

Number of points in the index.
Source§

fn regions(&self, level: usize) -> Vec<(u32, Vec<f32>, usize)>

Get semantic regions at a given HNSW level (RFC-004). Returns (hub_node_id, hub_vector, n_assigned) per region.
Source§

fn region_members( &self, region_hub: u32, level: usize, filter: TemporalFilter, ) -> Vec<(u32, u64, i64)>

Get points belonging to a specific region, optionally time-filtered (RFC-005). Returns (node_id, entity_id, timestamp) per member.
Source§

fn region_assignments( &self, level: usize, filter: TemporalFilter, ) -> HashMap<u32, Vec<(u64, i64)>>

Assign all nodes to regions in a single O(N) pass, optionally time-filtered. Returns HashMap<hub_id, Vec<(entity_id, timestamp)>>.
Source§

fn region_trajectory( &self, entity_id: u64, level: usize, window_days: i64, alpha: f32, ) -> Vec<(i64, Vec<f32>)>

Smoothed region-distribution trajectory for an entity (RFC-004).
Source§

fn is_empty(&self) -> bool

Whether the index is empty.
Source§

fn metadata(&self, _node_id: u32) -> HashMap<String, String>

Get metadata for a node. Returns empty map if not available.
Source§

fn search_with_metadata( &self, query: &[f32], k: usize, filter: TemporalFilter, alpha: f32, query_timestamp: i64, metadata_filter: &MetadataFilter, ) -> Vec<(u32, f32)>

Search with metadata filtering (post-filter on search results). Default: ignores metadata filter and delegates to search_raw.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> TemporalSearch for T

Source§

fn search_raw( &self, query: &[f32], k: usize, filter: TemporalFilter, alpha: f32, query_timestamp: i64, ) -> Vec<(u32, f32)>

Search with temporal filtering, returning (node_id, score) pairs.
Source§

impl<T> TrajectoryAccess for T

Source§

fn trajectory(&self, entity_id: u64, filter: TemporalFilter) -> Vec<(i64, u32)>

Retrieve trajectory for an entity: (timestamp, node_id) pairs.
Source§

fn vector(&self, node_id: u32) -> Vec<f32>

Get the vector for a node. Returns owned vec for thread safety.
Source§

fn entity_id(&self, node_id: u32) -> u64

Get the entity_id for a node.
Source§

fn timestamp(&self, node_id: u32) -> i64

Get the timestamp for a node.
Source§

fn len(&self) -> usize

Number of points in the index.
Source§

fn is_empty(&self) -> bool

Whether the index is empty.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V