pub trait EmbeddingCache: Send {
Show 21 methods
// Required methods
fn register_profile(
&mut self,
id: &str,
profile: &CacheProfile,
) -> Result<()>;
fn resource_index(
&self,
profile: &str,
) -> Result<HashMap<ResourceId, CachedResourceState>>;
fn resource(
&self,
profile: &str,
path: &ResourceId,
) -> Result<Option<CachedResource>>;
fn put_resource(
&mut self,
profile: &str,
path: &ResourceId,
resource: &ResourceWrite<'_>,
) -> Result<()>;
fn touch_resource(
&mut self,
profile: &str,
path: &ResourceId,
metadata: &ResourceMetadata,
version: &ResourceVersion,
) -> Result<()>;
fn remove_resources(
&mut self,
profile: &str,
paths: &[ResourceId],
) -> Result<()>;
fn known_inputs(
&self,
profile: &str,
hashes: &[String],
) -> Result<HashSet<String>>;
fn put_embeddings(
&mut self,
profile: &str,
items: &[(String, Vec<f32>)],
) -> Result<()>;
fn vectors_for(
&self,
profile: &str,
paths: &HashSet<ResourceId>,
) -> Result<Vec<StoredVector>>;
fn lexical_search(
&self,
profile: &str,
query: &LexicalQuery,
paths: &HashSet<ResourceId>,
limit: usize,
) -> Result<Vec<LexicalHit>>;
fn lexical_matched_terms(
&self,
profile: &str,
query: &LexicalQuery,
keys: &[(ResourceId, usize)],
) -> Result<Vec<Vec<String>>>;
fn prune_orphans(&mut self, profile: &str) -> Result<u64>;
fn stats(&self) -> Result<CacheStats>;
fn clear(&mut self) -> Result<()>;
// Provided methods
fn scrub(&mut self) -> Result<CacheCleanup> { ... }
fn scrub_if_idle(
&mut self,
_quiet: Duration,
) -> Result<Option<CacheCleanup>> { ... }
fn scrub_delay(&self, quiet: Duration) -> Duration { ... }
fn supports_image_codes(&self) -> bool { ... }
fn sync_image_codes(
&mut self,
_profile: &str,
_paths: &HashSet<ResourceId>,
) -> Result<()> { ... }
fn image_scan_rows(
&self,
_profile: &str,
_paths: &HashSet<ResourceId>,
) -> Result<Vec<ScanVector>> { ... }
fn selected_image_vectors(
&self,
_profile: &str,
_hashes: &HashSet<String>,
) -> Result<HashMap<String, Vec<f32>>> { ... }
}Expand description
Storage for resource metadata, segment locators and vectors.
Unstable: exposes ResourceVersion and CachedResourceState, which may change before 1.0; filesystem is the only supported production provider.
Required Methods§
fn register_profile(&mut self, id: &str, profile: &CacheProfile) -> Result<()>
Sourcefn resource_index(
&self,
profile: &str,
) -> Result<HashMap<ResourceId, CachedResourceState>>
fn resource_index( &self, profile: &str, ) -> Result<HashMap<ResourceId, CachedResourceState>>
Every cached resource for a profile, keyed by identity. Segments are not loaded.
fn resource( &self, profile: &str, path: &ResourceId, ) -> Result<Option<CachedResource>>
Sourcefn put_resource(
&mut self,
profile: &str,
path: &ResourceId,
resource: &ResourceWrite<'_>,
) -> Result<()>
fn put_resource( &mut self, profile: &str, path: &ResourceId, resource: &ResourceWrite<'_>, ) -> Result<()>
Replace a resource and its segments.
Sourcefn touch_resource(
&mut self,
profile: &str,
path: &ResourceId,
metadata: &ResourceMetadata,
version: &ResourceVersion,
) -> Result<()>
fn touch_resource( &mut self, profile: &str, path: &ResourceId, metadata: &ResourceMetadata, version: &ResourceVersion, ) -> Result<()>
Update metadata and version when content is unchanged.
fn remove_resources( &mut self, profile: &str, paths: &[ResourceId], ) -> Result<()>
Sourcefn known_inputs(
&self,
profile: &str,
hashes: &[String],
) -> Result<HashSet<String>>
fn known_inputs( &self, profile: &str, hashes: &[String], ) -> Result<HashSet<String>>
Which of hashes already have a vector.
fn put_embeddings( &mut self, profile: &str, items: &[(String, Vec<f32>)], ) -> Result<()>
Sourcefn vectors_for(
&self,
profile: &str,
paths: &HashSet<ResourceId>,
) -> Result<Vec<StoredVector>>
fn vectors_for( &self, profile: &str, paths: &HashSet<ResourceId>, ) -> Result<Vec<StoredVector>>
All searchable vectors for the given paths.
Sourcefn lexical_search(
&self,
profile: &str,
query: &LexicalQuery,
paths: &HashSet<ResourceId>,
limit: usize,
) -> Result<Vec<LexicalHit>>
fn lexical_search( &self, profile: &str, query: &LexicalQuery, paths: &HashSet<ResourceId>, limit: usize, ) -> Result<Vec<LexicalHit>>
Segments of paths matching query by keyword, best first, at most limit.
Equal scores are ordered by path bytes, then segment ordinal.
Sourcefn lexical_matched_terms(
&self,
profile: &str,
query: &LexicalQuery,
keys: &[(ResourceId, usize)],
) -> Result<Vec<Vec<String>>>
fn lexical_matched_terms( &self, profile: &str, query: &LexicalQuery, keys: &[(ResourceId, usize)], ) -> Result<Vec<Vec<String>>>
Query tokens confirmed by the cached index for the requested segments. Called only for final hits ranked by the keyword leg, after fusion and eligibility checks. Return one term list per key, in the same order. Never recover source text; report only complete matching query groups.
Sourcefn prune_orphans(&mut self, profile: &str) -> Result<u64>
fn prune_orphans(&mut self, profile: &str) -> Result<u64>
Drop vectors no segment refers to any more.
fn stats(&self) -> Result<CacheStats>
fn clear(&mut self) -> Result<()>
Provided Methods§
Sourcefn scrub(&mut self) -> Result<CacheCleanup>
fn scrub(&mut self) -> Result<CacheCleanup>
Erase stale FTS postings and historical WAL frames. Busy readers leave work pending.
Sourcefn scrub_if_idle(&mut self, _quiet: Duration) -> Result<Option<CacheCleanup>>
fn scrub_if_idle(&mut self, _quiet: Duration) -> Result<Option<CacheCleanup>>
Attempt a background scrub after this long without writes. Busy work is retried at the same interval, rather than on every scheduler tick.
Sourcefn scrub_delay(&self, quiet: Duration) -> Duration
fn scrub_delay(&self, quiet: Duration) -> Duration
Scheduler delay until the next quiet-period/retry deadline. When idle, check at this interval to observe activity from other processes.
Sourcefn supports_image_codes(&self) -> bool
fn supports_image_codes(&self) -> bool
Whether persistent Photo Anchor representations are supported.
Sourcefn sync_image_codes(
&mut self,
_profile: &str,
_paths: &HashSet<ResourceId>,
) -> Result<()>
fn sync_image_codes( &mut self, _profile: &str, _paths: &HashSet<ResourceId>, ) -> Result<()>
Derive missing image codes from retained f32 during an opted-in sync.
Sourcefn image_scan_rows(
&self,
_profile: &str,
_paths: &HashSet<ResourceId>,
) -> Result<Vec<ScanVector>>
fn image_scan_rows( &self, _profile: &str, _paths: &HashSet<ResourceId>, ) -> Result<Vec<ScanVector>>
Read representations without writing or loading f32 for coded images.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".