pub struct CacheKeyBuilder { /* private fields */ }Expand description
Builder for composed cache keys.
Implementations§
Source§impl CacheKeyBuilder
impl CacheKeyBuilder
Sourcepub const fn new() -> CacheKeyBuilder
pub const fn new() -> CacheKeyBuilder
Creates an empty cache key builder.
Sourcepub fn namespace(self, namespace: CacheNamespace) -> CacheKeyBuilder
pub fn namespace(self, namespace: CacheNamespace) -> CacheKeyBuilder
Sets the namespace prefix.
Examples found in repository?
examples/basic_usage.rs (line 15)
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 segment(self, segment: impl AsRef<str>) -> CacheKeyBuilder
pub fn segment(self, segment: impl AsRef<str>) -> CacheKeyBuilder
Adds a non-empty segment.
Examples found in repository?
examples/basic_usage.rs (line 16)
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 build(self) -> CacheKey
pub fn build(self) -> CacheKey
Builds the cache key using : separators.
Examples found in repository?
examples/basic_usage.rs (line 20)
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}Trait Implementations§
Source§impl Clone for CacheKeyBuilder
impl Clone for CacheKeyBuilder
Source§fn clone(&self) -> CacheKeyBuilder
fn clone(&self) -> CacheKeyBuilder
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 CacheKeyBuilder
impl Debug for CacheKeyBuilder
Source§impl Default for CacheKeyBuilder
impl Default for CacheKeyBuilder
Source§fn default() -> CacheKeyBuilder
fn default() -> CacheKeyBuilder
Returns the “default value” for a type. Read more
Source§impl PartialEq for CacheKeyBuilder
impl PartialEq for CacheKeyBuilder
Source§fn eq(&self, other: &CacheKeyBuilder) -> bool
fn eq(&self, other: &CacheKeyBuilder) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for CacheKeyBuilder
impl StructuralPartialEq for CacheKeyBuilder
Auto Trait Implementations§
impl Freeze for CacheKeyBuilder
impl RefUnwindSafe for CacheKeyBuilder
impl Send for CacheKeyBuilder
impl Sync for CacheKeyBuilder
impl Unpin for CacheKeyBuilder
impl UnsafeUnpin for CacheKeyBuilder
impl UnwindSafe for CacheKeyBuilder
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