Skip to main content

Query

Struct Query 

Source
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: usize

Maximum number of scored points to return.

§filter: Option<Filter>

Optional point filter applied before final ranking.

§with_payload: bool

Whether returned winners include their JSON payloads.

§with_vector: bool

Whether returned winners include their stored vectors.

§expected_vector_space: Option<String>

Optional vector-space identity that must match collection metadata.

§params: QueryParams

Exact or approximate execution controls.

Implementations§

Source§

impl Query

Source

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?
examples/filtering.rs (line 12)
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}
Source

pub fn exact(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self

Creates a query that scores every eligible point.

Source

pub fn approximate(vector: impl IntoIterator<Item = f32>, limit: usize) -> Self

Creates a query that uses deterministic approximate candidate discovery.

Source

pub fn with_filter(self, filter: Filter) -> Self

Adds a point filter.

Examples found in repository?
examples/filtering.rs (line 13)
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}
Source

pub fn with_payload(self) -> Self

Requests payloads for returned winners.

Examples found in repository?
examples/filtering.rs (line 14)
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}
Source

pub fn with_vector(self) -> Self

Requests stored vectors for returned winners.

Source

pub fn in_vector_space(self, vector_space: impl Into<String>) -> Self

Requires the collection to use the supplied vector-space identity.

Source

pub fn with_params(self, params: QueryParams) -> Self

Replaces the exact or approximate execution parameters.

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Query

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Query

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Query
where Query: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Query

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V