Shared Valkey Search (FT.*) helpers: float32 vector encoding, FT.SEARCH reply parsing, version-skew FT.INFO parsing, TAG escaping, and error classification.
Project description
@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.
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
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_valkey_search_kit-0.1.0.tar.gz.
File metadata
- Download URL: betterdb_valkey_search_kit-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
549b0f5dbb7790b93a53cff5ed085e6abfb265da47a60e9fe6ab34063cac799e
|
|
| MD5 |
3a0d34dd1f5417b35724008387df9df9
|
|
| BLAKE2b-256 |
ea6e51e0fea389566c21a2c11ada5e8dd48e5a39660ac8981b80922cbb094d99
|
Provenance
The following attestation bundles were made for betterdb_valkey_search_kit-0.1.0.tar.gz:
Publisher:
valkey-search-kit-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_valkey_search_kit-0.1.0.tar.gz -
Subject digest:
549b0f5dbb7790b93a53cff5ed085e6abfb265da47a60e9fe6ab34063cac799e - Sigstore transparency entry: 1956870073
- Sigstore integration time:
-
Permalink:
BetterDB-inc/monitor@4db6ad58fee39a2d569675732f37a385c9897d1d -
Branch / Tag:
refs/tags/valkey-search-kit-py-v0.1.0 - Owner: https://github.com/BetterDB-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
valkey-search-kit-py-release.yml@4db6ad58fee39a2d569675732f37a385c9897d1d -
Trigger Event:
push
-
Statement type:
File details
Details for the file betterdb_valkey_search_kit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: betterdb_valkey_search_kit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 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 |
37e883972117edd6ec2f032110e7580dd8efcf5bca38270beb8ba4e8bb932f42
|
|
| MD5 |
422dd4fdfd3e884158841c94b8184ef6
|
|
| BLAKE2b-256 |
5ee0c9d095b721cca1acdf358d5216690b5d5b5fd28b31581e52aafd22f27568
|
Provenance
The following attestation bundles were made for betterdb_valkey_search_kit-0.1.0-py3-none-any.whl:
Publisher:
valkey-search-kit-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_valkey_search_kit-0.1.0-py3-none-any.whl -
Subject digest:
37e883972117edd6ec2f032110e7580dd8efcf5bca38270beb8ba4e8bb932f42 - Sigstore transparency entry: 1956870274
- Sigstore integration time:
-
Permalink:
BetterDB-inc/monitor@4db6ad58fee39a2d569675732f37a385c9897d1d -
Branch / Tag:
refs/tags/valkey-search-kit-py-v0.1.0 - Owner: https://github.com/BetterDB-inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
valkey-search-kit-py-release.yml@4db6ad58fee39a2d569675732f37a385c9897d1d -
Trigger Event:
push
-
Statement type: