# AMEM.SEARCH

> Search an agent's memory by embedding and return the closest entries with their source.

URL: https://docs.hotkv.com/commands/amem-search/

```
AMEM.SEARCH agent_id k value [value ...]
```

- Group: Agent memory
- Complexity: O(log N) where N is the number of facts
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the agent-memory license feature

Agent memory gives AI agents four kinds of memory. `AMEM.SEARCH` returns up
to `k` entries closest to a query embedding, most similar first, each tagged
with the memory it came from. It searches the agent's semantic memory only, so
every result has the source `semantic`. Note that `k` comes before the vector.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Array of results. Each result is a flat array: `"source"`, the source, `"key"`, the key, `"content"`, the content, `"similarity"`, the cosine similarity as a string (all bulk strings). Empty for an unknown agent or a vector of the wrong size. | Same |

Errors:

- `ERR invalid k` if `k` is not a positive integer.
- `ERR invalid vector component` if a vector value is not a finite number.
- `ERR empty embedding vector` if no vector values are given.
- `ERR wrong number of arguments for 'amem.search' command` if the argument count is wrong.
- `NOLICENSE agent-memory requires a HotKV license. Contact sales@hotkv.com` if your license does not include the `agent-memory` feature.

## Examples

```
127.0.0.1:6379> AMEM.SEARCH notes 1 0.1 0.2 0.31
1) 1) "source"
   2) "semantic"
   3) "key"
   4) "fact-1"
   5) "content"
   6) "Paris is the capital of France."
   7) "similarity"
   8) "0.99990195"
```

## Compatibility

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

## See also

[AMEM.SEM.CREATE](https://docs.hotkv.com/commands/amem-sem-create/index.md), [AMEM.SEM.STORE](https://docs.hotkv.com/commands/amem-sem-store/index.md), [AMEM.SEM.RECALL](https://docs.hotkv.com/commands/amem-sem-recall/index.md), [AMEM.SEM.FORGET](https://docs.hotkv.com/commands/amem-sem-forget/index.md), [AMEM.SEM.LIST](https://docs.hotkv.com/commands/amem-sem-list/index.md), [AI features guide](https://docs.hotkv.com/ai-features/index.md)