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.GET

Last updated
SCACHE.GET namespace value [value ...] [THRESHOLD similarity]
Group
Semantic cache
Complexity
O(log N) where N is the number of entries
Arity
-3 (at least 3 words, counting the command name)
Flags
read-only, 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.GET searches the namespace for the stored embedding closest to the one you pass (one argument per value). If its similarity is at least the namespace’s threshold and the entry has not expired, it is a hit. THRESHOLD similarity replaces the namespace’s threshold for this one lookup. Each call counts as a hit or a miss in SCACHE.STATS, except a call with the wrong number of vector values, which returns nil without counting.

Option Effect
THRESHOLD similarity Minimum similarity, from 0.0 to 1.0, for this lookup only. It replaces the namespace’s threshold (see SCACHE.CREATE and SCACHE.THRESHOLD) and leaves it unchanged. Put it after the vector values.
Case RESP2 RESP3
Hit Array of two bulk strings: the cached response and the similarity score Same
Miss, unknown namespace, or wrong number of vector values Nil bulk string Null

Errors:

  • ERR invalid vector component if a vector value is not a finite number.
  • ERR invalid threshold if the THRESHOLD value is not a number from 0.0 to 1.0.
  • ERR wrong number of arguments for 'scache.get' 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.SET small "What is the capital of France?" "The capital of France is Paris." 0.1 0.2 0.3
OK
127.0.0.1:6379> SCACHE.GET small 0.1 0.2 0.29
1) "The capital of France is Paris."
2) "0.99986"
127.0.0.1:6379> SCACHE.GET small 0.9 -0.4 0.1
(nil)

A lookup can ask for a stricter or a looser match than the namespace does. In a namespace created with THRESHOLD 0.99, a stored vector 1 0 0 and a query with similarity 0.7071:

127.0.0.1:6379> SCACHE.GET strict 0.7071 0.7071 0
(nil)
127.0.0.1:6379> SCACHE.GET strict 0.7071 0.7071 0 THRESHOLD 0.5
1) "Paris"
2) "0.7071"
127.0.0.1:6379> SCACHE.GET strict 0.7071 0.7071 0 THRESHOLD 1.5
(error) ERR invalid threshold

The exact similarity digits depend on the stored vectors.

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

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