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:
Node- The matched node IDFloat64- 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
impl VectorScanOperator
Sourcepub fn brute_force(
store: Arc<LpgStore>,
property: impl Into<String>,
query: Vec<f32>,
k: usize,
metric: DistanceMetric,
) -> Self
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 scanproperty- The property name containing vector embeddingsquery- The query vectork- Number of nearest neighbors to returnmetric- Distance metric to use
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Sets a label filter for brute-force search.
Sourcepub fn with_ef(self, ef: usize) -> Self
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.
Sourcepub fn with_min_similarity(self, threshold: f32) -> Self
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].
Sourcepub fn with_max_distance(self, threshold: f32) -> Self
pub fn with_max_distance(self, threshold: f32) -> Self
Sets a maximum distance threshold.
Results with distance above this value will be filtered out.
Sourcepub fn with_chunk_capacity(self, capacity: usize) -> Self
pub fn with_chunk_capacity(self, capacity: usize) -> Self
Sets the chunk capacity for output batches.
Trait Implementations§
Source§impl Operator for VectorScanOperator
impl Operator for VectorScanOperator
Auto Trait Implementations§
impl Freeze for VectorScanOperator
impl !RefUnwindSafe for VectorScanOperator
impl Send for VectorScanOperator
impl Sync for VectorScanOperator
impl Unpin for VectorScanOperator
impl !UnwindSafe for VectorScanOperator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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