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.2.tar.gz (75.0 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.2-py3-none-any.whl (64.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: betterdb_semantic_cache-0.1.2.tar.gz
  • Upload date:
  • Size: 75.0 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.2.tar.gz
Algorithm Hash digest
SHA256 45379eb2b084126d55d066cd689295ab6627e8f1b2af62622df23e0b2026050b
MD5 54abc7c802822076b03dd3cc9d2bdfde
BLAKE2b-256 0b629dff499b6052b237cf22f171d7e77507862a8d123ae3c74b33b549731f92

See more details on using hashes here.

Provenance

The following attestation bundles were made for betterdb_semantic_cache-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for betterdb_semantic_cache-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77fbb34d07a7abb1f2346dd53085a5587d1c102ed10e6c6d809fb4a09a8cab98
MD5 f77b9a8738166e14a606257f72f32f76
BLAKE2b-256 a255a2456760a926ce437fdb6d5d90f5eb3a2cf89247986f6afb8046af61ea70

See more details on using hashes here.

Provenance

The following attestation bundles were made for betterdb_semantic_cache-0.1.2-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