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
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45379eb2b084126d55d066cd689295ab6627e8f1b2af62622df23e0b2026050b
|
|
| MD5 |
54abc7c802822076b03dd3cc9d2bdfde
|
|
| BLAKE2b-256 |
0b629dff499b6052b237cf22f171d7e77507862a8d123ae3c74b33b549731f92
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
betterdb_semantic_cache-0.1.2.tar.gz -
Subject digest:
45379eb2b084126d55d066cd689295ab6627e8f1b2af62622df23e0b2026050b - Sigstore transparency entry: 1373691105
- Sigstore integration time:
-
Permalink:
BetterDB-inc/monitor@4411483fa7c615b4a0f97e1042657ae1a75611be -
Branch / Tag:
refs/tags/semantic-cache-py-v0.1.2 - Owner: https://github.com/BetterDB-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
semantic-cache-py-release.yml@4411483fa7c615b4a0f97e1042657ae1a75611be -
Trigger Event:
push
-
Statement type:
File details
Details for the file betterdb_semantic_cache-0.1.2-py3-none-any.whl.
File metadata
- Download URL: betterdb_semantic_cache-0.1.2-py3-none-any.whl
- Upload date:
- Size: 64.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77fbb34d07a7abb1f2346dd53085a5587d1c102ed10e6c6d809fb4a09a8cab98
|
|
| MD5 |
f77b9a8738166e14a606257f72f32f76
|
|
| BLAKE2b-256 |
a255a2456760a926ce437fdb6d5d90f5eb3a2cf89247986f6afb8046af61ea70
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
betterdb_semantic_cache-0.1.2-py3-none-any.whl -
Subject digest:
77fbb34d07a7abb1f2346dd53085a5587d1c102ed10e6c6d809fb4a09a8cab98 - Sigstore transparency entry: 1373691204
- Sigstore integration time:
-
Permalink:
BetterDB-inc/monitor@4411483fa7c615b4a0f97e1042657ae1a75611be -
Branch / Tag:
refs/tags/semantic-cache-py-v0.1.2 - Owner: https://github.com/BetterDB-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
semantic-cache-py-release.yml@4411483fa7c615b4a0f97e1042657ae1a75611be -
Trigger Event:
push
-
Statement type: