Skip to content

Reference

MEM.* commands

Fifteen commands with no Redis equivalent. The dotted prefix follows the convention Redis modules use, so any client reaches these through the send-a-raw-command call it already has.

Index management

CommandReply
MEM.CREATE key [MODE SEARCH|VECTOR|HYBRID] [DIM n] [METRIC COSINE|L2|IP] [WEIGHTS kw vec rec imp] [HALFLIFE seconds]OK, or an error if the key exists
MEM.INFO keyMap: mode, dim, metric, weights, halflife, records, vectors, terms, avg_doc_len, bytes
MEM.CONFIG key [WEIGHTS kw vec rec imp] [HALFLIFE seconds]OK
MEM.CARD keyThe live record count
klyro
MEM.CREATE user:123 MODE HYBRID DIM 384 METRIC COSINE \
  WEIGHTS 0.35 0.50 0.10 0.05 HALFLIFE 604800
+OK

MEM.CONFIG user:123 WEIGHTS 0.25 0.60 0.10 0.05
+OK

MODE defaults to HYBRID, METRIC to COSINE, and HALFLIFE to the server's mem-recency-halflife. DIM is required for any mode that stores vectors and must be at or below mem-max-dim.

Writing records

CommandReply
MEM.ADD key [ID id] TEXT text [VEC blob | FVEC n f1..fn] [META field value]... [IMPORTANCE x] [TTL seconds] [NX|XX]The record id
MEM.DEL key id [id ...]Number removed
MEM.SETMETA key id field value [field value ...]Number of fields newly set
MEM.DELMETA key id field [field ...]Number removed
MEM.EXPIRE key id seconds1 if set; 0 seconds clears the deadline

Vectors

VEC takes raw little-endian float32 bytes, four per dimension, which is exactly what struct.pack or a Float32Array already holds. FVEC spells the same vector as decimal words so a query can be typed into redis-cli.

klyro
# typeable form
MEM.ADD user:123 TEXT "Prefers PostgreSQL." FVEC 4 0.1 0.9 0.2 0.4 \
  META type preference IMPORTANCE 0.85 TTL 86400
$1
1

# NX only writes when the id is absent, XX only when present
MEM.ADD user:123 ID pref:db TEXT "Prefers SQLite." FVEC 4 0.2 0.7 0.1 0.5 NX
$6
pref:db

Importance defaults to 0.5 and is clamped to the 0.0–1.0 range. Text is capped by mem-max-text-bytes, and the tokenizer stops after mem-max-terms-per-doc terms.

Reading records

CommandReply
MEM.GET key id [NOTEXT] [WITHMETA] [WITHVEC]The record as a map, or nil
MEM.MGET key id [id ...]Array of records, nil per missing id
MEM.SCAN key cursor [COUNT n] [FILTER ...][next cursor, ids]
klyro
MEM.GET user:123 1 WITHMETA
1) "id"          2) "1"
3) "text"        4) "Prefers PostgreSQL."
5) "importance"  6) "0.85"
7) "created_at"  8) (integer) 1757462400000
9) "meta"       10) 1) "type" 2) "preference"

MEM.SCAN user:123 0 COUNT 100 FILTER type EQ preference
1) "0"
2) 1) "1"

Querying

CommandReply
MEM.SEARCH key query [TOPK k] [FILTER ...] [flags]Ranked hits, keyword only
MEM.VSEARCH key (VEC blob | FVEC n f1..fn) [TOPK k] [FILTER ...] [flags]Ranked hits, semantic only
MEM.QUERY key [TEXT query] [VEC blob | FVEC n f1..fn] [TOPK k] [WEIGHTS ...] [FUSION LINEAR|RRF] [FILTER ...] [flags]Ranked hits, fused

MEM.QUERY is the one to reach for. Given only TEXT it runs a keyword search, given only a vector a semantic one, and given both it fuses the two rankings.

klyro
MEM.QUERY user:123 TEXT "what database do they prefer?" \
  FVEC 3 0.10 0.79 0.46 TOPK 5 \
  WEIGHTS 0.3 0.55 0.1 0.05 FUSION LINEAR \
  FILTER type EQ preference FILTER @importance GTE 0.5 \
  WITHSCORES WITHMETA

Return flags

FlagEffect
NOTEXTOmit the record text
WITHMETAInclude the metadata pairs
WITHVECInclude the stored vector
WITHSCORESInclude the fused score and its four components

Filters

Repeated FILTER field op value triples, ANDed, with EQ, NE, GT, GTE, LT, LTE, IN, and CONTAINS. A field beginning with @ reads the record rather than its metadata: @id, @text, @importance, @created_at, @updated_at. See filters & metadata.

Limits and errors

SituationResult
Key holds another typeWRONGTYPE error
MEM.SEARCH on a VECTOR indexError: the mode cannot serve keyword search
MEM.VSEARCH on a SEARCH indexError: the index stores no vectors
Vector length ≠ DIMError naming the expected dimension
TOPK above mem-max-topkError rather than a silent clamp
Scan would exceed mem-max-scanThe query is refused rather than partly answered