Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/main' into litellm_rust_qdrant_semantic_cache

Yujong Leebda406c0af65
diff --cc litellm-rust/Cargo.lock
index 238b869cb0b,b37202dce1b..f4b94ae44e2
--- a/litellm-rust/Cargo.lock
+++ b/litellm-rust/Cargo.lock
@@@ -2735,8 -2742,8 +2805,9 @@@ dependencies =
"litellm-auth",
"litellm-auth-gcp",
"litellm-cache",
+ "litellm-cache-azure-blob",
"litellm-cache-memory",
+ "litellm-cache-qdrant-semantic",
"litellm-cache-redis",
"litellm-cache-response",
"litellm-callbacks-legacy-python",
diff --cc litellm-rust/crates/python-bridge/src/cache/config.rs
index d7041b9c7da,5c962f2bc7a..7772716f128
--- a/litellm-rust/crates/python-bridge/src/cache/config.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/config.rs
@@@ -110,7 -94,7 +115,8 @@@ impl QdrantSemanticCacheConfig
pub(super) enum CacheBackendConfig {
Memory(MemoryCacheConfig),
Redis(Box<RedisCacheConfig>),
+ QdrantSemantic(Box<QdrantSemanticCacheConfig>),
+ AzureBlob(AzureBlobCacheConfig),
}
#[allow(dead_code, reason = "consumed by the cache activation follow-up")]
@@@ -183,19 -161,18 +189,24 @@@ impl NativeCacheConfig
}))),
Err(reason) => Ok(CacheConfigProjection::Unsupported(reason)),
},
+ Some(CacheType::QdrantSemantic) => match project_qdrant_semantic(&backend)? {
+ Ok(backend) => Ok(CacheConfigProjection::Native(Box::new(Self {
+ policy,
+ backend: CacheBackendConfig::QdrantSemantic(Box::new(backend)),
+ }))),
+ Err(reason) => Ok(CacheConfigProjection::Unsupported(reason)),
+ },
+ Some(CacheType::AzureBlob) => project_azure_blob(&backend).map(|backend| {
+ CacheConfigProjection::Native(Box::new(Self {
+ policy,
+ backend: CacheBackendConfig::AzureBlob(backend),
+ }))
+ }),
Some(
CacheType::RedisSemantic
| CacheType::ValkeySemantic
| CacheType::S3
| CacheType::Disk
- | CacheType::AzureBlob
- | CacheType::QdrantSemantic
| CacheType::Gcs,
)
| None => Ok(CacheConfigProjection::Unsupported(
@@@ -205,15 -182,18 +216,18 @@@
}
pub(super) fn service_mismatch(&self, service: &NativeResponseCache) -> Option<&'static str> {
+ let default_ttl = match &self.backend {
+ CacheBackendConfig::Memory(config) => Some(config.default_ttl),
+ CacheBackendConfig::Redis(config) => Some(config.default_ttl),
- CacheBackendConfig::AzureBlob(_) => None,
++ CacheBackendConfig::AzureBlob(_) | CacheBackendConfig::QdrantSemantic(_) => None,
+ };
+ if service.default_ttl() != default_ttl {
+ return Some("facade and native backend default TTLs must match");
+ }
match &self.backend {
- CacheBackendConfig::Memory(config) if service.kind() != "memory" => {
+ CacheBackendConfig::Memory(_) if service.kind() != "memory" => {
Some("facade and native backend types must match")
}
- CacheBackendConfig::Memory(config)
- if service.default_ttl() != Some(config.default_ttl) =>
- {
- Some("facade and native backend default TTLs must match")
- }
CacheBackendConfig::Memory(config) if service.capacity() != Some(config.capacity) => {
Some("facade and native backend capacities must match")
}
@@@ -231,134 -211,35 +245,154 @@@
}
CacheBackendConfig::Redis(config) => (service.namespace()
!= config.namespace.as_deref())
- .then_some("facade and native backend namespaces must match")
- .or_else(|| {
- (service.default_ttl() != Some(config.default_ttl))
- .then_some("facade and native backend default TTLs must match")
- }),
+ .then_some("facade and native backend namespaces must match"),
+ CacheBackendConfig::QdrantSemantic(config) if service.kind() != "qdrant_semantic" => {
+ Some("facade and native backend types must match")
+ }
+ CacheBackendConfig::QdrantSemantic(config)
+ if service.collection_name() != Some(config.collection_name.as_str()) =>
+ {
+ Some("facade and native backend collections must match")
+ }
+ CacheBackendConfig::QdrantSemantic(config)
+ if service.similarity_threshold() != Some(config.similarity_threshold) =>
+ {
+ Some("facade and native backend similarity thresholds must match")
+ }
+ CacheBackendConfig::QdrantSemantic(config)
+ if service.vector_size() != Some(config.vector_size) =>
+ {
+ Some("facade and native backend vector sizes must match")
+ }
+ CacheBackendConfig::QdrantSemantic(config)
+ if service.embedding_model() != Some(config.embedding.model.as_str()) =>
+ {
+ Some("facade and native backend embedding models must match")
+ }
+ CacheBackendConfig::QdrantSemantic(_) => None,
+ CacheBackendConfig::AzureBlob(config) => match service.azure_blob_identity() {
+ None => Some("facade and native backend types must match"),
+ Some((account_url, container))
+ if account_url != config.account_url || container != config.container =>
+ {
+ Some("facade and native backend containers must match")
+ }
+ Some(_) => None,
+ },
}
}
}
+#[inline(never)]
+fn project_qdrant_semantic(
+ backend: &Bound<'_, PyAny>,
+) -> PyResult<Result<QdrantSemanticCacheConfig, UnsupportedCacheConfig>> {
+ let rest_url = backend.getattr("qdrant_api_base")?.extract::<String>()?;
+ let parsed = match url::Url::parse(&rest_url) {
+ Ok(value) => value,
+ Err(_) => return Ok(Err(UnsupportedCacheConfig::QdrantEndpoint)),
+ };
+ if !matches!(parsed.scheme(), "http" | "https")
+ || !parsed.path().is_empty() && parsed.path() != "/"
+ || parsed.query().is_some()
+ || parsed.host_str().is_none()
+ || parsed.port().is_some_and(|port| port != 6333)
+ {
+ return Ok(Err(UnsupportedCacheConfig::QdrantEndpoint));
+ }
+ let mut grpc_url = parsed;
+ if grpc_url.set_port(Some(6334)).is_err() {
+ return Ok(Err(UnsupportedCacheConfig::QdrantEndpoint));
+ }
+ grpc_url.set_path("");
+ grpc_url.set_query(None);
+
+ let embedding_max_input_tokens = optional_attribute_i64(backend, "embedding_max_input_tokens")?;
+ if embedding_max_input_tokens.is_some() {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ }
+ let configured_model = backend.getattr("embedding_model")?.extract::<String>()?;
+ let embedding_model = configured_model
+ .strip_prefix("openai/")
+ .unwrap_or(&configured_model)
+ .to_owned();
+ if !embedding_model.starts_with("text-embedding-") {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ }
+ let proxy_server = py_sys_module(backend.py())?;
+ if let Some(proxy_server) = proxy_server {
+ let router = proxy_server.getattr("llm_router")?;
+ let model_list = proxy_server.getattr("llm_model_list")?;
+ let embedding_router = backend.py().import("litellm.caching._embedding_router")?;
+ if !embedding_router
+ .getattr("resolve_embedding_router")?
+ .call1((embedding_model.as_str(), router, model_list))?
+ .is_none()
+ {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ }
+ }
+ let litellm = backend.py().import("litellm")?;
+ for name in ["api_key", "openai_key", "api_base"] {
+ if !litellm.getattr(name)?.is_none() {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ }
+ }
+ let Ok(embedding_api_key) = env::var("OPENAI_API_KEY") else {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ };
+ if embedding_api_key.is_empty() {
+ return Ok(Err(UnsupportedCacheConfig::SemanticEmbedding));
+ }
+ let embedding_api_base = env::var("OPENAI_BASE_URL")
+ .or_else(|_| env::var("OPENAI_API_BASE"))
+ .unwrap_or_else(|_| "https://api.openai.com/v1".to_owned());
+ let timeout = optional_attribute_f64(backend, "embedding_timeout")?
+ .map(duration)
+ .transpose()?;
+ Ok(Ok(QdrantSemanticCacheConfig {
+ grpc_url: grpc_url.to_string().trim_end_matches('/').to_owned(),
+ api_key: optional_string(backend.getattr("qdrant_api_key")?)?,
+ collection_name: backend.getattr("collection_name")?.extract()?,
+ similarity_threshold: backend.getattr("similarity_threshold")?.extract()?,
+ vector_size: backend.getattr("vector_size")?.extract::<u64>()?,
+ embedding: OpenAiEmbedderConfig {
+ api_base: embedding_api_base,
+ api_key: embedding_api_key,
+ model: embedding_model,
+ timeout,
+ },
+ quantization: Quantization::Binary,
+ }))
+}
+
+fn py_sys_module(py: Python<'_>) -> PyResult<Option<Bound<'_, PyAny>>> {
+ match py
+ .import("sys")?
+ .getattr("modules")?
+ .get_item("litellm.proxy.proxy_server")
+ {
+ Ok(module) => Ok(Some(module)),
+ Err(error) if error.is_instance_of::<pyo3::exceptions::PyKeyError>(py) => Ok(None),
+ Err(error) => Err(error),
+ }
+}
+
+ #[inline(never)]
+ fn project_azure_blob(backend: &Bound<'_, PyAny>) -> PyResult<AzureBlobCacheConfig> {
+ let client = backend.getattr("container_client")?;
+ let container = client.getattr("container_name")?.extract::<String>()?;
+ let url = client.getattr("url")?.extract::<String>()?;
+ let account_url = url
+ .strip_suffix(container.as_str())
+ .and_then(|url| url.strip_suffix('/'))
+ .ok_or_else(|| PyValueError::new_err("Azure Blob container URL is malformed"))?;
+ Ok(AzureBlobCacheConfig {
+ account_url: account_url.to_string(),
+ container,
+ })
+ }
+
#[inline(never)]
fn project_memory(backend: &Bound<'_, PyAny>) -> PyResult<MemoryCacheConfig> {
let max_size_kib = backend.getattr("max_size_per_item")?.extract::<usize>()?;
diff --cc litellm-rust/crates/python-bridge/src/cache/facade.rs
index db37491653c,0e20676938f..f24c1b2e86d
--- a/litellm-rust/crates/python-bridge/src/cache/facade.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/facade.rs
@@@ -256,11 -295,11 +324,16 @@@ impl FacadeGuard
"RedisClusterCache",
"redis",
),
+ ("qdrant_semantic", _) => (
+ "litellm.caching.qdrant_semantic_cache",
+ "QdrantSemanticCache",
+ "qdrant-semantic",
+ ),
+ ("azure-blob", _) => (
+ "litellm.caching.azure_blob_cache",
+ "AzureBlobCache",
+ "azure-blob",
+ ),
_ => unreachable!(),
};
let backend = facade.getattr("cache")?;
@@@ -315,12 -333,19 +388,8 @@@
"semantic_cache_scope",
],
)?,
- backend: ObjectGuard::capture(
- py,
- &backend,
- &[
- "namespace",
- "default_ttl",
- "max_size_in_memory",
- "max_size_per_item",
- "redis_kwargs",
- "redis_flush_size",
- ],
- )?,
+ backend: ObjectGuard::capture(py, &backend, backend_config_names)?,
- redis_pool: match (kind, cluster) {
- ("redis", false) => Some(RedisPoolGuard::capture(&backend, STANDALONE_POOL)?),
- ("redis", true) => Some(RedisPoolGuard::capture(&backend, CLUSTER_POOL)?),
- _ => None,
- },
+ connection: ConnectionGuard::capture(kind, cluster, &backend)?,
})
}
diff --cc litellm-rust/crates/python-bridge/src/cache/handle.rs
index 9709bd68791,002cd6b7a33..94a2cfec2bd
--- a/litellm-rust/crates/python-bridge/src/cache/handle.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/handle.rs
@@@ -72,94 -64,14 +72,109 @@@ impl CacheTestHandle
})
}
+ #[staticmethod]
+ #[pyo3(signature = (url, *, collection_name, similarity_threshold, vector_size, embedding_model="text-embedding-3-small", api_key=None, embedding_api_key=None, embedding_api_base=None, embedding_timeout_seconds=None, quantization="binary"))]
+ #[expect(
+ clippy::too_many_arguments,
+ reason = "the test handle exposes the complete Qdrant constructor"
+ )]
+ fn qdrant_semantic(
+ py: Python<'_>,
+ url: String,
+ collection_name: String,
+ similarity_threshold: f64,
+ vector_size: u64,
+ embedding_model: &str,
+ api_key: Option<String>,
+ embedding_api_key: Option<String>,
+ embedding_api_base: Option<String>,
+ embedding_timeout_seconds: Option<f64>,
+ quantization: &str,
+ ) -> PyResult<Self> {
+ let parsed = Url::parse(&url).map_err(|_| {
+ pyo3::exceptions::PyValueError::new_err(
+ "native Qdrant requires the default REST port so the gRPC port can be derived",
+ )
+ })?;
+ if !matches!(parsed.scheme(), "http" | "https")
+ || (!parsed.path().is_empty() && parsed.path() != "/")
+ || parsed.query().is_some()
+ || parsed.host_str().is_none()
+ || parsed.port().is_some_and(|port| port != 6333)
+ {
+ return Err(pyo3::exceptions::PyValueError::new_err(
+ "native Qdrant requires the default REST port so the gRPC port can be derived",
+ ));
+ }
+ let mut grpc_url = parsed;
+ grpc_url.set_port(Some(6334)).map_err(|_| {
+ pyo3::exceptions::PyValueError::new_err(
+ "native Qdrant requires the default REST port so the gRPC port can be derived",
+ )
+ })?;
+ grpc_url.set_path("");
+ grpc_url.set_query(None);
+ let embedding_api_key = embedding_api_key
+ .or_else(|| {
+ env::var("OPENAI_API_KEY")
+ .ok()
+ .filter(|value| !value.is_empty())
+ })
+ .ok_or_else(|| {
+ pyo3::exceptions::PyValueError::new_err(
+ "native semantic embedding requires an OpenAI API key",
+ )
+ })?;
+ let embedding_api_base = embedding_api_base.unwrap_or_else(|| {
+ env::var("OPENAI_BASE_URL")
+ .or_else(|_| env::var("OPENAI_API_BASE"))
+ .unwrap_or_else(|_| "https://api.openai.com/v1".to_owned())
+ });
+ let quantization = match quantization {
+ "binary" => Quantization::Binary,
+ "scalar" => Quantization::Scalar,
+ "product" => Quantization::Product,
+ _ => {
+ return Err(pyo3::exceptions::PyValueError::new_err(
+ "unsupported Qdrant quantization",
+ ));
+ }
+ };
+ let config = QdrantSemanticCacheConfig {
+ grpc_url: grpc_url.to_string().trim_end_matches('/').to_owned(),
+ api_key,
+ collection_name,
+ similarity_threshold,
+ vector_size,
+ embedding: OpenAiEmbedderConfig {
+ api_base: embedding_api_base,
+ api_key: embedding_api_key,
+ model: embedding_model.to_owned(),
+ timeout: embedding_timeout_seconds.map(duration).transpose()?,
+ },
+ quantization,
+ };
+ let service = run_sync_value(py, async move {
+ let handle = tokio::runtime::Handle::current();
+ NativeResponseCache::qdrant_semantic(config, handle)
+ .await
+ .map_err(cache_error)
+ })?;
++ Ok(Self {
++ service,
++ guard: None,
++ pid: std::process::id(),
++ })
++ }
++
+ #[staticmethod]
+ #[pyo3(signature = (account_url, container))]
+ fn azure_blob(py: Python<'_>, account_url: String, container: String) -> PyResult<Self> {
+ let service = run_sync_value(py, async move {
+ NativeResponseCache::azure_blob(&account_url, &container)
+ .await
+ .map_err(cache_error)
+ })?;
Ok(Self {
service,
guard: None,
diff --cc litellm-rust/crates/python-bridge/src/cache/native.rs
index b93f15e59f3,2cd72a7ce14..0e14b9cb39c
--- a/litellm-rust/crates/python-bridge/src/cache/native.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/native.rs
@@@ -1,8 -1,8 +1,9 @@@
use std::{sync::Arc, time::Duration};
-use litellm_cache::{CacheCodec, CacheConnectionResult, Error};
+use litellm_cache::{CacheCodec, CacheConnectionResult, Error, SemanticCacheContext};
+ use litellm_cache_azure_blob::AzureBlobCache;
use litellm_cache_memory::InMemoryCache;
+use litellm_cache_qdrant_semantic::{Embedder, OpenAiEmbedder, QdrantSemanticCache};
use litellm_cache_redis::{RedisCache, RedisTopology};
use litellm_cache_response::{
CacheEntry, PartialHits, ResponseCache, ResponseCacheCodec, ResponseCacheRequest, WriteBuffer,
@@@ -18,7 -16,7 +19,8 @@@ pub(super) enum NativeResponseCache
cache: Arc<ResponseCache<RedisCache<ResponseCacheCodec>>>,
buffer: Option<Arc<WriteBuffer>>,
},
+ QdrantSemantic(Arc<ResponseCache<QdrantSemanticCache<OpenAiEmbedder, ResponseCacheCodec>>>),
+ AzureBlob(Arc<ResponseCache<AzureBlobCache<ResponseCacheCodec>>>),
}
impl NativeResponseCache {
@@@ -50,29 -48,28 +52,52 @@@
})
}
+ pub async fn qdrant_semantic(
+ config: QdrantSemanticCacheConfig,
+ runtime: tokio::runtime::Handle,
+ ) -> Result<Self, Error> {
+ let client = qdrant_client::Qdrant::from_url(&config.grpc_url)
+ .skip_compatibility_check()
+ .api_key(config.api_key.as_deref())
+ .build()
+ .map_err(|_| Error::Unavailable)?;
+ let qdrant_config = config.to_qdrant_config();
+ let embedder = OpenAiEmbedder::new(config.embedding)?;
+ let cache = QdrantSemanticCache::connect(
+ client,
+ embedder,
+ ResponseCacheCodec,
+ qdrant_config,
+ runtime,
+ )
+ .await?;
+ Ok(Self::QdrantSemantic(Arc::new(ResponseCache::new(
+ Arc::new(cache),
+ ))))
+ }
++
+ pub async fn azure_blob(account_url: &str, container: &str) -> Result<Self, Error> {
+ let backend = AzureBlobCache::connect(
+ account_url,
+ container,
+ ResponseCacheCodec,
+ tokio::runtime::Handle::current(),
+ )
+ .await?;
+ Ok(Self::AzureBlob(Arc::new(ResponseCache::new(Arc::new(
+ backend,
+ )))))
+ }
+
+ pub fn azure_blob_identity(&self) -> Option<(&str, &str)> {
+ match self {
+ Self::AzureBlob(cache) => Some((
+ cache.backend().account_url(),
+ cache.backend().container_name(),
+ )),
- Self::Memory(_) | Self::Redis { .. } => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::QdrantSemantic(_) => None,
+ }
+ }
}
impl NativeResponseCache {
@@@ -80,7 -77,7 +105,8 @@@
match self {
Self::Memory(_) => "memory",
Self::Redis { .. } => "redis",
+ Self::QdrantSemantic(_) => "qdrant_semantic",
+ Self::AzureBlob(_) => "azure-blob",
}
}
@@@ -88,39 -85,35 +114,42 @@@
match self {
Self::Memory(cache) => cache.default_ttl(),
Self::Redis { cache, .. } => cache.default_ttl(),
+ Self::QdrantSemantic(_) => None,
+ Self::AzureBlob(cache) => cache.default_ttl(),
}
}
pub fn namespace(&self) -> Option<&str> {
match self {
- Self::Memory(_) => None,
+ Self::Memory(_) | Self::AzureBlob(_) => None,
Self::Redis { cache, .. } => cache.backend().namespace(),
+ Self::QdrantSemantic(_) => None,
}
}
pub fn topology(&self) -> Option<&RedisTopology> {
match self {
- Self::Memory(_) => None,
+ Self::Memory(_) | Self::AzureBlob(_) => None,
Self::Redis { cache, .. } => Some(cache.backend().topology()),
+ Self::QdrantSemantic(_) => None,
}
}
pub fn capacity(&self) -> Option<usize> {
match self {
Self::Memory(cache) => Some(cache.backend().max_size_in_memory()),
- Self::Redis { .. } | Self::AzureBlob(_) => None,
+ Self::Redis { .. } => None,
+ Self::QdrantSemantic(_) => None,
++ Self::AzureBlob(_) => None,
}
}
pub fn max_entry_bytes(&self) -> Option<usize> {
match self {
Self::Memory(cache) => cache.backend().max_entry_bytes(),
- Self::Redis { .. } | Self::AzureBlob(_) => None,
+ Self::Redis { .. } => None,
+ Self::QdrantSemantic(_) => None,
++ Self::AzureBlob(_) => None,
}
}
@@@ -168,9 -133,9 +197,10 @@@
now: Duration,
) -> Result<Option<Value>, Error> {
match self {
- Self::Memory(cache) => cache.lookup(request, now),
- Self::Redis { cache, .. } => cache.lookup(request, now),
- Self::AzureBlob(cache) => cache.lookup(request, now),
+ Self::Memory(cache) => cache.lookup(&exact(request), now),
+ Self::Redis { cache, .. } => cache.lookup(&exact(request), now),
+ Self::QdrantSemantic(cache) => cache.lookup(request, now),
++ Self::AzureBlob(cache) => cache.lookup(&exact(request), now),
}
}
@@@ -181,9 -146,9 +211,10 @@@
now: Duration,
) -> Result<(), Error> {
match self {
- Self::Memory(cache) => cache.store(request, response, now),
- Self::Redis { cache, .. } => cache.store(request, response, now),
- Self::AzureBlob(cache) => cache.store(request, response, now),
+ Self::Memory(cache) => cache.store(&exact(request), response, now),
+ Self::Redis { cache, .. } => cache.store(&exact(request), response, now),
+ Self::QdrantSemantic(cache) => cache.store(request, response, now),
++ Self::AzureBlob(cache) => cache.store(&exact(request), response, now),
}
}
@@@ -193,13 -158,9 +224,16 @@@
now: Duration,
) -> Result<PartialHits, Error> {
match self {
- Self::Memory(cache) => cache.lookup_batch(requests, now),
- Self::Redis { cache, .. } => cache.lookup_batch(requests, now),
- Self::AzureBlob(cache) => cache.lookup_batch(requests, now),
+ Self::Memory(cache) => {
+ cache.lookup_batch(&requests.iter().map(exact).collect::<Vec<_>>(), now)
+ }
+ Self::Redis { cache, .. } => {
+ cache.lookup_batch(&requests.iter().map(exact).collect::<Vec<_>>(), now)
+ }
+ Self::QdrantSemantic(_) => Err(Error::UnsupportedOperation),
++ Self::AzureBlob(cache) => {
++ cache.lookup_batch(&requests.iter().map(exact).collect::<Vec<_>>(), now)
++ }
}
}
@@@ -209,9 -170,9 +243,10 @@@
now: Duration,
) -> Result<Option<Value>, Error> {
match self {
- Self::Memory(cache) => cache.async_lookup(request, now).await,
- Self::Redis { cache, .. } => cache.async_lookup(request, now).await,
- Self::AzureBlob(cache) => cache.async_lookup(request, now).await,
+ Self::Memory(cache) => cache.async_lookup(&exact(request), now).await,
+ Self::Redis { cache, .. } => cache.async_lookup(&exact(request), now).await,
+ Self::QdrantSemantic(cache) => cache.async_lookup(request, now).await,
++ Self::AzureBlob(cache) => cache.async_lookup(&exact(request), now).await,
}
}
@@@ -230,11 -191,8 +265,12 @@@
Self::Redis {
cache,
buffer: Some(buffer),
- } => buffer.async_store(cache, request, response, now).await,
- Self::AzureBlob(cache) => cache.async_store(request, response, now).await,
+ } => {
+ let request = exact(request);
+ buffer.async_store(cache, &request, response, now).await
+ }
+ Self::QdrantSemantic(cache) => cache.async_store(request, response, now).await,
++ Self::AzureBlob(cache) => cache.async_store(&exact(request), response, now).await,
}
}
@@@ -244,15 -202,9 +280,19 @@@
now: Duration,
) -> Result<PartialHits, Error> {
match self {
- Self::Memory(cache) => cache.async_lookup_batch(requests, now).await,
- Self::Redis { cache, .. } => cache.async_lookup_batch(requests, now).await,
- Self::AzureBlob(cache) => cache.async_lookup_batch(requests, now).await,
+ Self::Memory(cache) => {
+ let requests = requests.iter().map(exact).collect::<Vec<_>>();
+ cache.async_lookup_batch(&requests, now).await
+ }
+ Self::Redis { cache, .. } => {
+ let requests = requests.iter().map(exact).collect::<Vec<_>>();
+ cache.async_lookup_batch(&requests, now).await
+ }
+ Self::QdrantSemantic(_) => Err(Error::UnsupportedOperation),
++ Self::AzureBlob(cache) => {
++ let requests = requests.iter().map(exact).collect::<Vec<_>>();
++ cache.async_lookup_batch(&requests, now).await
++ }
}
}
@@@ -262,29 -214,9 +302,40 @@@
now: Duration,
) -> Result<(), Error> {
match self {
- Self::Memory(cache) => cache.async_store_batch(entries, now).await,
- Self::Redis { cache, .. } => cache.async_store_batch(entries, now).await,
- Self::AzureBlob(cache) => cache.async_store_batch(entries, now).await,
+ Self::Memory(cache) => {
+ cache
+ .async_store_batch(
+ entries
+ .into_iter()
+ .map(|(request, value)| (exact(&request), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
+ Self::Redis { cache, .. } => {
+ cache
+ .async_store_batch(
+ entries
+ .into_iter()
+ .map(|(request, value)| (exact(&request), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
+ Self::QdrantSemantic(cache) => cache.async_store_batch(entries, now).await,
++ Self::AzureBlob(cache) => {
++ cache
++ .async_store_batch(
++ entries
++ .into_iter()
++ .map(|(request, value)| (exact(&request), value))
++ .collect(),
++ now,
++ )
++ .await
++ }
}
}
@@@ -297,7 -229,7 +348,8 @@@
}
cache.async_flush().await
}
+ Self::QdrantSemantic(_) => Err(Error::UnsupportedOperation),
+ Self::AzureBlob(cache) => cache.async_flush().await,
}
}
@@@ -305,7 -237,7 +357,8 @@@
match self {
Self::Memory(cache) => cache.test_connection().await,
Self::Redis { cache, .. } => cache.test_connection().await,
+ Self::QdrantSemantic(_) => Err(Error::UnsupportedOperation),
+ Self::AzureBlob(cache) => cache.test_connection().await,
}
}
}