SCACHE.GET
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.
Options
Section titled “Options”| 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. |
Return value
Section titled “Return value”| 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 componentif a vector value is not a finite number.ERR invalid thresholdif theTHRESHOLDvalue is not a number from0.0to1.0.ERR wrong number of arguments for 'scache.get' commandif the argument count is wrong.NOLICENSE semantic-cache requires a HotKV license. Contact sales@hotkv.comif your license does not include thesemantic-cachefeature.
Examples
Section titled “Examples”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.3OK127.0.0.1:6379> SCACHE.GET small 0.1 0.2 0.291) "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.51) "Paris"2) "0.7071"127.0.0.1:6379> SCACHE.GET strict 0.7071 0.7071 0 THRESHOLD 1.5(error) ERR invalid thresholdThe exact similarity digits depend on the stored vectors.
Compatibility
Section titled “Compatibility”HotKV-only command. Redis and Valkey have no equivalent.
See also
Section titled “See also”SCACHE.CREATE, SCACHE.SET, SCACHE.STATS, SCACHE.FLUSH, SCACHE.DROP, SCACHE.LIST, SCACHE.THRESHOLD, PCACHE.GET, AI features guide
Was this page helpful?
Thanks for the feedback.