VSIM.CREATEINDEX
VSIM.CREATEINDEX index dims [METRIC COSINE | L2 | IP] [M m] [EF_CONSTRUCTION n] [EF_SEARCH n]
- Group
- Vector search
- Complexity
- O(1)
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- write, slow
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
VSIM.CREATEINDEX creates an empty vector index called index for vectors
of dims dimensions. You then store vectors under key names with
VSIM.SET and find the closest ones to a query vector
with VSIM.SEARCH. Searches are approximate
(HNSW-indexed), which keeps them fast on large indexes.
Indexes and their vectors live beside the keyspace: KEYS, EXISTS and DEL do not see them, and an index name does not clash with a key of the same name. They are kept in snapshots. In cluster mode, an index lives on the node that owns the hash slot of its name.
Options
Section titled “Options”| Option | Effect |
|---|---|
METRIC COSINE |
Compare vectors by angle (the default). Good for text embeddings. |
METRIC L2 |
Compare vectors by squared Euclidean distance. |
METRIC IP |
Compare vectors by inner product (higher product means closer). |
M m |
Index connectivity, 2 to 256 (a general-purpose default applies). Higher values improve search accuracy and use more memory. |
EF_CONSTRUCTION n |
Build effort, at least 1 (a general-purpose default applies). Higher values build a more accurate index, more slowly. |
EF_SEARCH n |
Default search effort, at least 1 (a general-purpose default applies). Higher values make searches more accurate and slower. Can be overridden per search with EF. |
Metric names are case-insensitive. dims must be 1 to 65536.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Created | Simple string OK |
Simple string OK |
Error replies:
ERR index 'name' already existsERR invalid dimensions (must be 1-65536)ERR invalid metric (use cosine, l2, or ip)ERR invalid M parameter (must be 2-256)ERR invalid EF_CONSTRUCTION (must be >= 1)andERR invalid EF_SEARCH (must be >= 1)ERR unknown option 'name'
An option name given last without a value is ignored.
Examples
Section titled “Examples”127.0.0.1:6379> VSIM.CREATEINDEX docs 384OK127.0.0.1:6379> VSIM.CREATEINDEX points 3 METRIC L2 M 32 EF_SEARCH 100OK127.0.0.1:6379> VSIM.CREATEINDEX docs 384(error) ERR index 'docs' already exists127.0.0.1:6379> VSIM.INFO1) "docs"2) "points"The order of the names VSIM.INFO lists can differ.
Compatibility
Section titled “Compatibility”HotKV-only command. It is not related to the vector set commands (VADD,
VSIM) of Redis 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.