@betterdb/valkey-search-kit (Python)
betterdb-valkey-search-kit — shared low-level helpers for working with Valkey
Search (FT.*) from Python. This is the Python equivalent of the TypeScript
@betterdb/valkey-search-kit package, and the shared foundation the
betterdb-retrieval and betterdb-agent-memory packages build on.
It has no runtime dependencies and exposes only pure functions, so it stays trivial to vendor and test.
See it live in BetterDB Monitor
BetterDB Monitor gives you live dashboards for the AI workloads running on your Valkey:
- AI Cache & Memory - hit rate, cost saved, evictions, and index size across all your caches and memory stores, with history.
- AI Traces - OpenTelemetry waterfalls for each request, correlated with live Valkey state to explain every cache hit and miss.
Run it self-hosted (docker run -p 3001:3001 betterdb/monitor), or use BetterDB Cloud - which can also provision a managed, TLS-enabled Valkey instance with the Search module in one click - exactly what this library needs.
Install
pip install betterdb-valkey-search-kit
API
Vector encoding
from betterdb_valkey_search_kit import encode_float32, decode_float32
blob = encode_float32([0.1, 0.2, 0.3]) # little-endian Float32 bytes
vec = decode_float32(blob) # back to list[float]
Use encode_float32 to store embeddings as binary HSET field values and as
the PARAMS vector for a KNN FT.SEARCH.
TAG escaping
from betterdb_valkey_search_kit import escape_tag
f"@model:{{{escape_tag('gpt-4o')}}}" # -> "@model:{gpt\\-4o}"
Escapes every character with special meaning in the TAG filter syntax, including spaces (unescaped spaces are treated as OR term separators).
FT.SEARCH reply parsing
from betterdb_valkey_search_kit import parse_ft_search_response
raw = await client.execute_command("FT.SEARCH", index, query, ...)
hits = parse_ft_search_response(raw)
# [{"key": "cache:entry:abc", "fields": {"prompt": "...", "__score": "0.05"}}]
Handles valkey-py's mixed bytes/str replies, RETURN 0 mode (keys with no
field list), and odd-length field lists. Binary field values that are not valid
UTF-8 (e.g. raw embedding bytes) are skipped. Never raises — returns [] on
any malformed input.
FT.INFO parsing (version-skew tolerant)
from betterdb_valkey_search_kit import (
parse_dimension_from_info,
parse_ft_info_stats,
)
info = await client.execute_command("FT.INFO", index)
dims = parse_dimension_from_info(info) # 1536, or 0 if no vector field
stats = parse_ft_info_stats(info) # FtIndexStats(num_docs=..., indexing_state=...)
parse_dimension_from_info understands both the flat DIM attribute pair and
the nested index/dimensions shape introduced in Valkey Search 1.2.
Error classification
from betterdb_valkey_search_kit import is_index_not_found_error
try:
await client.execute_command("FT.INFO", index)
except Exception as err:
if is_index_not_found_error(err):
... # index does not exist yet
else:
raise
Matches the "index does not exist" message variants emitted across Valkey Search / RediSearch versions, case-insensitively.
Development
uv run --extra dev pytest tests -q
Metadata
Release files for betterdb-valkey-search-kit 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| betterdb_valkey_search_kit-0.1.1.tar.gz | 8.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| betterdb_valkey_search_kit-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.7 kB
Release files / betterdb_valkey_search_kit-0.1.1.tar.gz
| Download URL | betterdb_valkey_search_kit-0.1.1.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dc5cf7793f0d1cd3762f2a5a53a57214d71b04a07a41c982f081afac4ad6cf1
|
|
BLAKE2b-256 checksum How to use checksums |
13a60c2a1a25b44f84ca4f7bd1a1ce499f19516b01f3de5a9b7c4e002223ffc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2026.
Transparency logRelease files / betterdb_valkey_search_kit-0.1.1-py3-none-any.whl
| Download URL | betterdb_valkey_search_kit-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6513c9c24fc42b30f18cd344e2578d71c6cd7bd4e2132a0d66ba8a3cce24aa6
|
|
BLAKE2b-256 checksum How to use checksums |
90320a5f190d5f02d6ea6b0411aab22c5f2f9295a4d2808f0c1b218b7a79b6e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2026.
Transparency logSecurity for betterdb-valkey-search-kit 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for betterdb_valkey_search_kit-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.