> ## Documentation Index
> Fetch the complete documentation index at: https://askmarvin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Memory

> Store and retrieve facts with a vector database

A `Memory` gives an agent tools to add, search, and delete facts. It uses a vector-database provider, separately from the database that stores [thread history](https://askmarvin.ai/concepts/threads.md).

The default provider, `chroma-ephemeral`, keeps data in memory. It does **not** survive a process restart. Install Chroma separately and choose `chroma-db` for persistence:

```bash theme={null}
uv add chromadb
```

```python theme={null}
import marvin

preferences = marvin.Memory(
    key="user_preferences",
    provider="chroma-db",
    instructions="Store the user's stated writing preferences.",
)
assistant = marvin.Agent(memories=[preferences])
assistant.run("Remember that I prefer short answers.")
```

`chroma-db` stores data under `~/.marvin/memory/chroma` by default. Reuse the same provider configuration and memory key to access stored facts later.

## Direct operations

```python theme={null}
import asyncio
import marvin

async def main():
    memory = marvin.Memory(key="writing_preferences", provider="chroma-db")
    memory_id = await memory.add("The user prefers short answers.")
    results = await memory.search("Preferred answer length", n=1)
    await memory.delete(memory_id)
    print(results)

asyncio.run(main())
```

Search returns a dictionary of memory IDs and their contents. A memory key may contain letters, numbers, and underscores.

## Retrieval and providers

By default, the agent chooses whether to use memory tools. `auto_use=True` also queries memory before the agent runs, using recent messages.

You can pass a `MemoryProvider` instance or a supported provider string: `chroma-ephemeral`, `chroma-db`, `chroma-cloud`, `lancedb`, `postgres`, or `qdrant`. Each provider needs its own dependencies and configuration; see the [memory API](https://askmarvin.ai/api-reference/marvin-memory-memory.md).

Memory can be shared by multiple agents. Use separate keys for facts that should be searched separately. `MARVIN_DATABASE_URL` configures thread history, not vector memory.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.