# IMentorMemoryStore interface

> The IMentorMemoryStore interface of Novior.MentorAgent.Memory: Interface for persisting the Mentor AI contextual memory. MentorAgent registers…

- URL: https://docs.mentoragent.net/api/novior-mentoragent-memory/imentormemorystore
- Verified with: MentorAgent 1.2.0
- Last updated: 2026-10-27
- Packages: Novior.MentorAgent

Interface for persisting the Mentor AI contextual memory. MentorAgent registers `InMemoryMentorMemoryStore` by default (RAM, zero config). For real persistence, register your own implementation BEFORE AddMentorAgent():

```text title="Example"
// Redis
builder.Services.AddSingleton<IMentorMemoryStore, RedisMemoryStore>();

// EF Core
builder.Services.AddScoped<IMentorMemoryStore, EfCoreMemoryStore>();

// MongoDB
builder.Services.AddSingleton<IMentorMemoryStore, MongoMemoryStore>();

builder.Services.AddMentorAgent(options => { ... });
```

## Definition

Namespace: `Novior.MentorAgent.Memory`. Package: `Novior.MentorAgent`.

`public interface IMentorMemoryStore`

```shell
dotnet add package Novior.MentorAgent
```

## Methods

### `ClearAsync`

`Task ClearAsync(string userId, CancellationToken ct = default)`

Deletes all memory entries for a user.

### `DeleteAsync`

`Task DeleteAsync(string userId, string key, CancellationToken ct = default)`

Deletes a specific memory entry.

### `GetAsync`

`Task<string?> GetAsync(string userId, string key, CancellationToken ct = default)`

Retrieves a specific memory entry by key. Returns null if not found.

### `GetRecentAsync`

`Task<IReadOnlyList<MemoryEntry>> GetRecentAsync(string userId, int count = 10, CancellationToken ct = default)`

Retrieves the most recent N entries for the user, ordered by date descending.

### `SaveAsync`

`Task SaveAsync(string userId, string key, string value, CancellationToken ct = default)`

Saves a memory entry for a user.

**Parameters**

- `userId`: Unique user ID. Use "anonymous" if not authenticated.
- `key`: Memory key (e.g. "last\_action", "preferred\_filter")
- `value`: Serialized value (string, JSON, etc.)
- `ct`: Cancels the save.

---

- Previous: [Extensions.ServiceCollectionExtensions](https://docs.mentoragent.net/api/novior-mentoragent-extensions/servicecollectionextensions.md)
- Next: [MentorMemoryService class](https://docs.mentoragent.net/api/novior-mentoragent-memory/mentormemoryservice.md)
