pub struct Point {
pub id: PointId,
pub vector: Vec<f32>,
pub payload: JsonObject,
}Expand description
A vector and its optional JSON payload, identified by a typed ID.
Fields§
§id: PointIdThe stable typed identifier for this point.
vector: Vec<f32>The vector components, whose length must match the collection dimension.
payload: JsonObjectApplication-defined metadata used by filters and optional result output.
Implementations§
Source§impl Point
impl Point
Sourcepub fn new(
id: impl Into<PointId>,
vector: impl IntoIterator<Item = f32>,
) -> Self
pub fn new( id: impl Into<PointId>, vector: impl IntoIterator<Item = f32>, ) -> Self
Creates a point with an empty payload.
Examples found in repository?
More examples
examples/quickstart.rs (line 8)
3fn main() -> git_vdb::Result<()> {
4 let temporary = tempfile::TempDir::new()?;
5 let db = open(temporary.path().join("vectors.git"))?;
6 let docs = db.collection("docs");
7 docs.upsert([
8 Point::new("east", [1.0, 0.0]),
9 Point::new("north", [0.0, 1.0]),
10 ])?;
11 let hits = docs.search([0.9, 0.1], 1)?;
12 assert_eq!(hits[0].id.to_string(), "east");
13 Ok(())
14}examples/filtering.rs (line 8)
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, payload: JsonObject) -> Self
pub fn with_payload(self, payload: JsonObject) -> Self
Replaces the point payload and returns the updated point.
Sourcepub fn with_metadata(self, metadata: impl Serialize) -> Result<Self>
pub fn with_metadata(self, metadata: impl Serialize) -> Result<Self>
Serializes object-shaped metadata as the point payload.
Arrays, scalars, and null are rejected because persisted point payloads are always JSON objects.
Examples found in repository?
examples/filtering.rs (line 8)
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}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Point
impl<'de> Deserialize<'de> for Point
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>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Point
Auto Trait Implementations§
impl Freeze for Point
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnsafeUnpin for Point
impl UnwindSafe for Point
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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