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

@reaatech/hybrid-rag-ingestion

v0.1.0

Published

Document loading, preprocessing, and chunking strategies for hybrid RAG systems

Readme

@reaatech/hybrid-rag-ingestion

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Multi-format document loading, preprocessing, validation, and four configurable chunking strategies for hybrid RAG systems. Supports PDF, Markdown, HTML, and plain text with deterministic chunk ID generation.

Installation

npm install @reaatech/hybrid-rag-ingestion
# or
pnpm add @reaatech/hybrid-rag-ingestion

Feature Overview

  • Multi-format loading — PDF, Markdown, HTML, and plain text with automatic format detection
  • Text preprocessing — Unicode normalization, whitespace normalization, special character handling
  • Document validation — duplicate detection via content hashing, file size limits, format verification
  • Four chunking strategies — Fixed-Size, Semantic, Recursive, Sliding Window
  • Deterministic chunk IDs — reproducible IDs based on document ID + chunk index
  • Chunking benchmarks — compare strategies on your documents with measured quality
  • Typed errorsUnsupportedFormatError, FileSizeExceededError, DocumentParseError

Quick Start

import {
  DocumentLoader,
  TextPreprocessor,
  DocumentValidator,
  chunkDocument,
  ChunkingStrategy,
} from '@reaatech/hybrid-rag-ingestion';

// Load a document
const loader = new DocumentLoader({ allowedFormats: ['pdf', 'md', 'html', 'txt'] });
const doc = await loader.loadFile('./docs/report.pdf');
console.log(`Loaded: ${doc.id}, ${doc.content.length} chars`);

// Validate
const validator = new DocumentValidator({ maxFileSize: 10 * 1024 * 1024 }); // 10MB
const validation = validator.validate(doc);

// Chunk
const chunks = await chunkDocument(
  doc.content,
  doc.id,
  {
    strategy: ChunkingStrategy.SEMANTIC,
    chunkSize: 512,
    overlap: 50,
    similarityThreshold: 0.5,
  },
  doc.metadata,
);

API Reference

Document Loading

DocumentLoader

| Constructor Option | Type | Default | Description | |--------------------|------|---------|-------------| | allowedFormats | string[] | ['pdf','md','html','txt'] | Whitelist of accepted formats |

| Method | Returns | Description | |--------|---------|-------------| | loadFile(filePath) | Document | Load and parse a single file | | loadDirectory(dirPath) | Document[] | Load all supported files in a directory |

Custom Errors

| Error | When | |-------|------| | UnsupportedFormatError | File format not in allowedFormats | | FileSizeExceededError | File exceeds maxFileSize limit | | DocumentParseError | Parse failure for the detected format |

Preprocessing

TextPreprocessor

| Option | Type | Default | Description | |--------|------|---------|-------------| | normalizeUnicode | boolean | true | Normalize to NFC form | | normalizeWhitespace | boolean | true | Collapse multiple spaces, normalize newlines | | removeControlChars | boolean | true | Strip non-printable control characters |

Validation

DocumentValidator

| Option | Type | Default | Description | |--------|------|---------|-------------| | maxFileSize | number | 10 * 1024 * 1024 | Max file size in bytes | | minContentLength | number | 1 | Minimum document content length |

ValidationResult

| Property | Type | Description | |----------|------|-------------| | valid | boolean | Whether the document passed all checks | | errors | string[] | List of validation error messages |

Chunking Strategies

All strategies produce Chunk[] with deterministic IDs.

Fixed-Size

Splits by token count, word count, or character count with configurable overlap.

const chunks = await chunkDocument(content, docId, {
  strategy: ChunkingStrategy.FIXED_SIZE,
  chunkSize: 512,  // tokens
  overlap: 50,
});

| Parameter | Description | |-----------|-------------| | chunkSize | Target size in tokens | | overlap | Overlap between consecutive chunks in tokens |

Semantic

Splits at topic boundaries using sentence-level similarity. Best for long-form content.

const chunks = await chunkDocument(content, docId, {
  strategy: ChunkingStrategy.SEMANTIC,
  chunkSize: 512,
  overlap: 50,
  similarityThreshold: 0.5,
});

| Parameter | Description | |-----------|-------------| | similarityThreshold | Minimum similarity for boundary detection (0–1) |

Recursive

Hierarchical splitting: headers → paragraphs → sentences. Best for structured documents.

const chunks = await chunkDocument(content, docId, {
  strategy: ChunkingStrategy.RECURSIVE,
  chunkSize: 512,
  separators: ['\n## ', '\n', '. '],
});

| Parameter | Description | |-----------|-------------| | separators | Splitting delimiters in priority order |

Sliding Window

Fixed window moving by configurable stride. Best for dense retrieval scenarios.

const chunks = await chunkDocument(content, docId, {
  strategy: ChunkingStrategy.SLIDING_WINDOW,
  windowSize: 512,
  stride: 256,
});

| Parameter | Description | |-----------|-------------| | windowSize | Size of each window in tokens | | stride | Step size between windows in tokens |

Chunking Engine

ChunkingEngine

Orchestrator that routes to the correct strategy:

| Method | Description | |--------|-------------| | chunkDocument(content, docId, config, metadata?) | Main entry point — returns Chunk[] | | chunkBatch(documents, config) | Process multiple documents in sequence |

ChunkingBenchmark

Compare strategies head-to-head:

import { ChunkingBenchmark } from '@reaatech/hybrid-rag-ingestion';

const benchmark = new ChunkingBenchmark();
const results = await benchmark.benchmark(documents, [
  { name: 'fixed-512', config: { strategy: ChunkingStrategy.FIXED_SIZE, chunkSize: 512, overlap: 50 } },
  { name: 'semantic-512', config: { strategy: ChunkingStrategy.SEMANTIC, chunkSize: 512, overlap: 50 } },
]);

console.table(results.map(r => ({ name: r.name, chunkCount: r.chunkCount, avgTokens: r.avgTokens })));

Related Packages

License

MIT