Memory (RAG)

View as Markdown

The UE plugin exposes two memory layers:

  • remote NPC memory backed by the Forboc API
  • local node-backed memory backed by SQLite plus local embeddings

This matches the split between packages/core and packages/node.

During processNPC(...), the API can request memory recall or memory storage. If the runtime does not have local memory configured and the API asks for those steps, the protocol fails fast.

Memory Item Shape

1USTRUCT(BlueprintType)
2struct FMemoryItem {
3 UPROPERTY(BlueprintReadOnly) FString Id;
4 UPROPERTY(BlueprintReadOnly) FString Text;
5 UPROPERTY(BlueprintReadOnly) TArray<float> Embedding;
6 UPROPERTY(BlueprintReadOnly) int64 Timestamp;
7 UPROPERTY(BlueprintReadOnly) FString Type;
8 UPROPERTY(BlueprintReadOnly) float Importance;
9 UPROPERTY(BlueprintReadOnly) float Similarity;
10};

Local Node Memory

Use local memory when you want the UE runtime to satisfy protocol recall/store instructions directly.

1#include "RuntimeStore.h"
2#include "CLI/CliOperations.h"
3
4auto Store = createSDKStore();
5
6SDKOps::InitNodeMemory(Store, TEXT("/tmp/merchant.db"));
7SDKOps::StoreNodeMemory(Store, TEXT("Player bought the old key"), 0.9f);
8
9TArray<FMemoryItem> Recalled =
10 SDKOps::RecallNodeMemory(Store, TEXT("key"), 5, 0.7f);
11
12SDKOps::ClearNodeMemory(Store);

initNodeMemoryThunk(DatabasePath) tracks the active database path, and clearNodeMemoryThunk() clears that same resolved path. Custom database locations are supported.

Remote NPC Memory

Use the remote thunks when you want the API-backed per-NPC memory endpoints.

1#include "RuntimeStore.h"
2#include "CLI/CliOperations.h"
3#include "RuntimeConfig.h"
4
5auto Store = createSDKStore();
6SDKConfig::SetApiConfig(TEXT("https://api.forboc.ai"), ApiKey);
7
8TArray<FMemoryItem> Listed = SDKOps::MemoryList(Store, TEXT("npc_1"));
9TArray<FMemoryItem> RemoteRecall =
10 SDKOps::MemoryRecall(Store, TEXT("npc_1"), TEXT("key"), 10, 0.7f);
11
12SDKOps::MemoryStore(Store, TEXT("npc_1"),
13 TEXT("Player bought the old key"), 0.9f);
14SDKOps::MemoryClear(Store, TEXT("npc_1"));

Slice State

MemorySlice tracks:

  • entity-backed memory items
  • StorageStatus
  • RecallStatus
  • Error
  • LastRecalledIds

Useful selectors:

  • MemorySlice::SelectAllMemories(State)
  • MemorySlice::SelectLastRecalledMemories(State)
  • MemorySlice::SelectMemoryById(State, Id)

Direct Thunks

For parity with the TypeScript SDKs, dispatch:

  • rtk::initNodeMemoryThunk(DatabasePath)
  • rtk::storeNodeMemoryThunk(Text, Type, Importance)
  • rtk::recallNodeMemoryThunk(Query, Limit, Threshold)
  • rtk::clearNodeMemoryThunk()
  • rtk::listMemoryRemoteThunk(NpcId)
  • rtk::recallMemoryRemoteThunk(NpcId, Query, Similarity)
  • rtk::storeMemoryRemoteThunk(NpcId, Observation, Importance)
  • rtk::clearMemoryRemoteThunk(NpcId)