Compositional semantic caching for LLM APIs and RAG pipelines
Project description
ComposeCache Python Package
Python package for compositional semantic caching over LLM requests.
Published package name on PyPI: composecache.
Quick Start
1. Prerequisites
- Python 3.10+
- PostgreSQL with
pgvectorenabled - OpenAI API key
2. Install
python -m venv .venv
source .venv/bin/activate
pip install composecache
3. Configure Environment
export DATABASE_URL="postgresql://dev:dev@localhost:5432/composecache"
export OPENAI_API_KEY="sk-..."
ComposeCache automatically connects and runs its schema migration on first use.
4. Run
python - <<'PY'
from composecache import ComposeCache
cache = ComposeCache(
database_url="postgresql://dev:dev@localhost:5432/composecache", # or os.environ["DATABASE_URL"]
openai_api_key="YOUR_OPENAI_KEY", # or os.environ["OPENAI_API_KEY"]
)
request = {
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Compare GDP of France and Germany"}],
}
first = cache.complete(request)
second = cache.complete(request)
print("First call cache type:", first["cache_type"])
print("Second call cache type:", second["cache_type"])
print("Answer:", second["content"])
PY
5. Useful Response Fields
content: model answer textcache_type:exact,semantic,partial, ormisstokens_saved: estimated tokens avoided via cache reusecost_saved: estimated cost savings
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
composecache-0.1.4.tar.gz
(13.7 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
File details
Details for the file composecache-0.1.4.tar.gz.
File metadata
- Download URL: composecache-0.1.4.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05efe2d6405301b7f43fbe3a85e8d1ce68440d515eb2ed4357f6ee9ddf2c61d2
|
|
| MD5 |
1c2eac76ad82dc55ee499f89eeb9a949
|
|
| BLAKE2b-256 |
d60d7bb22861fdacacc8025f143ccb3f551500b9a1fd6ccf0af852a93b6c4bba
|
File details
Details for the file composecache-0.1.4-py3-none-any.whl.
File metadata
- Download URL: composecache-0.1.4-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce0f882f614fdcfd20fad22b3d66effada2ce122d7e9eaf2de779a5a98b62828
|
|
| MD5 |
dbbc1fea71b1fb2d4089213d49cd6494
|
|
| BLAKE2b-256 |
9f96cf93cbba5758c4f04ae2a1a9e460f63e222bfcb8e88ce452a78984dfe7d4
|