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_native_redis_semantic_cache

Yujong Lee0116a502bcb9
diff --cc litellm-rust/Cargo.lock
index 5c1688acac1,1a4eb51af08..f39f5b3ea95
--- a/litellm-rust/Cargo.lock
+++ b/litellm-rust/Cargo.lock
@@@ -2758,9 -2814,9 +2829,10 @@@ dependencies =
"litellm-auth-gcp",
"litellm-cache",
"litellm-cache-azure-blob",
+ "litellm-cache-disk",
"litellm-cache-memory",
"litellm-cache-redis",
+ "litellm-cache-redis-semantic",
"litellm-cache-response",
"litellm-callbacks-legacy-python",
"litellm-core",
diff --cc litellm-rust/Cargo.toml
index 91e0cc08c8f,fabec9bcd6c..c152409decb
--- a/litellm-rust/Cargo.toml
+++ b/litellm-rust/Cargo.toml
@@@ -32,7 -32,7 +32,8 @@@ litellm-cache = { path = "crates/cache
litellm-cache-azure-blob = { path = "crates/cache-azure-blob" }
litellm-cache-memory = { path = "crates/cache-memory" }
litellm-cache-redis = { path = "crates/cache-redis" }
+ litellm-cache-disk = { path = "crates/cache-disk" }
+litellm-cache-redis-semantic = { path = "crates/cache-redis-semantic" }
litellm-cache-response = { path = "crates/cache-response" }
litellm-token-counter = { path = "crates/token-counter" }
litellm-token-counter-fast = { path = "crates/token-counter-fast" }
diff --cc litellm-rust/crates/python-bridge/Cargo.toml
index 507bd20348a,f5d08850b39..02c3f9653dc
--- a/litellm-rust/crates/python-bridge/Cargo.toml
+++ b/litellm-rust/crates/python-bridge/Cargo.toml
@@@ -24,7 -24,7 +24,8 @@@ litellm-cache.workspace = tru
litellm-cache-azure-blob.workspace = true
litellm-cache-memory.workspace = true
litellm-cache-redis.workspace = true
+ litellm-cache-disk.workspace = true
+litellm-cache-redis-semantic.workspace = true
litellm-cache-response.workspace = true
serde.workspace = true
litellm-auth.workspace = true
diff --cc litellm-rust/crates/python-bridge/src/cache/config.rs
index 3db49f9dfc5,927017e2e60..3166a228b9d
--- a/litellm-rust/crates/python-bridge/src/cache/config.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/config.rs
@@@ -107,8 -98,8 +111,9 @@@ const REDIS_PY_DEFAULT_MAX_CONNECTIONS
pub(super) enum CacheBackendConfig {
Memory(MemoryCacheConfig),
Redis(Box<RedisCacheConfig>),
+ Disk(DiskCacheConfig),
AzureBlob(AzureBlobCacheConfig),
+ RedisSemantic(Box<RedisSemanticCacheConfig>),
}
#[allow(dead_code, reason = "consumed by the cache activation follow-up")]
@@@ -181,16 -181,10 +195,15 @@@ impl NativeCacheConfig
backend: CacheBackendConfig::AzureBlob(backend),
}))
}),
+ Some(CacheType::RedisSemantic) => project_redis_semantic(&backend).map(|backend| {
+ CacheConfigProjection::Native(Box::new(Self {
+ policy,
+ backend: CacheBackendConfig::RedisSemantic(Box::new(backend)),
+ }))
+ }),
Some(
- CacheType::RedisSemantic
- | CacheType::ValkeySemantic
+ CacheType::ValkeySemantic
| CacheType::S3
- | CacheType::Disk
| CacheType::QdrantSemantic
| CacheType::Gcs,
)
@@@ -204,7 -198,8 +217,8 @@@
let default_ttl = match &self.backend {
CacheBackendConfig::Memory(config) => Some(config.default_ttl),
CacheBackendConfig::Redis(config) => Some(config.default_ttl),
+ CacheBackendConfig::Disk(_) => None,
- CacheBackendConfig::AzureBlob(_) => None,
+ CacheBackendConfig::AzureBlob(_) | CacheBackendConfig::RedisSemantic(_) => None,
};
if service.default_ttl() != default_ttl {
return Some("facade and native backend default TTLs must match");
@@@ -231,20 -226,17 +245,31 @@@
CacheBackendConfig::Redis(config) => (service.namespace()
!= config.namespace.as_deref())
.then_some("facade and native backend namespaces must match"),
+ CacheBackendConfig::Disk(_) if service.kind() != "disk" => {
+ Some("facade and native backend types must match")
+ }
+ CacheBackendConfig::Disk(config) => {
+ let Some(directory) = service.directory() else {
+ return Some("facade and native backend types must match");
+ };
+ let native = std::fs::canonicalize(directory).ok();
+ let facade = std::fs::canonicalize(&config.directory).ok();
+ (native != facade).then_some("facade and native backend directories must match")
+ }
+ CacheBackendConfig::RedisSemantic(_) if service.kind() != "redis_semantic" => {
+ Some("facade and native backend types must match")
+ }
+ CacheBackendConfig::RedisSemantic(config)
+ if service.index_name() != Some(config.index_name.as_str()) =>
+ {
+ Some("facade and native backend index names must match")
+ }
+ CacheBackendConfig::RedisSemantic(config)
+ if service.similarity_threshold() != Some(config.similarity_threshold as f32) =>
+ {
+ Some("facade and native backend similarity thresholds must match")
+ }
+ CacheBackendConfig::RedisSemantic(_) => None,
CacheBackendConfig::AzureBlob(config) => match service.azure_blob_identity() {
None => Some("facade and native backend types must match"),
Some((account_url, container))
diff --cc litellm-rust/crates/python-bridge/src/cache/facade.rs
index bf1b69cfbf5,ee6423daf6e..5b49166541b
--- a/litellm-rust/crates/python-bridge/src/cache/facade.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/facade.rs
@@@ -360,15 -369,11 +386,18 @@@ impl FacadeGuard
"max_size_per_item",
"redis_kwargs",
"redis_flush_size",
+ "similarity_threshold",
+ "distance_threshold",
+ "embedding_model",
+ "embedding_max_input_tokens",
+ "embedding_timeout",
+ "_index_name",
+ "_redis_url",
],
)?,
+ disk_store: (kind == "disk")
+ .then(|| DiskStoreGuard::capture(&backend))
+ .transpose()?,
connection: ConnectionGuard::capture(kind, cluster, &backend)?,
})
}
diff --cc litellm-rust/crates/python-bridge/src/cache/native.rs
index bad2c30f189,80789cc279a..da09b165aad
--- a/litellm-rust/crates/python-bridge/src/cache/native.rs
+++ b/litellm-rust/crates/python-bridge/src/cache/native.rs
@@@ -1,10 -1,10 +1,11 @@@
- use std::{sync::Arc, time::Duration};
+ use std::{path::Path, sync::Arc, time::Duration};
-use litellm_cache::{CacheCodec, CacheConnectionResult, Error};
+use litellm_cache::{CacheCodec, CacheConnectionResult, Error, ExactCacheContext};
use litellm_cache_azure_blob::AzureBlobCache;
+ use litellm_cache_disk::DiskCache;
use litellm_cache_memory::InMemoryCache;
use litellm_cache_redis::{RedisCache, RedisTopology};
+use litellm_cache_redis_semantic::{RedisSemanticCache, RedisSemanticConfig};
use litellm_cache_response::{
CacheEntry, PartialHits, ResponseCache, ResponseCacheCodec, ResponseCacheRequest, WriteBuffer,
};
@@@ -20,8 -17,8 +21,9 @@@ pub(super) enum NativeResponseCache
cache: Arc<ResponseCache<RedisCache<ResponseCacheCodec>>>,
buffer: Option<Arc<WriteBuffer>>,
},
+ Disk(Arc<ResponseCache<DiskCache<ResponseCacheCodec>>>),
AzureBlob(Arc<ResponseCache<AzureBlobCache<ResponseCacheCodec>>>),
+ RedisSemantic(Arc<ResponseCache<RedisSemanticCache<PythonEmbedder>>>),
}
impl NativeResponseCache {
@@@ -52,17 -49,11 +54,22 @@@
buffer: None,
})
}
+ pub fn disk(directory: &str) -> Result<Self, Error> {
+ let cache = DiskCache::open(directory, ResponseCacheCodec)?;
+ Ok(Self::Disk(Arc::new(ResponseCache::new(Arc::new(cache)))))
+ }
+
+ pub fn redis_semantic(
+ url: &str,
+ embedder: PythonEmbedder,
+ config: RedisSemanticConfig,
+ ) -> Result<Self, Error> {
+ let backend = RedisSemanticCache::new(url, embedder, config)?;
+ Ok(Self::RedisSemantic(Arc::new(ResponseCache::new(Arc::new(
+ backend,
+ )))))
+ }
+
pub async fn azure_blob(account_url: &str, container: &str) -> Result<Self, Error> {
let backend = AzureBlobCache::connect(
account_url,
@@@ -82,7 -73,7 +89,7 @@@
cache.backend().account_url(),
cache.backend().container_name(),
)),
- Self::Memory(_) | Self::Redis { .. } | Self::RedisSemantic(_) => None,
- Self::Memory(_) | Self::Redis { .. } | Self::Disk(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::Disk(_) | Self::RedisSemantic(_) => None,
}
}
}
@@@ -92,7 -83,7 +99,8 @@@ impl NativeResponseCache
match self {
Self::Memory(_) => "memory",
Self::Redis { .. } => "redis",
+ Self::Disk(_) => "disk",
+ Self::RedisSemantic(_) => "redis_semantic",
Self::AzureBlob(_) => "azure-blob",
}
}
@@@ -101,21 -92,21 +109,22 @@@
match self {
Self::Memory(cache) => cache.default_ttl(),
Self::Redis { cache, .. } => cache.default_ttl(),
+ Self::Disk(cache) => cache.default_ttl(),
+ Self::RedisSemantic(cache) => cache.default_ttl(),
Self::AzureBlob(cache) => cache.default_ttl(),
}
}
pub fn namespace(&self) -> Option<&str> {
match self {
- Self::Memory(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
- Self::Memory(_) | Self::Disk(_) | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Disk(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
Self::Redis { cache, .. } => cache.backend().namespace(),
}
}
pub fn topology(&self) -> Option<&RedisTopology> {
match self {
- Self::Memory(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
- Self::Memory(_) | Self::Disk(_) | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Disk(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
Self::Redis { cache, .. } => Some(cache.backend().topology()),
}
}
@@@ -123,52 -114,17 +132,56 @@@
pub fn capacity(&self) -> Option<usize> {
match self {
Self::Memory(cache) => Some(cache.backend().max_size_in_memory()),
- Self::Redis { .. } | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
- Self::Redis { .. } | Self::Disk(_) | Self::AzureBlob(_) => None,
++ Self::Redis { .. } | Self::Disk(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => {
++ None
++ }
}
}
pub fn max_entry_bytes(&self) -> Option<usize> {
match self {
Self::Memory(cache) => cache.backend().max_entry_bytes(),
- Self::Redis { .. } | Self::AzureBlob(_) | Self::RedisSemantic(_) => None,
- Self::Redis { .. } | Self::Disk(_) | Self::AzureBlob(_) => None,
++ Self::Redis { .. } | Self::Disk(_) | Self::AzureBlob(_) | Self::RedisSemantic(_) => {
++ None
++ }
}
}
+ pub fn index_name(&self) -> Option<&str> {
+ match self {
+ Self::RedisSemantic(cache) => Some(cache.backend().index_name()),
- Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) | Self::Disk(_) => None,
+ }
+ }
+
+ pub fn similarity_threshold(&self) -> Option<f32> {
+ match self {
+ Self::RedisSemantic(cache) => Some(cache.backend().similarity_threshold()),
- Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) | Self::Disk(_) => None,
+ }
+ }
+
+ pub fn semantic_embedder(&self) -> Option<&PythonEmbedder> {
+ match self {
+ Self::RedisSemantic(cache) => Some(cache.backend().embedder()),
- Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) | Self::Disk(_) => None,
+ }
+ }
+
+ pub fn embedder_object(&self) -> Option<&Py<PyAny>> {
+ match self {
+ Self::RedisSemantic(cache) => Some(cache.backend().embedder().object()),
- Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) | Self::Disk(_) => None,
+ }
+ }
+
+ pub fn traverse(&self, visit: &PyVisit<'_>) -> Result<(), PyTraverseError> {
+ if let Self::RedisSemantic(cache) = self {
+ cache.backend().embedder().traverse(visit)?;
+ }
+ Ok(())
+ }
+
pub fn with_redis_flush_size(self, flush_size: Option<usize>) -> Self {
match self {
Self::Redis { cache, .. } => Self::Redis {
@@@ -179,16 -135,23 +192,26 @@@
}
}
+ pub fn directory(&self) -> Option<&Path> {
+ match self {
+ Self::Disk(cache) => Some(cache.backend().directory()),
- Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) => None,
++ Self::Memory(_) | Self::Redis { .. } | Self::AzureBlob(_) | Self::RedisSemantic(_) => {
++ None
++ }
+ }
+ }
+
- pub fn lookup(
- &self,
- request: &ResponseCacheRequest,
- now: Duration,
- ) -> Result<Option<Value>, Error> {
+ fn exact_requests(requests: &[CacheRequest]) -> Vec<ResponseCacheRequest<ExactCacheContext>> {
+ requests.iter().map(CacheRequest::exact).collect()
+ }
+
+ pub fn lookup(&self, request: &CacheRequest, now: Duration) -> Result<Option<Value>, Error> {
match self {
- Self::Memory(cache) => cache.lookup(request, now),
- Self::Redis { cache, .. } => cache.lookup(request, now),
- Self::Disk(cache) => cache.lookup(request, now),
- Self::AzureBlob(cache) => cache.lookup(request, now),
+ Self::Memory(cache) => cache.lookup(&request.exact(), now),
+ Self::Redis { cache, .. } => cache.lookup(&request.exact(), now),
- Self::RedisSemantic(cache) => cache.lookup(&request.semantic(), now),
++ Self::Disk(cache) => cache.lookup(&request.exact(), now),
+ Self::AzureBlob(cache) => cache.lookup(&request.exact(), now),
++ Self::RedisSemantic(cache) => cache.lookup(&request.semantic(), now),
}
}
@@@ -199,10 -162,10 +222,11 @@@
now: Duration,
) -> Result<(), Error> {
match self {
- Self::Memory(cache) => cache.store(request, response, now),
- Self::Redis { cache, .. } => cache.store(request, response, now),
- Self::Disk(cache) => cache.store(request, response, now),
- Self::AzureBlob(cache) => cache.store(request, response, now),
+ Self::Memory(cache) => cache.store(&request.exact(), response, now),
+ Self::Redis { cache, .. } => cache.store(&request.exact(), response, now),
- Self::RedisSemantic(cache) => cache.store(&request.semantic(), response, now),
++ Self::Disk(cache) => cache.store(&request.exact(), response, now),
+ Self::AzureBlob(cache) => cache.store(&request.exact(), response, now),
++ Self::RedisSemantic(cache) => cache.store(&request.semantic(), response, now),
}
}
@@@ -212,10 -175,10 +236,11 @@@
now: Duration,
) -> Result<PartialHits, Error> {
match self {
- Self::Memory(cache) => cache.lookup_batch(requests, now),
- Self::Redis { cache, .. } => cache.lookup_batch(requests, now),
- Self::Disk(cache) => cache.lookup_batch(requests, now),
- Self::AzureBlob(cache) => cache.lookup_batch(requests, now),
+ Self::Memory(cache) => cache.lookup_batch(&Self::exact_requests(requests), now),
+ Self::Redis { cache, .. } => cache.lookup_batch(&Self::exact_requests(requests), now),
- Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
++ Self::Disk(cache) => cache.lookup_batch(&Self::exact_requests(requests), now),
+ Self::AzureBlob(cache) => cache.lookup_batch(&Self::exact_requests(requests), now),
++ Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
}
}
@@@ -225,10 -188,10 +250,11 @@@
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::Disk(cache) => cache.async_lookup(request, now).await,
- Self::AzureBlob(cache) => cache.async_lookup(request, now).await,
+ Self::Memory(cache) => cache.async_lookup(&request.exact(), now).await,
+ Self::Redis { cache, .. } => cache.async_lookup(&request.exact(), now).await,
- Self::RedisSemantic(cache) => cache.async_lookup(&request.semantic(), now).await,
++ Self::Disk(cache) => cache.async_lookup(&request.exact(), now).await,
+ Self::AzureBlob(cache) => cache.async_lookup(&request.exact(), now).await,
++ Self::RedisSemantic(cache) => cache.async_lookup(&request.semantic(), now).await,
}
}
@@@ -247,15 -210,9 +273,16 @@@
Self::Redis {
cache,
buffer: Some(buffer),
- } => buffer.async_store(cache, request, response, now).await,
- Self::Disk(cache) => cache.async_store(request, response, now).await,
- Self::AzureBlob(cache) => cache.async_store(request, response, now).await,
+ } => {
+ buffer
+ .async_store(cache, &request.exact(), response, now)
+ .await
+ }
++ Self::Disk(cache) => cache.async_store(&request.exact(), response, now).await,
++ Self::AzureBlob(cache) => cache.async_store(&request.exact(), response, now).await,
+ Self::RedisSemantic(cache) => {
+ cache.async_store(&request.semantic(), response, now).await
+ }
- Self::AzureBlob(cache) => cache.async_store(&request.exact(), response, now).await,
}
}
@@@ -265,22 -222,10 +292,27 @@@
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::Disk(cache) => cache.async_lookup_batch(requests, now).await,
- Self::AzureBlob(cache) => cache.async_lookup_batch(requests, now).await,
+ Self::Memory(cache) => {
+ cache
+ .async_lookup_batch(&Self::exact_requests(requests), now)
+ .await
+ }
+ Self::Redis { cache, .. } => {
+ cache
+ .async_lookup_batch(&Self::exact_requests(requests), now)
+ .await
+ }
- Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
++ Self::Disk(cache) => {
++ cache
++ .async_lookup_batch(&Self::exact_requests(requests), now)
++ .await
++ }
+ Self::AzureBlob(cache) => {
+ cache
+ .async_lookup_batch(&Self::exact_requests(requests), now)
+ .await
+ }
++ Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
}
}
@@@ -290,50 -235,10 +322,61 @@@
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::Disk(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)| (request.exact(), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
+ Self::Redis { cache, .. } => {
+ cache
+ .async_store_batch(
+ entries
+ .into_iter()
+ .map(|(request, value)| (request.exact(), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
- Self::RedisSemantic(cache) => {
++ Self::Disk(cache) => {
+ cache
+ .async_store_batch(
+ entries
+ .into_iter()
- .map(|(request, value)| (request.semantic(), value))
++ .map(|(request, value)| (request.exact(), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
+ Self::AzureBlob(cache) => {
+ cache
+ .async_store_batch(
+ entries
+ .into_iter()
+ .map(|(request, value)| (request.exact(), value))
+ .collect(),
+ now,
+ )
+ .await
+ }
++ Self::RedisSemantic(cache) => {
++ cache
++ .async_store_batch(
++ entries
++ .into_iter()
++ .map(|(request, value)| (request.semantic(), value))
++ .collect(),
++ now,
++ )
++ .await
++ }
}
}
@@@ -346,7 -251,7 +389,8 @@@
}
cache.async_flush().await
}
+ Self::Disk(cache) => cache.async_flush().await,
+ Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
Self::AzureBlob(cache) => cache.async_flush().await,
}
}
@@@ -355,7 -260,7 +399,8 @@@
match self {
Self::Memory(cache) => cache.test_connection().await,
Self::Redis { cache, .. } => cache.test_connection().await,
+ Self::Disk(cache) => cache.test_connection().await,
+ Self::RedisSemantic(_) => Err(Error::UnsupportedOperation),
Self::AzureBlob(cache) => cache.test_connection().await,
}
}
diff --cc litellm/rust_bridge/_native.pyi
index baac21bb4bd,05a6df6d5af..23dc26a6260
--- a/litellm/rust_bridge/_native.pyi
+++ b/litellm/rust_bridge/_native.pyi
@@@ -93,71 -93,6 +93,75 @@@ class ResponsesWebSocketConnection
def recv_text(self) -> Future[str | None]: ...
def close(self) -> Future[None]: ...
+@final
+class _CacheTestHandle:
+ def __new__(cls, _uninstantiable: Never, /) -> Never: ...
+ @staticmethod
+ def memory(
+ *,
+ capacity: int = 200,
+ ttl_seconds: float = 600.0,
+ max_entry_bytes: int = 1048576,
+ ) -> _CacheTestHandle: ...
+ @staticmethod
+ def redis(
+ url: str,
+ *,
+ ttl_seconds: float = 60.0,
+ namespace: str | None = None,
+ startup_nodes: list[tuple[str, int]] | None = None,
+ ) -> _CacheTestHandle: ...
+ @staticmethod
++ def disk(directory: str) -> _CacheTestHandle: ...
++ @staticmethod
+ def azure_blob(account_url: str, container: str) -> _CacheTestHandle: ...
+ @staticmethod
+ def redis_semantic(backend: object) -> _CacheTestHandle: ...
+ @property
- def backend(self) -> Literal["memory", "redis", "azure-blob", "redis_semantic"]: ...
++ def backend(
++ self,
++ ) -> Literal["memory", "redis", "disk", "azure-blob", "redis_semantic"]: ...
+ def _bind_facade(self, facade: object) -> None: ...
+
+@final
+class _CacheTestBinding:
+ def __new__(cls, _uninstantiable: Never, /) -> Never: ...
+ @property
+ def kind(self) -> Literal["disabled", "native", "python_callback"]: ...
+ def lookup(
+ self, request: object, *, callback_kwargs: object = None
+ ) -> object: ...
+ def store(
+ self, request: object, response: object, *, callback_kwargs: object = None
+ ) -> None: ...
+ def lookup_batch(
+ self, requests: object, *, callback_kwargs: object = None
+ ) -> object: ...
+ def async_lookup(
+ self, request: object, *, callback_kwargs: object = None
+ ) -> Future[object]: ...
+ def async_store(
+ self, request: object, response: object, *, callback_kwargs: object = None
+ ) -> Future[object]: ...
+ def async_lookup_batch(
+ self, requests: object, *, callback_kwargs: object = None
+ ) -> Future[object]: ...
+ def async_store_batch(
+ self,
+ requests: object,
+ responses: object,
+ *,
+ callback_result: object = None,
+ callback_kwargs: object = None,
+ ) -> Future[object]: ...
+ def async_flush(self) -> Future[object]: ...
+ def ping(self) -> Future[object]: ...
+
+@final
+class _CacheTestResolver:
+ def __new__(cls, namespace: object) -> _CacheTestResolver: ...
+ def resolve(self) -> _CacheTestBinding: ...
+
@final
class TokenCounter:
def __new__(cls, tokenizer_json: str) -> TokenCounter: ...
diff --cc tests/test_litellm_rust/test_cache.py
index fd1610dff6b,8cddc868073..3f5449a1aa9
--- a/tests/test_litellm_rust/test_cache.py
+++ b/tests/test_litellm_rust/test_cache.py
@@@ -9,13 -7,13 +9,15 @@@ import threadin
import time
import uuid
import weakref
-from collections.abc import Generator
+from collections.abc import Callable, Generator
+from contextlib import ExitStack
+ from pathlib import Path
from types import SimpleNamespace
from typing import Final, Protocol, cast
from urllib.parse import urlparse
+from uuid import uuid4
+ import diskcache
import fakeredis
import pytest
import redis
@@@ -24,18 -22,13 +26,19 @@@ from azure.storage.blob import Containe
import litellm
from litellm.caching.azure_blob_cache import AzureBlobCache
from litellm.caching.caching import Cache, disable_cache, enable_cache, update_cache
+ from litellm.caching.disk_cache import DiskCache
from litellm.caching.in_memory_cache import InMemoryCache
from litellm.caching.redis_cluster_cache import RedisClusterCache
+from litellm.caching.redis_semantic_cache import RedisSemanticCache
from litellm.rust_bridge import _native
from litellm.types.caching import LiteLLMCacheType
+from litellm.types.llms.custom_llm import CustomLLMItem
+from litellm.types.utils import EmbeddingResponse
from tests.test_litellm_rust.support.isolation import rebound
+_CacheTestHandle: Final = _native._CacheTestHandle # pyright: ignore[reportPrivateUsage] # test-only handle has no public module name
+_CacheTestResolver: Final = _native._CacheTestResolver # pyright: ignore[reportPrivateUsage] # test-only resolver has no public module name
+
pytestmark: Final = pytest.mark.requires_rust_extension