Skip to main content

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 pgvector enabled
  • 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 text
  • cache_type: exact, semantic, partial, or miss
  • tokens_saved: estimated tokens avoided via cache reuse
  • cost_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.3.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

composecache-0.1.3-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file composecache-0.1.3.tar.gz.

File metadata

  • Download URL: composecache-0.1.3.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for composecache-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c18b8972d481946bdac628ab87f217f5f6f1edae7b55a7b62d5f8082eda8f1da
MD5 919fdd3428fb232236361fd384e79bb6
BLAKE2b-256 0b97239739e5c3b3c342e07c1497eb263d49eb3838785849a2fbdc75de9cf27f

See more details on using hashes here.

File details

Details for the file composecache-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: composecache-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for composecache-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b43a54edc80f079cf976d0c06ce61caff957f235245ac1184a0db893833fbed8
MD5 82b3c26573bd8ffdd9722bccadc974f9
BLAKE2b-256 4154c8b8f5d1d72f0fda74b9b6ebc13acb6fee0b27a4b5c4c650ffbea51b95c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page