Expand description
Reusable helpers for building brute-force vector similarity search expressions over
Vector extension arrays.
This module exposes three small building blocks that together make it straightforward to stand up a cosine-similarity-plus-threshold scan on top of a prepared data array:
compress_turboquantapplies the canonical TurboQuant encoding pipeline (L2Denorm(SorfTransform(FSL(Dict(codes, centroids))), norms)) to a rawVector<dim, f32>array without requiring the caller to plumb theunstable_encodingsfeature flag on thevortexfacade.build_constant_query_vectorwraps a single query vector into aVectorextension array whose storage is aConstantArraybroadcast acrossnum_rowsrows. This is the shape expected byCosineSimilarity::try_new_arrayfor the RHS of a database-vs-query scan.build_similarity_search_treewires everything together into a lazyBinary(Gt, [CosineSimilarity(data, query), threshold])expression.
Executing the tree from build_similarity_search_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, compress_turboquant};
fn run(session: &VortexSession, data: ArrayRef, query: &[f32]) -> anyhow::Result<()> {
let mut ctx = session.create_execution_ctx();
let data = compress_turboquant(data, &mut ctx)?;
let tree = build_similarity_search_tree(data, query, 0.8)?;
let _matches: BoolArray = tree.execute(&mut ctx)?;
Ok(())
}Functions§
- build_
constant_ query_ vector - Build a
Vectorextension array whose storage is aConstantArraybroadcasting a single query vector acrossnum_rowsrows. - build_
similarity_ search_ tree - Build the lazy similarity-search expression tree for a prepared database array and a single query vector.
- compress_
turboquant - Apply the canonical TurboQuant encoding pipeline to a
Vector<dim, f32>array.