Skip to content

Memory System Data Models

Last Updated: 2026-02-06
Content-Type: Reference
Audience: Developers


Database Schema

Memories Table

Table: memories

FieldTypeDescription
idINTEGERPrimary key
userIdINTEGERUser who owns this memory (NULL = world/global)
contentTEXTMemory content
sourceSTRINGMemory source tag (e.g. conversation, diary, world-lore-v1)
embeddingVECTOREmbedding vector (pgvector vector(VECTOR_DIM))
conversation_idINTEGERConversation/thread ID (optional)
file_sourceSTRINGFile import/source identifier (optional)
createdAtTIMESTAMPCreation timestamp

Notes:

  • This codebase does not maintain updatedAt for memories (it is effectively append-only).

Memory Chunks Table

Table: memory_chunks

Chunk rows power chunked hybrid retrieval.

FieldTypeDescription
idINTEGERPrimary key
memoryIdINTEGERParent memory ID (memories.id)
userIdINTEGEROwner user (NULL = world/global)
conversationIdINTEGERConversation/thread ID (optional, continuity boost)
tierSTRINGworld | aso | personal
sourceSTRINGSource tag copied from memory (optional)
chunkIndexINTEGERChunk order within a memory
contentTEXTChunk text
embeddingVECTORChunk embedding (vector(VECTOR_DIM))
createdAtTIMESTAMPCreated timestamp
updatedAtTIMESTAMPUpdated timestamp

RAG Traces Table (Optional)

Table: rag_traces

Persisted only when RAG_TRACE=true to help debugging retrieval quality.

FieldTypeDescription
idINTEGERPrimary key
userIdINTEGERTarget user
conversationIdINTEGERConversation/thread (optional)
queryTextTEXTQuery that triggered retrieval
chunksJSONBRetrieved chunks (tier/score/content)
metaJSONBDebug metadata (path, depth, etc.)
createdAtTIMESTAMPCreated timestamp

TypeScript Interfaces

Memory Model

typescript
interface Memory {
  id: number;
  userId: number;
  content: string;
  source: 'world' | 'aso_core' | 'shared' | 'image_ocr_extraction' | 'document_ingestion' | 'vision_analysis';
  embedding?: number[];
  metadata?: MemoryMetadata;
  conversationId?: number;
  createdAt: Date;
  updatedAt: Date;
}

Memory Metadata

typescript
interface MemoryMetadata {
  conversationId?: number;
  fileContext?: string;
  visionContext?: string;
  uploadContextId?: string;
  playerName?: string;
  npcName?: string;
  yexianInstanceId?: number;
  personaId?: number;
}

Memory Data (for creation)

typescript
interface MemoryData {
  userId: number;
  content: string;
  source: 'world' | 'aso_core' | 'shared';
  metadata?: MemoryMetadata;
  conversationId?: number;
}

Full Context

typescript
interface FullContext {
  memories: Memory[];
  persona: Persona;
  emotions: Emotions;
  quests: Quest[];
  inventory: InventoryItem[];
}

Embedding Configuration

Embedding Provider (Configurable)

Embeddings are generated by backend/src/services/embedding.service.ts.

  • Gemini: gemini-embedding-001
  • OneAPI/OpenAI-compatible: POST /v1/embeddings via ONE_API_URL + ONE_API_KEY

Key env vars:

  • EMBEDDING_PROVIDER=gemini|oneapi
  • ONE_API_EMBEDDING_MODEL=text-embedding-3-small (1536 dims) or another allowed model
  • VECTOR_DIM=1536 (must match the DB vector column dimension)
  • EMBEDDING_CACHE_SIZE=500 (optional)

Vector Similarity Search SQL

sql
SELECT
  id,
  content,
  source,
  embedding <-> CAST(:queryVector AS vector) AS distance
FROM "memories"
WHERE "userId" = :userId AND embedding IS NOT NULL
ORDER BY distance
LIMIT :limit;

Memory Source Types

SourceDescriptionScope
worldUniversal knowledge, game world rulesAll users
aso_coreCore identity and beliefsAll users (immutable)
sharedUser-specific conversationsPer user
image_ocr_extractionOCR text from imagesPer user
document_ingestionProcessed documentsPer user
vision_analysisImage vision analysisPer user

ASO Universal Consciousness System Documentation