# SCACHE.CREATE

> Create a semantic cache namespace with a vector dimension, distance metric and similarity threshold.

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

```
SCACHE.CREATE namespace dimensions [METRIC cosine | l2 | ip] [THRESHOLD similarity]
```

- Group: Semantic cache
- Complexity: O(1)
- 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.CREATE` creates a namespace for embeddings of exactly
`dimensions` values (1 to 65536).

## Options

| 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](https://docs.hotkv.com/commands/scache-get/index.md) to count a match as a hit. Default `0.85`. Change it later with [SCACHE.THRESHOLD](https://docs.hotkv.com/commands/scache-threshold/index.md). |

Option names and metric names are case-insensitive.

## Return value

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

## Examples

```
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)
```

## Compatibility

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

## See also

[SCACHE.SET](https://docs.hotkv.com/commands/scache-set/index.md), [SCACHE.GET](https://docs.hotkv.com/commands/scache-get/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), [AI features guide](https://docs.hotkv.com/ai-features/index.md)