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

adaptive-context-memory

v1.0.1

Published

High-performance long-term adaptive memory system for AI agents in TypeScript & Node.js

Readme

adaptive-context-memory

High-performance, standalone, zero-binary long-term adaptive memory system for AI agents and LLM applications in TypeScript & Node.js.


Features

  • Zero Binary Vector Search: Flat cosine similarity search in pure TypeScript. No C++ compilation or heavy FAISS binaries needed.
  • High Performance Local Database: Fast SQLite persistence via better-sqlite3.
  • Dual Memory Engine: Automatically classifies information into:
  • Semantic Facts: Long-term durable user knowledge (profile, skills, preferences).
  • Episodic Bubbles: Time-sensitive events, tasks, and deadlines with importance scoring.
  • Smart Contradiction Resolution: LLM agent dynamically decides whether to ADD, UPDATE, REPLACE, DELETE, or NOOP incoming facts.
  • MMR (Maximum Marginal Relevance) Search: Re-ranks query results for optimal relevance and diversity.
  • Batch & Cached Embeddings: Built-in LRU cache and single-call batch embedding to minimize API latency and cost.
  • Resilient Auto-Retry: Exponential backoff retry wrapper handles rate limits (429) and transient errors automatically.
  • Multi-Provider Support: Plug-and-play support for OpenAI and OpenRouter.

Installation

npm install adaptive-context-memory

Quick Start

import { configure, createTables, getDb, ContextMemory } from 'adaptive-context-memory';

// 1. Configure provider and model
configure({
  openrouterApiKey: process.env.OPENROUTER_API_KEY, // or openaiApiKey
  llmProvider: 'openrouter',
  llmModel: 'openai/gpt-4o-mini',
});

// 2. Initialize database schema
createTables();

// 3. Instantiate memory manager
const db = getDb();
const memory = new ContextMemory(db);

const CONVERSATION_ID = 1;

// 4. Extract and store memories from chat turns
await memory.add([
  { role: 'user', content: "My name is Prince and I'm a TypeScript developer." },
  { role: 'assistant', content: "Nice to meet you, Prince!" }
], CONVERSATION_ID);

// 5. Semantic MMR Search
const searchResult = await memory.search("what is the user's primary programming language?", CONVERSATION_ID);
console.log(searchResult.results);

API Reference

configure(options: ContextMemoryConfig)

Configures the global LLM provider, API keys, and embedding models.

createTables()

Initializes SQLite database tables and index migrations.

memory.add(messages, conversationId)

Extracts semantic facts and episodic bubbles from recent conversation turns, resolves contradictions, and saves to database & vector store.

memory.search(query, conversationId, options)

Performs MMR-ranked semantic search. Options include:

  • limit?: number (default 10)
  • mmrLambda?: number (default 0.6; 0.0 = max diversity, 1.0 = max similarity)
  • category?: string (filter by category: 'profile' | 'skill' | 'preference' | ...)

memory.getAll(conversationId, category?)

Lists all active memories for a conversation.

memory.getStats(conversationId)

Returns total count, breakdown by type/category, and embedding cache hit rates.

memory.consolidate(conversationId)

Scans for near-duplicate semantic facts and merges them into clean, concise facts via LLM.

memory.purgeOldBubbles(conversationId, olderThanDays)

Soft-deletes episodic bubbles older than $N$ days (default 30 days).


License

MIT