Zero-cost, low-latency tiered semantic caching SDK for LLMs running local embeddings.
Project description
SemCache (Python SDK)
Zero-cost, low-latency tiered semantic caching SDK for LLMs running local embeddings.
Installation
pip install semcache
Quick Start
from semcache import SemCache, FileStore
# Initialize cache with local file storage
cache = SemCache(
store=FileStore(".semcache/db.json"),
fuzzy_threshold=0.95,
semantic_threshold=0.85
)
# Set an entry (simulate LLM response time of 1500ms)
cache.set(
query="What is the capital of France?",
response="The capital of France is Paris.",
latency_ms=1500,
token_usage={"prompt_tokens": 7, "completion_tokens": 7}
)
# Query semantic matching (instant hit in ~20ms, $0 API cost)
result = cache.get("tell me the capital city of France")
if result:
entry, tier, similarity = result
print(f"Hit Tier: {tier} (Similarity: {similarity:.4f})")
print(f"Response: {entry.response}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
semc-1.0.0.tar.gz
(5.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
semc-1.0.0-py3-none-any.whl
(5.8 kB
view details)
File details
Details for the file semc-1.0.0.tar.gz.
File metadata
- Download URL: semc-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
501c2dcb7d97eba497c2d79bde88c815fd9f56db185285270095977c7dfd7e06
|
|
| MD5 |
0105a729f550153da0f0a7370ae420c7
|
|
| BLAKE2b-256 |
4322a81e301c38f2f85f00f71b6dece4464d71c9580ba3cbb6452f5010021af6
|
File details
Details for the file semc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: semc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
422e79c4b6d757ca2fd83ada319f7b2b269f890dda8e0020485d4fedca419301
|
|
| MD5 |
ae6e525a588f448f4c4832ef07cd7781
|
|
| BLAKE2b-256 |
b7892eaa1745567501be00a57335f7ecdf32824545ea8db477710ce3c064dd41
|