Skip to main content

Module vector_search

Module vector_search 

Source
Expand description

Reusable helpers for building brute-force vector similarity search expressions over Vector extension arrays.

build_similarity_search_tree broadcasts the query into the shape expected by CosineSimilarity via Vector::constant_array and returns a lazy Binary(Gt, [CosineSimilarity(data, query), threshold]) expression. The caller is responsible for preparing data (e.g. by compressing it beforehand); this builder does not compress.

Executing the tree into a BoolArray yields one boolean per row indicating whether that row’s cosine similarity to the query exceeds threshold.

§Example

use vortex_array::{ArrayRef, VortexSessionExecute};
use vortex_array::arrays::BoolArray;
use vortex_session::VortexSession;
use vortex_tensor::vector_search::build_similarity_search_tree;

fn run(session: &VortexSession, data: ArrayRef, query: &[f32]) -> anyhow::Result<()> {
    let mut ctx = session.create_execution_ctx();
    let tree = build_similarity_search_tree(data, query, 0.8)?;
    let _matches: BoolArray = tree.execute(&mut ctx)?;
    Ok(())
}

Functions§

build_similarity_search_tree
Build the lazy similarity-search expression tree for a prepared database array and a single query vector.