Skip to main content

Semantic cache for AI workloads backed by Valkey vector search. Embeddings-based similarity matching with OpenTelemetry and Prometheus instrumentation.

Project description

betterdb-semantic-cache

Semantic cache for AI workloads backed by Valkey vector search. Embeddings-based similarity matching with OpenTelemetry and Prometheus instrumentation.

Installation

pip install betterdb-semantic-cache
# With OpenAI embeddings:
pip install betterdb-semantic-cache[openai]
# All extras:
pip install betterdb-semantic-cache[all]

Quick start

import asyncio
import valkey.asyncio as valkey
from betterdb_semantic_cache import SemanticCache, SemanticCacheOptions
from betterdb_semantic_cache.embed.openai import create_openai_embed

async def main():
    client = valkey.Valkey(host="localhost", port=6399)
    cache = SemanticCache(SemanticCacheOptions(
        client=client,
        embed_fn=create_openai_embed(),
        default_threshold=0.12,
    ))
    await cache.initialize()

    result = await cache.check("What is the capital of France?")
    if not result.hit:
        await cache.store("What is the capital of France?", "Paris")

asyncio.run(main())

Telemetry

The published wheel includes anonymous product analytics powered by PostHog. When a baked API key is present in the package (injected at publish time), aggregate usage statistics (hit rate, cost saved) are collected on a per-instance basis — no prompt text, responses, or personally-identifiable information is ever sent.

To opt out, set the environment variable before starting your process:

export BETTERDB_TELEMETRY=false   # also accepts: 0, no, off

You can also disable it programmatically:

from betterdb_semantic_cache.types import AnalyticsOptions
cache = SemanticCache(SemanticCacheOptions(
    ...,
    analytics=AnalyticsOptions(disabled=True),
))

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

betterdb_semantic_cache-0.1.3.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

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

betterdb_semantic_cache-0.1.3-py3-none-any.whl (64.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: betterdb_semantic_cache-0.1.3.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for betterdb_semantic_cache-0.1.3.tar.gz
Algorithm Hash digest
SHA256 69017eda0e1c27aef82ced4d5e76c34ea2fd8672b1f61a73fbc2ecc1bff33dbb
MD5 39a371d6dde82fc12dfe172828c88607
BLAKE2b-256 c76a22981ff1f1c7f05080df80f875b752cff4ba9251bc3b13a54a21f12e3d47

See more details on using hashes here.

Provenance

The following attestation bundles were made for betterdb_semantic_cache-0.1.3.tar.gz:

Publisher: semantic-cache-py-release.yml on BetterDB-inc/monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for betterdb_semantic_cache-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf739cd3444541977f7c32a9d79bf799e1c72986b68d78fa1c090728ccaf31bd
MD5 40b923db61839065b070c48d0c56b1fd
BLAKE2b-256 175715754870e3a4554082d840d9fd29d809133a9c832b4f4a6178c78722e34b

See more details on using hashes here.

Provenance

The following attestation bundles were made for betterdb_semantic_cache-0.1.3-py3-none-any.whl:

Publisher: semantic-cache-py-release.yml on BetterDB-inc/monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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