pub struct VectorRecord { /* private fields */ }Expand description
A vector store record.
Implementations§
Source§impl VectorRecord
impl VectorRecord
Sourcepub fn new(id: VectorId, embedding: Embedding) -> VectorRecord
pub fn new(id: VectorId, embedding: Embedding) -> VectorRecord
Creates a vector record.
Examples found in repository?
examples/basic_usage.rs (lines 22-25)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let collection = CollectionName::new("customers");
8 let document_id = DocumentId::new("customer_123");
9 let patch = PatchSet::new(vec![PatchOperation::set(
10 DocumentPath::new("profile.display_name"),
11 "Joshua Whalen",
12 )]);
13
14 let key = CacheKey::builder()
15 .namespace(CacheNamespace::new("reviews"))
16 .segment("google-business-profile")
17 .segment("location")
18 .segment("fort-wayne")
19 .segment("summary")
20 .build();
21
22 let record = VectorRecord::new(
23 VectorId::new("review_789_embedding"),
24 Embedding::new(vec![0.012, -0.032, 0.481]),
25 )
26 .with_dimension(VectorDimension::new(3))?
27 .with_similarity_metric(SimilarityMetric::Cosine);
28
29 assert_eq!(collection.as_str(), "customers");
30 assert_eq!(document_id.as_str(), "customer_123");
31 assert_eq!(patch.operations().len(), 1);
32 assert_eq!(
33 key.to_string(),
34 "reviews:google-business-profile:location:fort-wayne:summary"
35 );
36 assert_eq!(record.dimension(), Some(VectorDimension::new(3)));
37
38 Ok(())
39}Sourcepub fn with_dimension(
self,
dimension: VectorDimension,
) -> Result<VectorRecord, InvalidDimensionError>
pub fn with_dimension( self, dimension: VectorDimension, ) -> Result<VectorRecord, InvalidDimensionError>
Sets and validates the expected dimension.
Examples found in repository?
examples/basic_usage.rs (line 26)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let collection = CollectionName::new("customers");
8 let document_id = DocumentId::new("customer_123");
9 let patch = PatchSet::new(vec![PatchOperation::set(
10 DocumentPath::new("profile.display_name"),
11 "Joshua Whalen",
12 )]);
13
14 let key = CacheKey::builder()
15 .namespace(CacheNamespace::new("reviews"))
16 .segment("google-business-profile")
17 .segment("location")
18 .segment("fort-wayne")
19 .segment("summary")
20 .build();
21
22 let record = VectorRecord::new(
23 VectorId::new("review_789_embedding"),
24 Embedding::new(vec![0.012, -0.032, 0.481]),
25 )
26 .with_dimension(VectorDimension::new(3))?
27 .with_similarity_metric(SimilarityMetric::Cosine);
28
29 assert_eq!(collection.as_str(), "customers");
30 assert_eq!(document_id.as_str(), "customer_123");
31 assert_eq!(patch.operations().len(), 1);
32 assert_eq!(
33 key.to_string(),
34 "reviews:google-business-profile:location:fort-wayne:summary"
35 );
36 assert_eq!(record.dimension(), Some(VectorDimension::new(3)));
37
38 Ok(())
39}Sourcepub const fn with_similarity_metric(
self,
similarity_metric: SimilarityMetric,
) -> VectorRecord
pub const fn with_similarity_metric( self, similarity_metric: SimilarityMetric, ) -> VectorRecord
Sets the similarity metric.
Examples found in repository?
examples/basic_usage.rs (line 27)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let collection = CollectionName::new("customers");
8 let document_id = DocumentId::new("customer_123");
9 let patch = PatchSet::new(vec![PatchOperation::set(
10 DocumentPath::new("profile.display_name"),
11 "Joshua Whalen",
12 )]);
13
14 let key = CacheKey::builder()
15 .namespace(CacheNamespace::new("reviews"))
16 .segment("google-business-profile")
17 .segment("location")
18 .segment("fort-wayne")
19 .segment("summary")
20 .build();
21
22 let record = VectorRecord::new(
23 VectorId::new("review_789_embedding"),
24 Embedding::new(vec![0.012, -0.032, 0.481]),
25 )
26 .with_dimension(VectorDimension::new(3))?
27 .with_similarity_metric(SimilarityMetric::Cosine);
28
29 assert_eq!(collection.as_str(), "customers");
30 assert_eq!(document_id.as_str(), "customer_123");
31 assert_eq!(patch.operations().len(), 1);
32 assert_eq!(
33 key.to_string(),
34 "reviews:google-business-profile:location:fort-wayne:summary"
35 );
36 assert_eq!(record.dimension(), Some(VectorDimension::new(3)));
37
38 Ok(())
39}Sourcepub fn with_metadata(self, metadata: VectorMetadata) -> VectorRecord
pub fn with_metadata(self, metadata: VectorMetadata) -> VectorRecord
Sets vector metadata.
Sourcepub const fn dimension(&self) -> Option<VectorDimension>
pub const fn dimension(&self) -> Option<VectorDimension>
Returns the validated dimension, if present.
Examples found in repository?
examples/basic_usage.rs (line 36)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let collection = CollectionName::new("customers");
8 let document_id = DocumentId::new("customer_123");
9 let patch = PatchSet::new(vec![PatchOperation::set(
10 DocumentPath::new("profile.display_name"),
11 "Joshua Whalen",
12 )]);
13
14 let key = CacheKey::builder()
15 .namespace(CacheNamespace::new("reviews"))
16 .segment("google-business-profile")
17 .segment("location")
18 .segment("fort-wayne")
19 .segment("summary")
20 .build();
21
22 let record = VectorRecord::new(
23 VectorId::new("review_789_embedding"),
24 Embedding::new(vec![0.012, -0.032, 0.481]),
25 )
26 .with_dimension(VectorDimension::new(3))?
27 .with_similarity_metric(SimilarityMetric::Cosine);
28
29 assert_eq!(collection.as_str(), "customers");
30 assert_eq!(document_id.as_str(), "customer_123");
31 assert_eq!(patch.operations().len(), 1);
32 assert_eq!(
33 key.to_string(),
34 "reviews:google-business-profile:location:fort-wayne:summary"
35 );
36 assert_eq!(record.dimension(), Some(VectorDimension::new(3)));
37
38 Ok(())
39}Sourcepub const fn similarity_metric(&self) -> Option<SimilarityMetric>
pub const fn similarity_metric(&self) -> Option<SimilarityMetric>
Returns the similarity metric, if present.
Sourcepub const fn metadata(&self) -> &VectorMetadata
pub const fn metadata(&self) -> &VectorMetadata
Returns vector metadata.
Trait Implementations§
Source§impl Clone for VectorRecord
impl Clone for VectorRecord
Source§fn clone(&self) -> VectorRecord
fn clone(&self) -> VectorRecord
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VectorRecord
impl Debug for VectorRecord
Source§impl PartialEq for VectorRecord
impl PartialEq for VectorRecord
Source§fn eq(&self, other: &VectorRecord) -> bool
fn eq(&self, other: &VectorRecord) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for VectorRecord
Auto Trait Implementations§
impl Freeze for VectorRecord
impl RefUnwindSafe for VectorRecord
impl Send for VectorRecord
impl Sync for VectorRecord
impl Unpin for VectorRecord
impl UnsafeUnpin for VectorRecord
impl UnwindSafe for VectorRecord
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