We’re excited to highlight @hazeljs/memory — a new standalone package in the HazelJS alpha that gives you pluggable, user-scoped memory with one interface and multiple backends. Use it to keep user context in one place and share it between RAG and agents in-process.
Why a dedicated memory package?
Without a dedicated memory layer, user context often ends up scattered: in RAG conversation buffers, ad-hoc database tables, or hardcoded in prompts. That makes it hard to keep profile, preferences, and conversation history consistent across your AI features.
@hazeljs/memory solves this with a single model for:
- Profile — User identity and static attributes
- Preference — Stated preferences (language, theme, etc.)
- Behavioral — Inferred behavior patterns
- Emotional — Emotional state (often with TTL)
- Episodic — Event-based memories (what happened when)
- Semantic summary — Summarized or semantic facts
You get explicit vs inferred storage, optional TTL (e.g. for emotional state or short-lived context), and support for composite stores that combine multiple backends.
New features and capabilities
One interface, multiple backends
By default the package uses in-memory storage — no database or env vars required. For production, plug in the backend that fits your stack:
| Backend | Use case |
|---|---|
| In-memory | Development, tests, no DB |
| Prisma | Production, same app DB as @hazeljs/flow |
| Postgres (raw) | Existing Postgres without Prisma |
| Redis | High-throughput, shared across processes |
| Vector episodic | Episodic/semantic vector search |
| Composite | Route by category to primary + optional episodic store |
Memory categories
Each memory item is tagged with a category so you can query and expire data by purpose. Use MemoryCategory (profile, preference, behavioral, emotional, episodic, semantic_summary) and optional TTL for short-lived state like emotional context.
Composite store
Use CompositeMemoryStore to route by category: e.g. primary key-value store for profile and preferences, plus an optional vector store for episodic/semantic search. One service, multiple storage strategies.
RAG and agent integration
Use the @hazeljs/rag/memory-hazel adapter to back RAG’s MemoryManager with @hazeljs/memory. Pass the same store (or adapter-wrapped manager) to RAGPipelineWithMemory and every AgentRuntime so RAG and agents share the same user context in-process — no duplicate buffers or sync logic.
Quick start
In-memory (default, no dependencies)
pnpm add @hazeljs/memory
import { createDefaultMemoryStore, MemoryService } from '@hazeljs/memory';
const store = createDefaultMemoryStore();
const service = new MemoryService(store);
await service.initialize();
// Use service to get/set memory by userId, category, etc.
PostgreSQL with Prisma
When you already use Prisma (e.g. with @hazeljs/flow), use the Prisma store:
import { createPrismaMemoryStore, getMemoryPrismaClient } from '@hazeljs/memory/prisma';
import { MemoryService } from '@hazeljs/memory';
const prisma = getMemoryPrismaClient(process.env.DATABASE_URL);
const store = createPrismaMemoryStore(prisma);
const service = new MemoryService(store);
await service.initialize();
Run prisma generate before build and prisma migrate from the package directory when using the Prisma backend.
Sharing memory between RAG and agents
pnpm add @hazeljs/rag @hazeljs/memory
import { MemoryManager, RAGPipelineWithMemory } from '@hazeljs/rag';
import { createHazelMemoryStoreAdapter } from '@hazeljs/rag/memory-hazel';
import { MemoryService, createDefaultMemoryStore } from '@hazeljs/memory';
const hazelStore = createDefaultMemoryStore();
const memoryService = new MemoryService(hazelStore);
const ragStore = createHazelMemoryStoreAdapter(memoryService);
const memoryManager = new MemoryManager(ragStore);
// Pass the same MemoryManager to RAG and to every AgentRuntime
const rag = new RAGPipelineWithMemory(config, memoryManager, llmFunction);
// agentRuntime = new AgentRuntime({ ..., memoryManager });
One store, one source of truth for user context across your RAG pipeline and all agents.
What’s next
We’ll keep improving @hazeljs/memory with more backends, better defaults, and docs. Check the package README and Memory guide for full API and examples.
— The HazelJS Team
Top comments (0)