pub struct VectorSearch<T>where
T: SurrealRecord,{ /* private fields */ }Expand description
A vector K-nearest-neighbour SELECT, reached from Table::nearest.
Renders SELECT … FROM <table> WHERE field <|k,ef|> [vector], optionally
projecting / ordering by the computed vector::distance::knn(). By default
it uses the field’s HNSW index with ef = k; call distance
for a brute-force scan or ef to tune recall.
Doc::table()
.nearest("embedding", vec![0.1, 0.2, 0.3])
.k(5)
.distance_as("dist") // SELECT *, vector::distance::knn() AS dist
.order_by_distance() // ORDER BY dist
.to_surrealql();
// SELECT *, vector::distance::knn() AS dist FROM doc
// WHERE embedding <|5,5|> [0.1, 0.2, 0.3] ORDER BY distImplementations§
Source§impl<T> VectorSearch<T>where
T: SurrealRecord,
impl<T> VectorSearch<T>where
T: SurrealRecord,
Sourcepub fn k(self, k: u32) -> VectorSearch<T>
pub fn k(self, k: u32) -> VectorSearch<T>
Number of neighbours k to return (default 10).
Sourcepub fn distance(self, metric: impl Into<String>) -> VectorSearch<T>
pub fn distance(self, metric: impl Into<String>) -> VectorSearch<T>
Brute-force KNN with an explicit distance metric (<|k,METRIC|>), e.g.
"EUCLIDEAN", "COSINE", "MANHATTAN".
Sourcepub fn ef(self, ef: u32) -> VectorSearch<T>
pub fn ef(self, ef: u32) -> VectorSearch<T>
HNSW KNN with explicit candidate-list size ef (<|k,ef|>); larger ef
trades latency for recall. Defaults to ef = k when unset.
Sourcepub fn filter(self, expr: impl DynExpr + 'static) -> VectorSearch<T>
pub fn filter(self, expr: impl DynExpr + 'static) -> VectorSearch<T>
AND an additional predicate onto the WHERE clause.
Sourcepub fn distance_as(self, alias: impl Into<String>) -> VectorSearch<T>
pub fn distance_as(self, alias: impl Into<String>) -> VectorSearch<T>
Project the computed distance as vector::distance::knn() AS <alias>.
Sourcepub fn order_by_distance(self) -> VectorSearch<T>
pub fn order_by_distance(self) -> VectorSearch<T>
ORDER BY <distance> — nearest first. Projects the computed distance
(default alias distance), since ORDER BY sorts on the projected alias
rather than the vector::distance::knn() call directly.
Sourcepub fn limit(self, n: u32) -> VectorSearch<T>
pub fn limit(self, n: u32) -> VectorSearch<T>
LIMIT n.
Sourcepub fn to_surrealql(&self) -> String
pub fn to_surrealql(&self) -> String
Render to a SurrealQL string with the query vector inlined.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for VectorSearch<T>
impl<T> !UnwindSafe for VectorSearch<T>
impl<T> Freeze for VectorSearch<T>
impl<T> Send for VectorSearch<T>
impl<T> Sync for VectorSearch<T>
impl<T> Unpin for VectorSearch<T>where
T: Unpin,
impl<T> UnsafeUnpin for VectorSearch<T>
Blanket Implementations§
impl<T> AsyncFriendly for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request