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

@ekai/mindmap

v0.1.8

Published

Semantic clustering mindmap for AI agent context management

Downloads

1,043

Readme

@ekai/mindmap

Semantic clustering mindmap for AI agent context management. Organizes conversation items into a hierarchical tree using embeddings and retrieves relevant context via beam search.

Install

npm install @ekai/mindmap

Quick Start

import { createMindmap } from '@ekai/mindmap';

const mindmap = createMindmap({
  provider: 'openrouter',
  apiKey: process.env.OPENROUTER_API_KEY!,
});

// Add conversation items
await mindmap.add([
  { id: '1', role: 'user', content: 'How do I set up authentication?' },
  { id: '2', role: 'assistant', content: 'You can use JWT or OAuth2...' },
  { id: '3', role: 'user', content: 'What database should I use?' },
  { id: '4', role: 'assistant', content: 'PostgreSQL is a solid choice...' },
]);

// Simple query (single-branch, returns ConversationItem[])
const result = await mindmap.query('auth setup');

// Multi-branch search with token budgeting (for agent context windows)
const scored = await mindmap.search('authentication and database setup', {
  maxResults: 20,
  maxTokens: 4000,
  beamWidth: 3,
});
// scored.items — ScoredItem[] with { item, score, estimatedTokens }
// scored.paths — cluster label paths explored
// scored.totalEstimatedTokens — total tokens of returned items

Retrieval

query(text, maxResults?)

Greedy single-branch traversal. Follows the best-matching cluster at each tree level and returns the top items by cosine similarity. Fast, but may miss items in other clusters.

search(text, options?)

Multi-branch beam search. Explores the top beamWidth clusters at each level, collects items from all matching branches, and applies maxResults and maxTokens caps. Returns items with similarity scores and token estimates — designed for fitting relevant context into an agent's context window.

Embedding Providers

Pass a built-in provider or a custom embedding function:

// Built-in providers: 'openrouter', 'openai', 'gemini'
const mindmap = createMindmap({
  provider: 'openrouter',
  apiKey: '...',
  embedModel: 'openai/text-embedding-3-small', // optional
});

// Custom embedding function
const mindmap = createMindmap({
  embedFn: async (text) => myEmbedder.embed(text),
});

Storage

import { createMindmap, jsonFileStorage, memoryStorage } from '@ekai/mindmap';

// In-memory (default)
const mindmap = createMindmap({ provider: 'openrouter', apiKey: '...' });

// Persist to JSON file
const mindmap = createMindmap({
  provider: 'openrouter',
  apiKey: '...',
  storage: jsonFileStorage('./mindmap.json'),
});

Configuration

const mindmap = createMindmap({
  provider: 'openrouter',
  apiKey: '...',
  config: {
    similarityThreshold: 0.65, // min cosine similarity to follow a branch
    maxDepth: 4,               // max tree depth
    maxChildren: 10,           // max children per node
    rebuildInterval: 50,       // inserts before full tree rebuild
  },
});

License

MIT