pub struct SemanticCacheConfig {
pub enabled: bool,
pub embedding_url: String,
pub embedding_model: String,
pub embedding_dim: usize,
pub threshold: f64,
pub ttl_secs: u64,
pub max_entries: usize,
pub embedding_timeout_ms: u64,
pub embedding_api_key: Option<String>,
}Expand description
Semantic cache config (DW-083 ai.semantic_cache): an
embedding-similarity cache for AI prompts. A paraphrased prompt
within the cosine-similarity threshold returns the cached response
with no provider call and no token spend. Uses an external
embedding service (OpenAI-compatible /v1/embeddings API) to
vectorize prompts and hnsw_rs (pure Rust HNSW) for approximate
nearest neighbor search. Compiled into every build (hnsw_rs is
an unconditional dependency).
Fields§
§enabled: boolWhether the semantic cache is enabled. Default false: an
ai.semantic_cache block without enabled: true caches
nothing (the engine compiles but stays inert).
embedding_url: StringThe URL of the external embedding service (OpenAI-compatible /v1/embeddings API). Required when enabled. Validation rejects an empty or non-http(s) URL.
embedding_model: StringThe model name passed to the embedding service in the
model field of the POST body.
embedding_dim: usizeThe dimension of the embedding vectors. Must match what the embedding service returns for the configured model; validation rejects 0.
threshold: f64Cosine similarity threshold (0.0 to 1.0, inclusive). A cached entry is returned only if its cosine similarity to the query embedding is >= this threshold. Higher = stricter matching (fewer hits, more accurate). Default 0.85.
ttl_secs: u64TTL for cached entries in seconds. Entries older than this are considered stale and not returned. Default 3600 (1 hour).
max_entries: usizeMaximum number of entries to cache. When the cache is full, it is reset (all entries evicted, the HNSW index rebuilt). Default 10 000.
embedding_timeout_ms: u64Timeout for the embedding service HTTP call in milliseconds. Default 5000 (5 seconds).
embedding_api_key: Option<String>Optional API key for the embedding service (sent as
Authorization: Bearer <key>). Can be a ${...} secret
reference (resolved at config-compile time). Inline values
are redacted in config echoes; never logged.
Trait Implementations§
Source§impl Clone for SemanticCacheConfig
impl Clone for SemanticCacheConfig
Source§fn clone(&self) -> SemanticCacheConfig
fn clone(&self) -> SemanticCacheConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SemanticCacheConfig
impl Debug for SemanticCacheConfig
Source§impl<'de> Deserialize<'de> for SemanticCacheConfig
impl<'de> Deserialize<'de> for SemanticCacheConfig
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>,
Source§impl JsonSchema for SemanticCacheConfig
impl JsonSchema for SemanticCacheConfig
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for SemanticCacheConfig
impl PartialEq for SemanticCacheConfig
Source§impl Serialize for SemanticCacheConfig
impl Serialize for SemanticCacheConfig
impl StructuralPartialEq for SemanticCacheConfig
Auto Trait Implementations§
impl Freeze for SemanticCacheConfig
impl RefUnwindSafe for SemanticCacheConfig
impl Send for SemanticCacheConfig
impl Sync for SemanticCacheConfig
impl Unpin for SemanticCacheConfig
impl UnwindSafe for SemanticCacheConfig
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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