Bitware Labs Est. 2022

Bitware Labs/bwmem

bwmem — memory that survives the session

The memory layer from our own long-running agent, pulled out and published as a standalone SDK. Facts, embeddings, contradiction detection and multi-stage consolidation for AI that has to remember things past next Tuesday.

v0.2.2Current release
AGPL3.0-only
Node 18+TypeScript, typed

The problem it solves

§ 01 — Rationale

Bolting a vector store onto a chatbot gives you something that looks like memory for about a month. Then the corpus fills with near-duplicates, retrieval quality falls as storage grows, nothing ever becomes false, and cost scales with history rather than relevance.

bwmem treats memory as a pipeline rather than a bucket. Messages go in; structured facts, summaries, embeddings and a knowledge graph come out, and a background consolidation pass keeps the whole thing from silting up. The longer argument is here.

What is in it

§ 02 — Capabilities

Fact extraction

Structured facts pulled from conversation automatically — names, work, preferences, relationships, career signals — as key/value claims rather than retrieved paragraphs. Semantic dedup compares normalised keys and value similarity, so the same fact stated forty ways stays one fact.

Semantic search over pgvector

Embeddings in PostgreSQL via pgvector — no separate vector database to operate, back up and keep consistent with your relational data. Search across messages, conversations and facts.

Multi-stage consolidation

Episodic at session end, then daily, then weekly. Each pass compresses, reconciles and lets cold material fall away. Runs in a background queue, never in the turn the user is waiting on.

Contradiction detection

Behavioural contradictions surfaced across sessions, with awareness of multi-valued facts and temporal context — so “moved to Berlin” supersedes “lives in Tokyo”, while “speaks Polish” simply joins “speaks Swedish”.

Emotional capture

High-affect moments identified by valence–arousal–dominance analysis and retained preferentially. Not sentiment for its own sake — a retention heuristic, because what someone reacted strongly to is disproportionately what matters later.

Knowledge graph

Optional Neo4j integration with schema-constrained entity relationships across 27 types, entity-to-entity edges, and entity-scoped subgraphs for questions semantic search answers badly.

Context builder

Aggregates nine memory sources into one formatted prompt injection, so what reaches your LLM is a deliberate budget across facts, recency, summaries and affect — not whatever ten chunks the index happened to return.

Provider-agnostic

OpenAI, Ollama, OpenRouter or a provider you write yourself. Embeddings and chat are injected dependencies, so running entirely local is a configuration choice rather than a fork.

Getting started

§ 03 — Practice

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.

Want it built into something

§ 04 — Engagement

bwmem is what we reach for when a client needs an agent that holds state. Typical work: designing what the agent should actually remember, choosing consolidation cadences that suit the traffic, wiring a local inference provider so conversation data never leaves the building, and operating the Postgres and Redis behind it.

How engagements work →

Correspondence

Write to the lab

Commissions, collaborations, or a quiet hello. The person you write to is the person who does the work — I reply within two working days.