# MentorMemoryService class

> The MentorMemoryService class of Novior.MentorAgent.Memory: Scoped service that orchestrates contextual memory. UserId resolved in this order: 1. Signed-in…

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

Scoped service that orchestrates contextual memory. UserId resolved in this order: 1. Signed-in user → its NameIdentifier as it is, else sub, oid or the name with the claim in the key ("sub:...", "name:...") — see MentorUserKey 2. Otherwise → an anonymous key, per session or shared (MentorOptions.AnonymousIdentity)

## Definition

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

`public sealed class MentorMemoryService : IDisposable`

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

## Constructors

`public MentorMemoryService(IMentorMemoryStore store, IOptions<MentorOptions> options, ILogger<MentorMemoryService> logger, AuthenticationStateProvider? auth = null)`

## Methods

### `Dispose`

`public void Dispose()`

### `ForgetAllAsync`

`public Task ForgetAllAsync(CancellationToken ct = default)`

### `GetMemoryContextAsync`

`public Task<string> GetMemoryContextAsync(int count = 10, CancellationToken ct = default)`

### `GetUserIdAsync`

`public Task<string> GetUserIdAsync(CancellationToken ct = default)`

### `RecallAsync`

`public Task<string?> RecallAsync(string key, CancellationToken ct = default)`

### `RememberAsync`

`public Task RememberAsync(string key, string value, CancellationToken ct = default)`

### `RememberObjectAsync`

`public Task RememberObjectAsync(string key, object value, CancellationToken ct = default)`

### `SetCurrentQuery`

`public void SetCurrentQuery(string? query)`

Sets the current user message so [`MentorMemoryService.GetMemoryContextAsync`](https://docs.mentoragent.net/api/novior-mentoragent-memory/mentormemoryservice#getmemorycontextasync) can rank memories by relevance when [`MentorOptions.MemoryRelevanceFiltering`](https://docs.mentoragent.net/api/novior-mentoragent-options/mentoroptions#memoryrelevancefiltering) is enabled. Called by the orchestrator before each message (scoped instance, same as RAG's PrepareAsync).

---

- Previous: [IMentorMemoryStore interface](https://docs.mentoragent.net/api/novior-mentoragent-memory/imentormemorystore.md)
- Next: [AgentCardInfo class](https://docs.mentoragent.net/api/novior-mentoragent-models/agentcardinfo.md)
