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

@mostlylucid/docsummarizer

v4.3.0

Published

Local-first RAG engine for documents: semantic segmentation, embeddings, salience-aware retrieval, and citation-grounded Q&A

Readme

@mostlylucid/docsummarizer

A local-first RAG engine for documents: semantic segmentation, embeddings, salience-aware retrieval, and citation-grounded Q&A — without requiring cloud APIs.

import { DocSummarizer } from "@mostlylucid/docsummarizer";

const doc = new DocSummarizer();
const { summary } = await doc.summarizeFile("report.pdf");
const { answer, evidence } = await doc.askFile("report.pdf", "What are the key findings?");

Install

npm install @mostlylucid/docsummarizer

The CLI binary is automatically downloaded during installation. Verify it works:

npx @mostlylucid/docsummarizer check

What It Does

  • RAG Q&A — Ask questions with source citations (single doc or folders)
  • Salience-aware retrieval — Better chunks, less noise
  • Deterministic ingestion — Same document = same segments = reproducible results
  • Local-first embeddings — ONNX runtime, no API keys required
  • Composable storage — Built-in stores or export embeddings to your own

How It Works

  1. Segment — Splits documents into semantic units (sentences, headings, lists, code blocks)
  2. Embed — Generates 384-dim vectors using BERT (runs locally via ONNX)
  3. Score — Computes salience scores based on position, structure, and content
  4. Retrieve — Finds relevant segments using cosine similarity
  5. Synthesize — Optionally uses an LLM to generate coherent answers

No API keys required for basic usage. Add Ollama for LLM-enhanced synthesis.


API

Summarize

// File (supports .md, .pdf, .docx, .txt)
const result = await doc.summarizeFile("./document.md");

// URL
const result = await doc.summarizeUrl("https://example.com/article");

// Raw markdown
const result = await doc.summarizeMarkdown("# My Doc\n\nContent here...");

// With options
const result = await doc.summarizeFile("./doc.md", {
  query: "focus on security concerns",  // Focus summary on specific topic
  mode: "BertRag",                       // Summarization mode
});

console.log(result.summary);      // The summary text
console.log(result.wordCount);    // Word count
console.log(result.topics);       // Extracted topics with sources

Question Answering

const result = await doc.askFile("./contract.pdf", "What are the payment terms?");

console.log(result.answer);       // The answer
console.log(result.confidence);   // "High" | "Medium" | "Low"
console.log(result.evidence);     // Source segments with similarity scores

Semantic Search

Search finds relevant segments within a single document (not a global index).

const result = await doc.search("./document.md", "machine learning", {
  topK: 5,  // Max results (default: 10)
});

result.results.forEach(r => {
  console.log(`[${r.score.toFixed(2)}] ${r.section}: ${r.preview}`);
});

Diagnostics

// Quick check
const ok = await doc.check();

// Detailed diagnostics
const info = await doc.diagnose();
console.log(info.available);       // true/false
console.log(info.executablePath);  // Resolved CLI path
console.log(info.output);          // Raw diagnostic output

CLI Usage

The package includes a CLI passthrough:

# Check installation
npx @mostlylucid/docsummarizer check

# Run diagnostics
npx @mostlylucid/docsummarizer doctor

# Summarize (JSON output)
npx @mostlylucid/docsummarizer tool --file doc.md

# Search
npx @mostlylucid/docsummarizer search --file doc.md --query "topic" --json

# All CLI commands
npx @mostlylucid/docsummarizer --help

Modes

| Mode | Description | Requires LLM | |------|-------------|--------------| | Auto | Auto-select based on document | Maybe | | BertRag | BERT embeddings + retrieval | No | | Bert | Pure extractive (BERT only) | No | | BertHybrid | BERT + LLM synthesis | Yes | | Rag | Full RAG pipeline | Yes |

// No LLM needed
await doc.summarizeFile("doc.md", { mode: "BertRag" });

// LLM-enhanced (requires Ollama)
await doc.summarizeFile("doc.md", { mode: "BertHybrid" });

Configuration

Constructor Options

const doc = new DocSummarizer({
  executable: "/path/to/docsummarizer",  // Custom CLI path
  configPath: "./config.json",            // Config file
  model: "llama3.2",                      // Ollama model
  timeout: 300000,                        // Timeout (ms)
});

Config File

Create docsummarizer.json:

{
  "ollama": {
    "baseUrl": "http://localhost:11434",
    "model": "llama3.2"
  },
  "onnx": {
    "embeddingModel": "AllMiniLmL6V2"
  }
}

Environment Variables

DOCSUMMARIZER_PATH=/path/to/cli         # Direct path to CLI
DOCSUMMARIZER_PROJECT=/path/to/proj.csproj  # Use dotnet run (dev mode)

Response Types

SummaryResult

interface SummaryResult {
  schemaVersion: string;  // "1.0.0"
  success: true;
  source: string;
  type: "summary";
  summary: string;
  wordCount: number;
  topics: Array<{
    topic: string;
    summary: string;
    sourceChunks: string[];
  }>;
  entities?: {
    people?: string[];
    organizations?: string[];
    locations?: string[];
    dates?: string[];
  };
  metadata: {
    documentId: string;
    totalChunks: number;
    chunksProcessed: number;
    coverageScore: number;   // 0-1
    processingTimeMs: number;
    mode: string;
    model: string;
  };
}

QAResult

interface QAResult {
  schemaVersion: string;
  success: true;
  source: string;
  type: "qa";
  question: string;
  answer: string;
  confidence: "High" | "Medium" | "Low";
  evidence: Array<{
    segmentId: string;
    text: string;
    similarity: number;  // 0-1
    section: string;
  }>;
  metadata: {
    processingTimeMs: number;
    model: string;
  };
}

SearchResult

interface SearchResult {
  schemaVersion: string;
  query: string;
  results: Array<{
    section: string;
    score: number;    // 0-1 (cosine similarity)
    preview: string;
  }>;
}

Error Handling

import { DocSummarizer, DocSummarizerError } from "@mostlylucid/docsummarizer";

try {
  await doc.summarizeFile("missing.md");
} catch (err) {
  if (err instanceof DocSummarizerError) {
    console.error(err.message);  // Error description
    console.error(err.output);   // Raw CLI output
  }
}

Events

doc.on("stderr", (data: string) => {
  console.log("Progress:", data);
});

Requirements

  • Node.js 18+
  • .NET 8+ runtime
  • Ollama (optional, for LLM modes)

Troubleshooting

CLI not found

# Run diagnostics
npx @mostlylucid/docsummarizer doctor

# Re-run postinstall to download CLI
node node_modules/@mostlylucid/docsummarizer/scripts/postinstall.js

# Verify
npx @mostlylucid/docsummarizer check

PDF/DOCX not working

PDF and DOCX conversion requires the Docling service. See CLI docs.

Slow first run

First run downloads ONNX models (~50MB). Subsequent runs are fast.



Why This Isn't a RAG Framework

  • No agent orchestration — You control the flow
  • No opinionated prompts — Bring your own LLM prompts
  • No cloud dependency — Runs entirely local

Why It Still Is RAG

This is a RAG engine, not a RAG framework. It handles:

  • Semantic chunking with structure preservation
  • Vector embeddings (local ONNX)
  • Similarity-based retrieval with salience scoring
  • Citation-grounded answers

What it doesn't handle (by design): conversational memory, agent loops, eval dashboards. Those are layers you add if you need them.


Links

License

MIT