Redis query syntax (FT.SEARCH)

The Redis wire implements a subset of the Redis query engine: FT.CREATE, FT.SEARCH, FT.INFO, FT.DROPINDEX (and FT.DROP) and FT._LIST. Any other FT.* command returns "ERR unknown command" (source: src/protocol/redis/commands/search.rs, ft_command). The query string is parsed into a small tree and evaluated by brute force over the documents of the index, inside the wire. The index field types, vector options and cross-wire mirroring are summarised in Redis implementation reference, Query engine.

Translation path

flowchart LR W["Write to a key under an index prefix"] --> OW["ft_on_write: reindex document"] OW --> IDX["FtIndex documents in memory"] S["FT.SEARCH idx query options"] --> OP["ft_parse_opts"] S --> PQ["parse_query to Node and optional Knn"] PQ --> EV["eval over every document"] IDX --> EV EV --> KNN["KNN or VECTOR_RANGE distances"] KNN --> R["ft_reply: SORTBY, LIMIT, RETURN, WITHSCORES, NOCONTENT"] DEF["FT.CREATE"] -->|"definition"| KV["KV key __redisft__:"]

(source: src/protocol/redis/commands/search.rs, ft_on_write, ft_parse_opts, parse_query, eval, ft_search, ft_reply, ft_persist_def, FT_DEF_PREFIX)

Index definitions are persisted under __redisft__: and reloaded at start-up by load_indexes; the indexed documents are the Redis keys themselves (HASH or JSON) and are re-read into the index (source: src/protocol/redis/commands/search.rs, FT_DEF_PREFIX, load_indexes).

Query grammar

Form Node
* All documents
a b (juxtaposition) AND
a \| b OR
-a NOT
( ... ) Grouping
@f:{a \| b} TAG match, exact or prefix (a*)
@f:[lo hi], @f:[(lo (hi] NUMERIC range; ( makes a bound exclusive
term, prefix*, "phrase", optionally @f: TEXT match
@f:[VECTOR_RANGE r $blob]=>{$YIELD_DISTANCE_AS: d} Vector range
<prefilter>=>[KNN k @f $blob AS alias] K nearest neighbours, with optional EF_RUNTIME and EPSILON

(source: src/protocol/redis/commands/search.rs, Node, Knn, parse_query)

The KNN prefilter must be a single term: *, one group or one filter. a b=>[KNN ...] is a syntax error, as in Redis (source: src/protocol/redis/commands/search.rs, parse_query). EF_RUNTIME is refused on a FLAT field and EPSILON on a non-HNSW field with SEARCH_OPTION_INVALID (source: src/protocol/redis/commands/search.rs, parse_query). Syntax errors are SEARCH_SYNTAX Syntax error at offset N near X; an unknown field is SEARCH_SYNTAX Unknown field at offset N near X (source: src/protocol/redis/commands/search.rs, syntax).

Distances: L2 is squared Euclidean, IP is 1 - dot, COSINE is 1 - dot of normalised vectors; scores are printed with 12 significant digits (source: src/protocol/redis/commands/search.rs, distance, prepare, fmt_score). Tested by l2_matches_redis_digits.

FT.SEARCH options

Option Handling
NOCONTENT, WITHSCORES, LIMIT offset num, SORTBY field [ASC\|DESC] [WITHCOUNT], RETURN n field [AS name] ..., PARAMS n name value ... Applied
VERBATIM, NOSTOPWORDS, WITHPAYLOADS, WITHSORTKEYS, INORDER, EXPLAINSCORE Accepted and ignored
DIALECT, TIMEOUT, SLOP, LANGUAGE, EXPANDER, SCORER, PAYLOAD (with their argument) Accepted and ignored
INKEYS, INFIELDS (with their list) Accepted and ignored
FILTER field min max Skipped: the numeric filter is not applied
GEOFILTER field lon lat radius unit Skipped: the geo filter is not applied
SUMMARIZE, HIGHLIGHT (with their sub-options) Accepted and ignored
anything else SEARCH_PARSE_ARGS Unknown argument

(source: src/protocol/redis/commands/search.rs, ft_parse_opts)

Because FILTER and GEOFILTER are consumed without effect, a query that relies on them returns documents outside the requested range rather than an error (source: src/protocol/redis/commands/search.rs, ft_parse_opts). INKEYS and INFIELDS are also not applied, so they do not narrow the result. GEO fields can be declared in FT.CREATE, but the query grammar has no geo predicate (source: src/protocol/redis/commands/search.rs, parse_create, Node).

Not supported

FT.AGGREGATE, FT.EXPLAIN, FT.PROFILE, FT.ALTER, aliases, cursors, dictionaries, suggestions, synonyms, FT.SPELLCHECK, FT.TAGVALS and FT.HYBRID are not dispatched; the ACL table lists some of them, but ft_command answers "ERR unknown command" (source: src/protocol/redis/commands/search.rs, ft_command; src/protocol/redis/commands/acl_table.rs). The Node tree has no fuzzy, optional-term or geo node, so Redis query forms for those (%term%, ~term, @f:[lon lat r unit]) are not evaluated as Redis does (source: src/protocol/redis/commands/search.rs, Node, parse_query). Not verified: no test shows whether such forms are rejected or read as plain terms.

Tests

Unit tests in src/protocol/redis/commands/search.rs: l2_matches_redis_digits, parses_hybrid_queries, mirrors_into_vector_service. Wider coverage comes from the Redis 8 FT/JSON vector differential reported on the wire page (source: Redis implementation reference).