AgentSea

Package

@lov3kaizen/agentsea-ingest

Parses PDF, DOCX, HTML, Markdown, text, CSV, Excel and JSON files, chunks them, and runs them through a pipeline for RAG use.

v1.2.1On npm

01Install

Install from npm into your project.

BASH
pnpm add @lov3kaizen/agentsea-ingest

02Example

TS
import { createIngester, pipelines } from '@lov3kaizen/agentsea-ingest';

const ingester = createIngester();
const doc = await ingester.ingestFile('./document.pdf');
console.log(`Extracted ${doc.chunks.length} chunks`);

const pipeline = pipelines.rag().build();
const result = await pipeline.process({ path: './document.md' });

03Key API

createIngester({ chunking, concurrency, fileSizeLimit, watchMode })
Creates an ingester with the given options.
ingester.ingestFile(path) / ingestUrl(url) / ingestBuffer(buffer, filename)
Parses one file, URL or buffer into chunks.
ingester.ingestDirectory(path, { recursive, include, exclude })
Parses every matching file in a directory.
pipelines.simple() / full() / rag() / analysis() / ocr()
Prebuilt pipelines, each finished with .build().
createFixedChunker / createRecursiveChunker / createSemanticChunker / createHierarchicalChunker
Chunking strategies.

04Caveats

  • OCR is listed for scanned documents, but the OCR engine is not named.
  • The example sets a 10 MB file size limit. The default limit is not stated.
  • The methods for table and image extraction are not described.
  • createSemanticChunker needs an embedding function you supply. Check the signatures, since some chunkers are called with await and others without.

05Supported formats

Each format has a parser. The parsers are also exported, so you can call one directly on a buffer.

TS
import { createPDFParser } from '@lov3kaizen/agentsea-ingest';
import { readFileSync } from 'fs';

const result = await createPDFParser().parse(readFileSync('./document.pdf'));
console.log(result.text, result.elements, result.tables);

PDF, DOCX, HTML, Markdown, plain text, CSV, Excel and JSON are supported. The parser classes are PDFParser, DOCXParser, HTMLParser, MarkdownParser, TextParser, CSVParser, ExcelParser and JSONParser.

06Watch mode

With watch mode on, the ingester processes files that are added or changed in the watched paths. Call startWatching to begin and stopWatching to stop.

TS
const ingester = createIngester({
  watchMode: {
    enabled: true,
    paths: ['./documents'],
    include: ['*.pdf', '*.md'],
    debounceDelay: 1000,
    processExisting: true,
  },
});

ingester.startWatching();

07Events

Pipeline.getEventEmitter returns an emitter. Subscribe with on and a document event type. The three events below are emitted for each document.

TS
const emitter = pipeline.getEventEmitter();

emitter.on('document:loaded', (event) => console.log('Loaded:', event.documentId));
emitter.on('document:chunked', (event) => console.log('Chunks:', event.chunkCount));
emitter.on('document:completed', (event) => console.log('Completed:', event.document.id));