Follow these steps to set up, build, and run the Valkey server with the valkey-search module. This guide walks you through creating indexes, inserting data, and issuing queries across all supported field types — vector, tag, numeric, and full-text.
- Follow the instructions to build Valkey from source. Make sure to use Valkey version 9.0.1 or later.
- Follow the instructions to build the valkey-search module from source.
Alternatively, you can get started quickly using the pre-built Docker bundle, which includes both Valkey and valkey-search ready to run.
Once valkey-search is built, run the Valkey server with the valkey-search module loaded:
valkey-server --loadmodule /path/to/libsearch.soTo enable JSON support, you'll need to also load the JSON module. See the valkey-json build instructions for how to build it.
valkey-server --loadmodule /path/to/libsearch.so --loadmodule /path/to/libjson.sovalkey-cliFT.CREATE myIndex SCHEMA embedding VECTOR HNSW 6 TYPE FLOAT32 DIM 3 DISTANCE_METRIC COSINEembeddingis the field name for storing vectors.VECTOR HNSWuses the Hierarchical Navigable Small World algorithm for approximate nearest neighbor search. The other option isVECTOR FLATfor exact brute-force search.DIM 3sets the vector dimensionality to 3.DISTANCE_METRIC COSINEsets the distance metric to cosine similarity. Other options areL2andIP.
Vectors must be encoded as 32-bit IEEE 754 floats in little-endian byte order. Each vector must have exactly DIM elements.
# [0.0, 0.0, 1.0]
HSET my_hash_key_1 embedding "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?"
# [0.000145, 0.0, 1.0]
HSET my_hash_key_2 embedding "\x00\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x80?"Perform a K-Nearest Neighbors (KNN) search, which returns the 5 vectors in the index most similar to the supplied query vector [0.8, 0.0, 0.0]:
# query vector: [0.8, 0.0, 0.0]
FT.SEARCH myIndex "*=>[KNN 5 @embedding $query_vector]" PARAMS 2 query_vector "\xcd\xccL?\x00\x00\x00\x00\x00\x00\x00\x00"The * before => means no pre-filtering — all vectors in the index are searched. For a hybrid query, replace * with a filter expression to narrow candidates before the KNN step:
# query vector: [0.8, 0.0, 0.0] — only search within "electronics" category
FT.SEARCH myIndex "@category:{electronics}=>[KNN 5 @embedding $query_vector]" PARAMS 2 query_vector "\xcd\xccL?\x00\x00\x00\x00\x00\x00\x00\x00"Tag fields store categorical values like status labels or product categories and support exact-match and prefix-match queries. Numeric fields store numbers and support range queries with inclusive or exclusive bounds.
FT.CREATE products ON HASH PREFIX 1 product: SCHEMA category TAG price NUMERIC rating NUMERICcategoryis a TAG field — supports exact-match and prefix-match filtering.priceandratingare NUMERIC fields — support range queries.
HSET product:1 category "electronics" name "Laptop" price 999.99 rating 4.5
HSET product:2 category "electronics" name "Tablet" price 499.00 rating 4.0
HSET product:3 category "electronics" name "Phone" price 299.00 rating 3.8
HSET product:4 category "books" name "Book" price 19.99 rating 4.8Return all products in the "electronics" category:
FT.SEARCH products "@category:{electronics}"Tags support the | operator for matching multiple values:
FT.SEARCH products "@category:{electronics | books}"Return products priced between 100 and 1000 with a rating of at least 4.0:
FT.SEARCH products "@price:[100 1000] @rating:[4.0 +inf]"Parentheses make a bound exclusive. For example, to find products with a price strictly less than 500:
FT.SEARCH products "@price:[-inf (500]"Multiple filters separated by spaces are AND'ed together:
FT.SEARCH products "@category:{books} @price:[10 30] @rating:[4.7 +inf]"Use | between predicates for OR:
FT.SEARCH products "@category:{books} | @price:[500 +inf]"FT.CREATE articles ON HASH PREFIX 1 article: SCHEMA title TEXT body TEXTHSET article:1 title "Introduction to Valkey" body "Valkey is a high performance key value store with module support"
HSET article:2 title "Search Module Overview" body "The search module provides vector and full text search capabilities"
HSET article:3 title "Getting Started with Vectors" body "Vector search enables similarity matching across high dimensional data"Find articles containing the word "valkey" in any text field:
FT.SEARCH articles "valkey"Search within a specific field:
FT.SEARCH articles "@title:valkey"Match any word that starts with "search":
FT.SEARCH articles "search*"Match the exact sequence of words:
FT.SEARCH articles "@body:\"full text search\""Match words within an edit distance of 1 from "valkee" (catches typos):
FT.SEARCH articles "%valkee%"Text matchers can be combined with tag and numeric filters in the same query. Separate predicates with a space for AND, or | for OR:
FT.CREATE docs ON HASH PREFIX 1 doc: SCHEMA content TEXT category TAG year NUMERIC
HSET doc:1 content "great introduction to databases" category "tech" year 2024
HSET doc:2 content "great recipes for summer" category "cooking" year 2023
FT.SEARCH docs "@category:{tech} database*"OR example — match documents in "tech" category or containing "recipes":
FT.SEARCH docs "@category:{tech} | recipes"FT.AGGREGATE extends FT.SEARCH with server-side data processing. It supports stages like GROUPBY, SORTBY, APPLY, FILTER, and LIMIT that transform the working set of records in a pipeline.
Using the products index from earlier:
FT.AGGREGATE products "*" LOAD 2 @category @price GROUPBY 1 @category REDUCE AVG 1 @price AS avg_price REDUCE COUNT 0 AS count SORTBY 2 @avg_price DESCThis groups all products by category, computes the average price and count per category, and sorts by average price descending.
For a full description of aggregate stages and expression syntax, see the FT.AGGREGATE documentation.
FT._LISTFT.INFO productsFT.DROPINDEX productsINFO SEARCH- Command Reference — detailed syntax and options for all commands.
- Query Language — full filter expression syntax, logical operators, and text search operators.
- Data Formats — ingestion formats for tag, numeric, vector, and text fields.
- Search Overview — architecture, cluster mode, replication, and consistency model.
- Configuration — tunable parameters for the search module.
- INFO SEARCH Metrics — module-wide memory, latency, query, and thread pool metrics.