npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

langmem-ts

v0.1.0

Published

TypeScript-native memory primitive for AI agents

Readme

langmem-ts

TypeScript-native memory primitive for AI agents.

License: MIT TypeScript Node

extract → embed → store → retrieve over any Postgres + pgvector backend.


Status

Early development. Not yet published to npm. API surface is stable for the core primitive; expect additions, not breaking changes.

Why

LangMem (Python) is excellent but Python-only. Mem0 is TypeScript-capable but VC-backed with the usual bifurcation risks. There is no credible MIT-licensed, framework-agnostic, TypeScript-native memory library for AI agents. langmem-ts fills that gap.

Install

npm install langmem-ts

Peer dependencies (you bring your own):

npm install openai pg

Quick start

import {
  OpenAIEmbedder,
  PgVectorStore,
  PgVectorRetriever,
  LLMExtractor,
} from "langmem-ts";

// Compose the four primitives
const extractor = new LLMExtractor({ apiKey: process.env.OPENAI_API_KEY! });
const embedder = new OpenAIEmbedder({ apiKey: process.env.OPENAI_API_KEY! });
const store = new PgVectorStore({ connectionString: process.env.DATABASE_URL! });
const retriever = new PgVectorRetriever({ connectionString: process.env.DATABASE_URL! });

// Validate that the column dimension matches your embedder output
await store.init(1536);

// Extract facts from a conversation turn
const facts = await extractor.extract({
  role: "user",
  content: "I decided to use pgvector for my memory system",
});

// Embed and store each fact
for (const fact of facts) {
  const vector = await embedder.embed(fact);
  await store.write({ content: fact, vector, metadata: { tags: ["tech"] } });
}

// Retrieve by semantic query later
const queryVector = await embedder.embed("what did I decide about vector databases");
const results = await retriever.search(queryVector, { topK: 5 });

for (const { memory, score } of results) {
  console.log(`[${score.toFixed(2)}] ${memory.content}`);
}

// Clean up when done
await store.close();
await retriever.close();

Core concepts

langmem-ts exposes four interfaces, each with a default OpenAI + Postgres implementation. Consumers swap any piece without touching library internals.

| Interface | Default | Purpose | |---|---|---| | Embedder | OpenAIEmbedder | Turns text into a vector | | Store | PgVectorStore | Writes memories to Postgres + pgvector | | Retriever | PgVectorRetriever | Searches memories by vector similarity | | Extractor | LLMExtractor | Distills conversation turns into facts worth remembering |

Every default accepts config via its constructor. The library never reads process.env on your behalf.

Requirements

  • Node.js 18 or newer
  • Postgres with the pgvector extension enabled
  • OpenAI API key (for default embedder + extractor — swap these out if you want)

Database setup

Run the reference migration against your Postgres database:

-- langmem-ts reference migration
-- Creates the pgvector extension and the default `memories` table.
--
-- IMPORTANT: The `embedding` column's dimension (1536 below) must match
-- the dimensions your Embedder produces. The library validates this at
-- startup and will refuse to run if they disagree.
--
-- If you use a different embedding model or dimension, change vector(1536)
-- to your model's output dimension BEFORE running this migration.

CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE IF NOT EXISTS memories (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  content     TEXT NOT NULL,
  embedding   vector(1536) NOT NULL,
  metadata    JSONB DEFAULT '{}',
  created_at  TIMESTAMPTZ DEFAULT now()
);

CREATE INDEX IF NOT EXISTS memories_embedding_idx
  ON memories USING ivfflat (embedding vector_cosine_ops);

The 1536 dimension matches the default embedder (OpenAI text-embedding-3-large truncated via matryoshka). Changing the embedding model or dimensions after memories exist will corrupt retrieval — PgVectorStore.init() validates this at startup and throws with an educational error on mismatch.

Design principles

  • Interface-first. Every component is an interface with a default implementation. Swap any piece.
  • Database-agnostic. Postgres + pgvector is the reference backend, not the only option.
  • Framework-agnostic. No LangGraph coupling. Works inside any TypeScript agent or plain script.
  • Zero env reads. Every config value is injected at construction.
  • Extraction precedes embedding. Raw conversation text retrieves poorly; extracted facts retrieve well.

License

MIT — see LICENSE.