This document is for AI agents that want to use sql-redis to query Redis.
For agents that want to modify the library itself, see
docs/for-ais-only/.
A SQL-to-Redis translator. It accepts a SQL SELECT string, looks up the
target index's schema in Redis, and emits a FT.SEARCH or FT.AGGREGATE
command. The library does not invent its own query language: SQL goes in,
Redis search results come out as a QueryResult(rows, count).
- The agent has a SQL string (from a planner, an LLM, an ORM, a user) and wants to run it against an existing RediSearch / RedisVL index.
- The agent needs vector search, full-text search, GEO filters, or date filtering and wants a single uniform interface instead of building Redis command lists by hand.
- The target index already exists. sql-redis does not run
FT.CREATE. If there is no index, the query fails. Create the index first.
- Plain key-value
GET/SETwork, list/set/sorted-set commands, streams, pub/sub. Useredis-pydirectly for those; sql-redis is a search-only translator. - Writes. There is no
INSERT,UPDATE, orDELETE. Write throughredis-py. - Index creation. Use
FT.CREATEdirectly viaredis-pyfirst. - Cross-index joins, subqueries,
HAVING,DISTINCT. Not implemented.
from redis import Redis
from sql_redis import create_executor
client = Redis()
executor = create_executor(client) # lazy schema loading; no I/O yet
result = executor.execute(
"SELECT title, price FROM products WHERE category = :cat AND price < :max LIMIT 10",
params={"cat": "electronics", "max": 500},
)
for row in result.rows: # row keys are bytes by default
print(row[b"title"], row[b"price"])Pass decode_responses=True to the Redis client if the agent prefers string
keys.
| Task | Symbol |
|---|---|
| Run a SQL query | Executor.execute / AsyncExecutor.execute |
| Build an executor | create_executor / create_async_executor |
| Read or refresh schema | SchemaRegistry / AsyncSchemaRegistry |
| Translate without executing | Translator.translate returns a TranslatedQuery |
Full reference, generated from docstrings, is at docs/api/.
- Field-key types. Result rows come back with
byteskeys when the underlyingRedisclient uses defaultdecode_responses=False. UseRedis(decode_responses=True)if you want string keys end-to-end. - Parameter substitution is token-based.
:idwill not match inside:product_id. String values are SQL-escaped automatically (O'Brienbecomes'O''Brien'). Passbytesfor vector parameters; they are substituted as raw bytes after translation. =on a TEXT field is exact-phrase, not tokenized. Usefulltext()for tokenized AND search. Seedocs/user_guide/how_to_guides/text-search.md.- Stopwords are stripped automatically before queries reach Redis. A
UserWarningis emitted when this happens. Index withSTOPWORDS 0to keep them. IS NULLrequires Redis 7.4+ andINDEXMISSINGdeclared on the field.- Lazy schema loading is the default. The first query that touches an
index issues one
FT.INFO. Passschema_cache_strategy="load_all"tocreate_executorif you want to fail fast on missing indexes at startup. - No JOIN, subquery, HAVING, or DISTINCT. The translator raises
ValueError; do not retry with rephrasing. - GEO uses
POINT(lon, lat)order. Longitude first, matching Redis.
| Exception | Meaning | Recovery |
|---|---|---|
ValueError from Translator.translate |
The SQL referenced an unknown index, unknown field, or unsupported clause. | Inspect the message; the index/field name is included. Do not retry the same SQL. |
redis.ResponseError from Executor.execute |
Redis rejected the generated command. The most common cases are wrong field type or INDEXMISSING not declared. |
Check the index schema. The library wraps ismissing() failures with a hint about Redis 7.4 + INDEXMISSING. |
UserWarning (not raised) |
Stopwords stripped, or IS NULL used without INDEXMISSING declared. |
Informational; does not affect the result. |
| Artifact | Purpose |
|---|---|
llms.txt |
Auto-generated flat index of every doc page with one-line summaries. Built by mkdocs-llmstxt at deploy time. Good for in-context injection. |
docs/api/ |
mkdocstrings reference for every public symbol, generated from Google-style docstrings. Source of truth for method signatures. |
docs/user_guide/how_to_guides/ |
Task-oriented recipes (vector search, GEO, dates, async, parameters). |
docs/concepts/ |
Why-style explanation: architecture, parameter substitution, schema-aware translation. |
docs/for-ais-only/ |
Internal repo map for agents modifying the library. |
sql-redis sits in the Redis AI Hub under the
Experimental tier as "SQL for Redis". Published docs:
redis-developer.github.io/sql-redis/
(GitHub Pages, deployed by .github/workflows/docs.yml on every push to
main). The hub's docs standards (Diataxis layout, docstring-driven API
reference, AI-agent affordances) are documented at
HUB_DOCS_STANDARDS.md
in the hub repo.