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

pageindex-ts

v1.0.3

Published

LLM-agnostic document indexing for js/ts - bring your own LLM and text

Readme

PageIndex TS 📑

Build intelligent document indices for RAG and Agents.

pageindex-ts converts documents Markdown into a hierarchical tree structure with semantic summaries. This structure gives your LLM a "map" of the document, allowing it to navigate large texts efficiently without getting lost in the context window.

💡 Inspiration: This project is a TypeScript port and adaptation inspired by VectifyAI/PageIndex (Python).

Why do I need this?

When you blindly chunk a large document (like a 50-page PDF) for RAG, you lose context.

  • "Section 1.2" might depend on "Section 1.0", but they end up in different chunks.
  • The LLM sees a fragment of text but doesn't know where it fits in the bigger picture.

PageIndex solves this by building a Tree:

  1. Structure: It understands headers and hierarchy (H1 -> H2 -> H3).
  2. Summary: It generates a tiny summary for each node in the tree.
  3. Navigation: You can feed this lightweight tree to an LLM so it can "look up" exactly which section it needs to read.

Installation

npm install pageindex-ts

Tutorials

Quick Start

1. The "Bring Your Own" Philosophy

We don't force you to use specific tools.

  • Bring Your Own LLM: Use OpenAI, Anthropic, Gemini, or even Ollama.
  • Bring Your Own Markdown Parser: use llama-parse, docling or any other pdf to markdown parser.

2. Usage (Markdown)

import { mdToTree } from 'pageindex-ts';
import OpenAI from 'openai';

// 1. Define your LLM function
const openai = new OpenAI();
const myLLM = async (prompt: string) => {
  const completion = await openai.chat.completions.create({
    model: 'gpt-4.1',
    messages: [{ role: 'user', content: prompt }],
  });
  return completion.choices[0].message.content || '';
};

// 2. Your Content
const markdown = `
# Project Alpha
## Overview
This project aims to...
## Timeline
Phase 1 starts in...
`;

// 3. Create the Index
const result = await mdToTree(markdown, docName, {
        llm,
        ifAddNodeSummary: true,
        ifAddNodeId: true,
        ifAddNodeText: true, // Store full text in nodes (matches Python notebook)
    });

console.log(JSON.stringify(result.structure, null, 2));
---

## How it Works

1.  **Parsing**: Identifies headers (Markdown).
2.  **Tree Building**: Constructs a nested JSON tree representing the document structure.
3.  **Summarization**: (Optional) Uses your LLM to generate a 1-sentence summary for every branch of the tree.

## Comparison with Original (Python)
- **Language**: TypeScript vs Python.
- **Async First**: Built for Node.js non-blocking I/O.
- **Zero Dependencies**: Lightweight, unlike the Python version which includes heavier ML libraries by default.
- **No PDF Support**: This version does not support PDF parsing.
- **Bring Your Own LLM**: Use OpenAI, Anthropic, Gemini, or even Ollama.
- **Bring Your Own Markdown Parser**: use llama-parse, docling or any other pdf to markdown parser.

## Contributing

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

## License

MIT