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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lbkm

v1.0.0

Published

Local Base Knowledge Model - A lightweight in-memory knowledge base with file persistence

Readme

LBKM - Local Base Knowledge Model

A lightweight, zero-dependency in-memory knowledge base with file persistence for Node.js. Features full-text search with BM25/TF-IDF ranking, automatic tokenization, and a simple CLI.

Features

  • Zero Dependencies - Pure Node.js, no external packages required
  • In-Memory Search - Fast BM25 and TF-IDF ranking algorithms
  • File Persistence - Automatic JSON file storage
  • Full-Text Search - Tokenization, stemming, stop word removal
  • TypeScript Support - Full type definitions included
  • CLI Interface - Use via npx lbkm or install globally
  • ES Modules - Modern ESM package

Installation

npm install lbkm

Or use directly with npx:

npx lbkm --help

CLI Usage

Quick Start

# Add knowledge
npx lbkm add -p "The sky is blue due to Rayleigh scattering of sunlight"
npx lbkm add -p "Water freezes at 0 degrees Celsius"
npx lbkm add -p "The Earth orbits the Sun in approximately 365 days"

# Query
npx lbkm -p "Why is the sky blue?"
npx lbkm -p "What is the freezing point?"

Try the Demo

# Load 40 sample documents (science, tech, history, general)
npx lbkm demo

# Query with different output modes
npx lbkm -p "black holes"              # Truncated output
npx lbkm -p "black holes" -e           # Expanded (full content)
npx lbkm -p "machine learning" -s      # Summary (grouped by relevance)

Commands

lbkm query -p "search query"     # Search the knowledge base
lbkm add -p "content"            # Add content
lbkm add -f ./file.txt           # Add content from file
lbkm list                        # List all documents
lbkm stats                       # Show statistics
lbkm clear                       # Clear all documents
lbkm demo                        # Load demo documents
lbkm interactive                 # Interactive mode

Options

-p, --prompt <text>    Query or content to add
-f, --file <path>      File to add as content
-n, --name <name>      Knowledge base name (default: 'default')
-d, --dir <path>       Storage directory (default: '.lbkm')
-l, --limit <num>      Max results (default: 10)
-m, --metadata <json>  JSON metadata for content
-e, --expand           Show full content (no truncation)
-s, --summary          Show AI-style summary of results
-j, --json             Output as JSON

Programmatic Usage

Basic Example

import { KnowledgeBase } from 'lbkm';

const kb = new KnowledgeBase();

// Add documents
kb.add('The quick brown fox jumps over the lazy dog');
kb.add('Machine learning is a subset of artificial intelligence');
kb.add('Node.js is a JavaScript runtime built on Chrome V8');

// Search
const results = kb.search('JavaScript runtime');
console.log(results);
// [{ document: {...}, score: 0.85, matchedTerms: ['javascript', 'runtim'] }]

With Persistence

import { PersistentKnowledgeBase } from 'lbkm';

const kb = new PersistentKnowledgeBase({
  name: 'my-kb',
  storagePath: './data'
});

// Load existing data
await kb.load();

// Add documents (auto-saved)
await kb.add('Important information here', { source: 'manual' });

// Search
const results = await kb.search('important');

// Clean up
await kb.close();

Advanced Options

import { KnowledgeBase } from 'lbkm';

const kb = new KnowledgeBase({
  algorithm: 'bm25',      // 'bm25' or 'tfidf'
  stemming: true,         // Apply word stemming
  removeStopWords: true,  // Remove common words
  caseSensitive: false    // Case-insensitive matching
});

// Batch add
kb.addBatch([
  { content: 'Document 1', metadata: { category: 'tech' } },
  { content: 'Document 2', metadata: { category: 'science' } }
]);

// Search with options
const results = kb.search('query', {
  limit: 5,
  minScore: 0.1
});

// Export/Import for custom storage
const state = kb.export();
// ... save state to database, etc.
kb.import(state);

Using Utilities

import { tokenizer, vector } from 'lbkm';

// Tokenization
const tokens = tokenizer.process('Hello World!');
// ['hello', 'world']

// TF-IDF calculation
const tf = vector.termFrequency(tokens);
const similarity = vector.cosineSimilarity(vecA, vecB);

API Reference

KnowledgeBase

| Method | Description | |--------|-------------| | add(content, metadata?) | Add a document | | addBatch(documents) | Add multiple documents | | get(id) | Get document by ID | | remove(id) | Remove a document | | search(query, options?) | Search documents | | all() | Get all documents | | clear() | Remove all documents | | export() | Export state for persistence | | import(state) | Import previously exported state | | stats() | Get statistics |

PersistentKnowledgeBase

Extends KnowledgeBase with automatic file persistence:

| Method | Description | |--------|-------------| | load() | Load from storage | | save() | Save to storage | | delete() | Delete from storage | | close() | Flush and clean up |

FileStorage

Low-level file storage:

| Method | Description | |--------|-------------| | save(key, data) | Save JSON data | | load(key) | Load JSON data | | delete(key) | Delete data | | list() | List all keys | | clear() | Delete all data |

How It Works

LBKM uses an inverted index for fast full-text search:

  1. Tokenization - Text is split into words, normalized, and optionally stemmed
  2. Indexing - Terms are mapped to document IDs in an inverted index
  3. Scoring - BM25 or TF-IDF algorithms rank documents by relevance
  4. Persistence - State is serialized to JSON files with atomic writes

Requirements

  • Node.js >= 20.0.0

License

MIT