***

title: Memory (RAG)
subtitle: Remote memory operations and protocol-driven local memory requirements
slug: npm/memory
----------------

Memory behavior in `sdk@0.6.3` is driven by protocol instructions and remote memory endpoints.

## Protocol Semantics

During `processNPC`:

* API can request recall via `memoryRecall`
* API can request storage via `memoryStore`
* If either is requested and no memory engine is configured, `processNPC` fails fast

## Remote Memory Thunks

```typescript
import {
  createSDKStore,
  listMemoryRemoteThunk,
  recallMemoryRemoteThunk,
  storeMemoryRemoteThunk,
  clearMemoryRemoteThunk
} from '@forbocai/core';

const store = createSDKStore();
const apiUrl = 'https://api.forboc.ai';
const apiKey = process.env.FORBOCAI_API_KEY;

const listed = await store.dispatch(listMemoryRemoteThunk({
  npcId: 'npc_1',
  apiUrl,
  apiKey
})).unwrap();

const recalled = await store.dispatch(recallMemoryRemoteThunk({
  npcId: 'npc_1',
  query: 'merchant key',
  apiUrl,
  apiKey
})).unwrap();

await store.dispatch(storeMemoryRemoteThunk({
  npcId: 'npc_1',
  observation: 'Player bought the old key',
  importance: 0.9,
  apiUrl,
  apiKey
})).unwrap();

await store.dispatch(clearMemoryRemoteThunk({
  npcId: 'npc_1',
  apiUrl,
  apiKey
})).unwrap();
```

## CLI

```bash
npx forbocai memory list <npcId>
npx forbocai memory recall <npcId> <query>
npx forbocai memory store <npcId> <text>
npx forbocai memory clear <npcId>
npx forbocai memory export <npcId>
```
