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

memg-core-js

v0.3.2

Published

Memory layer for LLM applications — native in-process engine with SQLite, hybrid search, and extraction pipeline

Readme

MemG TypeScript SDK

Memory layer for LLM applications. Zero runtime dependencies.

Install

npm install memg

Quick Start

Proxy Mode (Recommended)

Route LLM traffic through the MemG proxy for transparent memory recall and extraction.

import { MemG } from 'memg';
import OpenAI from 'openai';

const openai = MemG.wrap(new OpenAI(), { entity: 'user-123' });

const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'What do I usually order?' }],
});

Client Mode

Intercepts calls locally without running the proxy. Requires only the MCP server.

import { MemG } from 'memg';
import Anthropic from '@anthropic-ai/sdk';

const anthropic = MemG.wrap(new Anthropic(), {
  entity: 'user-123',
  mode: 'client',
});

const response = await anthropic.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Remind me about my preferences' }],
});

Direct Memory Operations

import { MemG } from 'memg';

const m = new MemG();

// Add memories (flexible input)
await m.add('user-123', 'likes coffee');
await m.add('user-123', ['works at Acme', 'prefers dark mode']);
await m.add('user-123', [
  { content: 'allergic to peanuts', type: 'identity', significance: 'high' },
]);

// Search
const results = await m.search('user-123', 'food preferences');
console.log(results.memories);

// List all
const all = await m.list('user-123', { type: 'identity' });

// Delete
await m.delete('user-123', 'memory-uuid');
await m.deleteAll('user-123');

Chat (Session-Aware)

chat() manages the full memory loop: sessions, history injection, recall, LLM call, exchange persistence, and extraction.

import { MemG } from 'memg';

const m = new MemG({ openaiApiKey: process.env.OPENAI_API_KEY, embedProvider: 'openai' });
await m.init();

const res = await m.chat(
  [{ role: 'user', content: 'I just moved to Seattle' }],
  'user-123'
);
console.log(res.content);

// Follow-ups are history-aware — the session tracks prior turns.
const res2 = await m.chat(
  [{ role: 'user', content: 'What city did I mention?' }],
  'user-123'
);

Low-Level MCP Client

import { MemGClient } from 'memg';

const client = new MemGClient('http://localhost:8686');

await client.add('user-1', [{ content: 'likes TypeScript' }]);
const results = await client.search('user-1', 'programming languages');

Gemini

import { MemG } from 'memg';
import { GoogleGenerativeAI } from '@google/generative-ai';

const genai = new GoogleGenerativeAI(process.env.GEMINI_API_KEY!);
const model = MemG.wrap(genai.getGenerativeModel({ model: 'gemini-2.5-flash' }), {
  entity: 'user-123',
  nativeConfig: { geminiApiKey: process.env.GEMINI_API_KEY, embedProvider: 'gemini' },
});

const result = await model.generateContent('What do you remember about me?');

Custom Store (MySQL, Postgres, etc.)

The SDK defaults to SQLite via better-sqlite3, but you can pass any object implementing the Store interface:

import { MemG, type Store } from 'memg';

class MyPostgresStore implements Store {
  // Implement all interface methods...
}

const m = new MemG({ store: new MyPostgresStore(connectionString) });

See Store in store.ts for the full interface contract (28 methods).

Supported Providers

| Provider | wrap() | Extraction | Embeddings | |----------|----------|------------|------------| | OpenAI | new OpenAI() | Yes | Yes | | Anthropic | new Anthropic() | Yes | No | | Gemini | genai.getGenerativeModel() | Yes | Yes |

Configuration

| Option | Default | Description | | ---------- | -------------------------- | ------------------------------------ | | mcpUrl | http://localhost:8686 | MCP server URL | | proxyUrl | http://localhost:8787/v1 | MemG proxy URL | | entity | — | Entity identifier for memory scoping | | mode | native | native, proxy, or client | | extract | true | Extract knowledge from responses | | nativeConfig.store | — | Custom Store implementation | | nativeConfig.embedProvider | sentence-transformers | sentence-transformers, openai, or gemini | | nativeConfig.geminiApiKey | — | Gemini API key for embeddings/LLM |

Requirements

  • Node.js >= 18 (native fetch)
  • For native mode: better-sqlite3 (auto-installed)
  • For proxy/client mode: MemG server running
  • OpenAI SDK >= 4.0.0 (optional peer dependency)
  • Anthropic SDK >= 0.20.0 (optional peer dependency)
  • @google/generative-ai (optional peer dependency)