Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SCACHE.CREATE

Last updated
SCACHE.CREATE namespace dimensions [METRIC cosine | l2 | ip] [THRESHOLD similarity]
Group
Semantic cache
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
Performance and Scale
On-Premise
requires the semantic-cache license feature

The semantic cache returns a cached LLM response when a new query embedding is similar enough to one you stored, so paraphrased requests can hit. Your application computes the embeddings. SCACHE.CREATE creates a namespace for embeddings of exactly dimensions values (1 to 65536).

Option Effect
METRIC cosine Cosine similarity (the default).
METRIC l2 Euclidean distance, turned into a score that is 1 for identical vectors and falls toward 0 as the distance grows.
METRIC ip Inner product. Use it with normalized embeddings.
THRESHOLD similarity Minimum similarity, from 0.0 to 1.0, for SCACHE.GET to count a match as a hit. Default 0.85. Change it later with SCACHE.THRESHOLD.

Option names and metric names are case-insensitive.

Case RESP2 RESP3
Namespace created Simple string OK Same

Errors:

  • ERR invalid dimensions (must be 1-65536) if dimensions is not an integer in that range.
  • ERR unknown metric, use cosine|l2|ip for any other metric.
  • ERR threshold must be 0.0-1.0 if the threshold is out of range or not a number.
  • ERR unknown option 'name' for an option other than METRIC and THRESHOLD, and ERR syntax error if an option has no value.
  • ERR namespace already exists or limit reached if the namespace exists, or the server already holds its maximum number of semantic cache namespaces (max_namespaces under [scache]).
  • ERR wrong number of arguments for 'scache.create' command if the argument count is wrong.
  • NOLICENSE semantic-cache requires a HotKV license. Contact sales@hotkv.com if your license does not include the semantic-cache feature.
127.0.0.1:6379> SCACHE.CREATE llm_cache 1536 METRIC cosine THRESHOLD 0.92
OK
127.0.0.1:6379> SCACHE.CREATE small 3
OK
127.0.0.1:6379> SCACHE.CREATE bad 0
(error) ERR invalid dimensions (must be 1-65536)

HotKV-only command. Redis and Valkey have no equivalent.

SCACHE.SET, SCACHE.GET, SCACHE.STATS, SCACHE.FLUSH, SCACHE.DROP, SCACHE.LIST, SCACHE.THRESHOLD, AI features guide