Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@hazeljs/memory

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hazeljs/memory

Pluggable user memory for HazelJS - profile, preferences, behavioral patterns, emotional state, episodic and semantic memory with multi-store support

latest
Source
npmnpm
Version
0.8.7
Version published
Weekly downloads
97
-36.18%
Maintainers
1
Weekly downloads
 
Created
Source

@hazeljs/memory

Pluggable user memory for HazelJS. Profile, preferences, behavioral patterns, emotional state, episodic and semantic memory — one interface, multiple backends. Share the same store between RAG and agents in-process.

npm version npm downloads License: Apache-2.0

Storage: By default the package uses in-memory storage (no dependencies). For durable persistence, use the Prisma store (same pattern as @hazeljs/flow) or plug in Postgres, Redis, or vector backends.

Features

  • One interface, multiple backends — In-memory (default), Postgres (raw or Prisma), Redis, vector episodic, composite
  • Memory categories — Profile, preference, behavioral, emotional, episodic, semantic_summary
  • Explicit vs inferred — Store user-stated facts and system-inferred patterns separately
  • Optional TTL — e.g. for emotional state or short-lived context
  • Composite store — Route by category to primary + optional episodic/vector store
  • RAG & agent integration — Use createHazelMemoryStoreAdapter from @hazeljs/rag/memory-hazel to back MemoryManager; share one store across RAGPipelineWithMemory and AgentRuntime

Installation

pnpm add @hazeljs/memory

No database or env vars are required for the default in-memory mode.

Quick Start

In-memory (default, no dependencies)

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 use Prisma in your app (e.g. like @hazeljs/flow and @hazeljs/flow-runtime), 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();

Build: Run pnpm prisma:generate (or prisma generate) before pnpm build so the Prisma client is generated. Migrate with pnpm prisma:migrate from the package directory.

Persistence

BackendModule / FactoryUse case
In-memorycreateDefaultMemoryStore()Development, tests, no DB
PrismacreatePrismaMemoryStore(prisma) from @hazeljs/memory/prismaProduction, same app DB as flow/core
Postgres (raw)PostgresStore — pass a pg pool with a query method (see postgres.store.ts)Existing Postgres without Prisma
RedisRedisStore — pass an ioredis-style clientHigh-throughput, shared across processes
Vector episodicVectorEpisodicStoreEpisodic/semantic vector search
CompositeCompositeMemoryStoreRoute by category to primary + optional episodic store

Memory categories

CategoryDescription
profileUser identity and static attributes
preferenceStated preferences (e.g. language, theme)
behavioralInferred behavior patterns
emotionalEmotional state (often with TTL)
episodicEvent-based memories (what happened when)
semantic_summarySummarized or semantic facts

See types in src/types/.

Integration with @hazeljs/rag and @hazeljs/agent

To back RAG (and agent) memory with @hazeljs/memory so RAG and agents share the same user context in-process:

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 });

See @hazeljs/rag README (Memory System / Using @hazeljs/memory as the backend) for full details.

Scripts

  • prisma:generate — Generate Prisma client
  • prisma:migrate — Run migrations (dev)
  • prisma:deploy — Deploy migrations (prod)
  • prisma:studio — Open Prisma Studio (when using Prisma store)
  • test — Run tests

License

Apache 2.0 © HazelJS

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

Keywords

hazeljs

FAQs

Package last updated on 12 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts