VECTOR.ADD to store a vector under an ID in an index.
The write is an upsert: an ID that is not in the index is added and the reply is 1, and an ID that is already there has its vector replaced and the reply is 0. Replacing a vector does not change VECTOR.COUNT, so the reply is what tells a bulk loader how many documents it actually introduced.
The vector can be given three ways. VALUES takes a count followed by that many decimal numbers. FP32 takes the raw little-endian 32-bit float blob, which skips decimal formatting and parsing on a binary-safe connection. BASE64-FP32 takes that same blob base64-encoded, which is how a binary vector travels over the REST API, where arguments are JSON strings. Whichever form is used, the length must match the index’s DIM.
Vector indexes are an Upstash extension. See the vector command overview for how an index is created, written to, and queried.
Syntax
Arguments
Important points
- The three vector forms are mutually exclusive and exactly one must be given.
VALUESis the readable form;FP32avoids decimal formatting on a binary-safe connection;BASE64-FP32carries the same bytes through JSON, which is what the REST API needs. - A vector whose length differs from the index’s
DIMreturnsERR vector dimension mismatch: expected <dim>, got <n>. - An index that does not exist returns
ERR Index <index> is not found. Create it withVECTOR.CREATEfirst.
Response
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples
TCP examples use the TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
This command is not supported yet in
@upstash/redis.upstash_redis
upstash_redis
This command is not supported yet in
upstash_redis.ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs