# SCACHE.GET

> Find the cached response whose query embedding is most similar to yours, if it clears the threshold.

URL: https://docs.hotkv.com/commands/scache-get/

```
SCACHE.GET namespace value [value ...] [THRESHOLD similarity]
```

- Group: Semantic cache
- Complexity: O(log N) where N is the number of entries
- HotKV Cloud: Performance and Scale plans
- 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](https://docs.hotkv.com/commands/scache-stats/index.md), except a call
with the wrong number of vector values, which returns nil without counting.

## 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](https://docs.hotkv.com/commands/scache-create/index.md) and [SCACHE.THRESHOLD](https://docs.hotkv.com/commands/scache-threshold/index.md)) and leaves it unchanged. Put it after the vector values. |

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

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

## Compatibility

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

## See also

[SCACHE.CREATE](https://docs.hotkv.com/commands/scache-create/index.md), [SCACHE.SET](https://docs.hotkv.com/commands/scache-set/index.md), [SCACHE.STATS](https://docs.hotkv.com/commands/scache-stats/index.md), [SCACHE.FLUSH](https://docs.hotkv.com/commands/scache-flush/index.md), [SCACHE.DROP](https://docs.hotkv.com/commands/scache-drop/index.md), [SCACHE.LIST](https://docs.hotkv.com/commands/scache-list/index.md), [SCACHE.THRESHOLD](https://docs.hotkv.com/commands/scache-threshold/index.md), [PCACHE.GET](https://docs.hotkv.com/commands/pcache-get/index.md), [AI features guide](https://docs.hotkv.com/ai-features/index.md)