Requirements: Node.js 18 or newer, PostgreSQL with the
pgvector extension, and Redis. Neo4j only if you want the knowledge graph.
npm install @bitwarelabs/bwmem
import { BwMem } from '@bitwarelabs/bwmem';
import { OpenAIProvider } from '@bitwarelabs/bwmem/providers/openai';
const provider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! });
const mem = new BwMem({
postgres: 'postgresql://localhost/myapp',
redis: 'redis://localhost:6379',
embeddings: provider,
llm: provider,
});
await mem.initialize();
const session = await mem.startSession({ userId: 'user-123' });
// Fact extraction and embedding happen in the background.
await session.recordMessage({ role: 'user', content: 'I live in Tokyo and work at SakuraTech.' });
await session.recordMessage({ role: 'user', content: 'I lead the ML perception team.' });
// One formatted block, ready for your system prompt.
const context = await mem.buildContext('user-123', { query: 'Tell me about yourself' });
await session.end(); // triggers episodic consolidation
On the licence
bwmem is AGPL-3.0-only. If you run a modified version as a
network service, the AGPL requires you to offer that source to its users.
For everyone building something they intend to publish or self-host, that
is a non-issue. If it does not fit your situation,
write about a commercial licence
— that is a normal request and it gets a normal answer.
The package also ships a Fastify-based multi-tenant REST layer with API-key
auth, rate limiting, usage tracking and Swagger docs, so you can run bwmem as
an internal service rather than a library. It is in the package and
documented in the README; run it on your own infrastructure.