pub struct Query {
pub vector: Vec<f32>,
pub limit: usize,
pub filter: Option<Filter>,
pub with_payload: bool,
pub with_vector: bool,
pub expected_vector_space: Option<String>,
pub params: QueryParams,
}Expand description
A vector similarity query.
Fields§
§vector: Vec<f32>Query vector, which must match the collection dimension.
limit: usizeMaximum number of scored points to return.
filter: Option<Filter>Optional point filter applied before final ranking.
with_payload: boolWhether returned winners include their JSON payloads.
with_vector: boolWhether returned winners include their stored vectors.
expected_vector_space: Option<String>Optional vector-space identity that must match collection metadata.
params: QueryParamsExact or approximate execution controls.
Implementations§
Source§impl Query
impl Query
Sourcepub fn new(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
pub fn new(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
Creates a query using collection defaults for exact or approximate mode.
Examples found in repository?
4fn main() -> git_vdb::Result<()> {
5 let temporary = tempfile::TempDir::new()?;
6 let docs = open(temporary.path().join("vectors.git"))?.collection("docs");
7 docs.upsert([
8 Point::new("guide", [1.0, 0.0]).with_metadata(json!({"kind": "docs"}))?,
9 Point::new("code", [0.9, 0.1]).with_metadata(json!({"kind": "source"}))?,
10 ])?;
11 let result = docs.advanced()?.query(
12 Query::new([1.0, 0.0], 5)
13 .with_filter(Filter::must([Condition::matches("kind", "docs")]))
14 .with_payload(),
15 )?;
16 assert_eq!(result.points[0].id.to_string(), "guide");
17 Ok(())
18}Sourcepub fn exact(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
pub fn exact(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
Creates a query that scores every eligible point.
Sourcepub fn approximate(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
pub fn approximate(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self
Creates a query that uses deterministic approximate candidate discovery.
Sourcepub fn with_filter(self, filter: Filter) -> Self
pub fn with_filter(self, filter: Filter) -> Self
Adds a point filter.
Examples found in repository?
4fn main() -> git_vdb::Result<()> {
5 let temporary = tempfile::TempDir::new()?;
6 let docs = open(temporary.path().join("vectors.git"))?.collection("docs");
7 docs.upsert([
8 Point::new("guide", [1.0, 0.0]).with_metadata(json!({"kind": "docs"}))?,
9 Point::new("code", [0.9, 0.1]).with_metadata(json!({"kind": "source"}))?,
10 ])?;
11 let result = docs.advanced()?.query(
12 Query::new([1.0, 0.0], 5)
13 .with_filter(Filter::must([Condition::matches("kind", "docs")]))
14 .with_payload(),
15 )?;
16 assert_eq!(result.points[0].id.to_string(), "guide");
17 Ok(())
18}Sourcepub fn with_payload(self) -> Self
pub fn with_payload(self) -> Self
Requests payloads for returned winners.
Examples found in repository?
4fn main() -> git_vdb::Result<()> {
5 let temporary = tempfile::TempDir::new()?;
6 let docs = open(temporary.path().join("vectors.git"))?.collection("docs");
7 docs.upsert([
8 Point::new("guide", [1.0, 0.0]).with_metadata(json!({"kind": "docs"}))?,
9 Point::new("code", [0.9, 0.1]).with_metadata(json!({"kind": "source"}))?,
10 ])?;
11 let result = docs.advanced()?.query(
12 Query::new([1.0, 0.0], 5)
13 .with_filter(Filter::must([Condition::matches("kind", "docs")]))
14 .with_payload(),
15 )?;
16 assert_eq!(result.points[0].id.to_string(), "guide");
17 Ok(())
18}Sourcepub fn with_vector(self) -> Self
pub fn with_vector(self) -> Self
Requests stored vectors for returned winners.
Sourcepub fn in_vector_space(self, vector_space: impl Into<String>) -> Self
pub fn in_vector_space(self, vector_space: impl Into<String>) -> Self
Requires the collection to use the supplied vector-space identity.
Sourcepub fn with_params(self, params: QueryParams) -> Self
pub fn with_params(self, params: QueryParams) -> Self
Replaces the exact or approximate execution parameters.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Query
impl<'de> Deserialize<'de> for Query
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Query
impl RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl UnsafeUnpin for Query
impl UnwindSafe for Query
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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