Skip to main content

VectorScanOperator

Struct VectorScanOperator 

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

A scan operator that finds nodes by vector similarity.

This operator performs k-nearest neighbor search on vector embeddings stored in node properties. It can use an HNSW index for O(log n) search or fall back to brute-force O(n) search.

§Output Schema

Returns a DataChunk with two columns:

  1. Node - The matched node ID
  2. Float64 - The distance/similarity score

§Example

use grafeo_core::execution::operators::VectorScanOperator;

let query = vec![0.1f32, 0.2, 0.3];
let mut scan = VectorScanOperator::brute_force(store, "embedding", query, 10, DistanceMetric::Cosine);

while let Some(chunk) = scan.next()? {
    for i in 0..chunk.row_count() {
        let node_id = chunk.column(0).get_node_id(i);
        let distance = chunk.column(1).get_float64(i);
        println!("Node {:?} at distance {}", node_id, distance);
    }
}

Implementations§

Source§

impl VectorScanOperator

Source

pub fn brute_force( store: Arc<LpgStore>, property: impl Into<String>, query: Vec<f32>, k: usize, metric: DistanceMetric, ) -> Self

Creates a new vector scan operator for brute-force search.

This is suitable for small datasets (< 10K vectors) where index overhead isn’t worth it.

§Arguments
  • store - The LPG store to scan
  • property - The property name containing vector embeddings
  • query - The query vector
  • k - Number of nearest neighbors to return
  • metric - Distance metric to use
Source

pub fn with_label(self, label: impl Into<String>) -> Self

Sets a label filter for brute-force search.

Source

pub fn with_ef(self, ef: usize) -> Self

Sets the search ef parameter (accuracy vs speed tradeoff).

Higher values give more accurate results but slower search. Default is 64. For production use, 50-200 is typical.

Source

pub fn with_min_similarity(self, threshold: f32) -> Self

Sets a minimum similarity threshold.

Results with similarity below this value will be filtered out. For cosine similarity, this should be in [-1, 1].

Source

pub fn with_max_distance(self, threshold: f32) -> Self

Sets a maximum distance threshold.

Results with distance above this value will be filtered out.

Source

pub fn with_chunk_capacity(self, capacity: usize) -> Self

Sets the chunk capacity for output batches.

Trait Implementations§

Source§

impl Operator for VectorScanOperator

Source§

fn next(&mut self) -> OperatorResult

Pulls the next batch of data. Returns None when exhausted.
Source§

fn reset(&mut self)

Resets to initial state so you can iterate again.
Source§

fn name(&self) -> &'static str

Returns a name for debugging/explain output.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.