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

@forgedevstack/forge-ai

v1.0.0

Published

Thin RAG toolkit: text chunking, provider-agnostic embeddings, pgvector SQL helpers, and document extraction types.

Readme

@forgedevstack/forge-ai

Thin RAG toolkit for TypeScript: text chunking, provider-agnostic embeddings, pgvector SQL helpers, and document extraction types. Zero runtime dependencies — the embedding client uses the global fetch.

Part of the ForgeStack ecosystem.

Install

npm install @forgedevstack/forge-ai

Quick Example

Chunk a document, embed the chunks, and store/query them with pgvector:

import {
  chunkText,
  createOpenAiEmbeddingProvider,
  buildCreateTableSql,
  buildSimilarityQuerySql,
  formatVectorLiteral,
} from '@forgedevstack/forge-ai';

const chunks = chunkText(documentText, {
  strategy: 'sentence',
  chunkSize: 512,
  overlap: 64,
});

const provider = createOpenAiEmbeddingProvider({
  baseUrl: 'https://api.openai.com/v1',
  apiKey: process.env.OPENAI_API_KEY ?? '',
});

const embeddings = await provider.embed(chunks.map((chunk) => chunk.text));

await db.query(buildCreateTableSql({ table: 'documents', dimensions: provider.dimensions }));

for (const [position, chunk] of chunks.entries()) {
  await db.query(
    'INSERT INTO documents (content, embedding) VALUES ($1, $2)',
    [chunk.text, formatVectorLiteral(embeddings[position])],
  );
}

const [queryEmbedding] = await provider.embed(['What is ForgeStack?']);
const results = await db.query(
  buildSimilarityQuerySql({ table: 'documents', topK: 5 }),
  [formatVectorLiteral(queryEmbedding)],
);

The similarity query uses a $1 placeholder for the query vector — pass the output of formatVectorLiteral as the query parameter.

API Overview

Chunking

  • chunkText(text, options?) — dispatches on options.strategy ('fixed' default, or 'sentence').
  • chunkFixedSize(text, options?) — sliding character window of chunkSize stepping chunkSize - overlap, with correct startOffset/endOffset on every chunk.
  • chunkBySentence(text, options?) — splits on sentence boundaries (., !, ? followed by whitespace), packs sentences up to chunkSize characters, and carries trailing sentences up to overlap characters into the next chunk.

Both throw when overlap >= chunkSize. Defaults: chunkSize 512, overlap 64.

Embeddings

  • createOpenAiEmbeddingProvider(options) — returns an EmbeddingProvider targeting any OpenAI-compatible embeddings endpoint (POST {baseUrl}/embeddings). Supports custom model, dimensions, headers, and fetchImpl for testing or non-global fetch. Results are sorted by response index. Non-ok responses throw with status and body.
  • Implement the EmbeddingProvider interface to plug in any other provider.

pgvector

  • buildCreateTableSql(options)CREATE EXTENSION IF NOT EXISTS vector; plus a CREATE TABLE IF NOT EXISTS statement with id (bigserial), text, vector(dimensions), and JSONB metadata columns. Column names are configurable.
  • buildSimilarityQuerySql(options) — cosine distance (<=>) query with configurable select columns, optional WHERE clause, and LIMIT topK (default 5).
  • formatVectorLiteral(embedding) — formats a number[] as a pgvector literal like [0.1,0.2,0.3].

Document Extraction

  • Extractor, ExtractorInput, ExtractedDocument, and SupportedDocumentFormat ('pdf' | 'docx' | 'xlsx') types describe the extraction contract.
  • createExtractorRegistry(initial?) — registry with register, get, and has; get throws for unregistered formats.
  • createStubExtractor(format) — placeholder whose extract rejects, naming the optional peer dependency to install.

pdf-parse, mammoth, and xlsx are optional peer dependencies. v0.1.0 ships only the Extractor interface and stubs — install a parser and register your own Extractor implementation to extract real documents.

License

MIT © John Yaghobieh