01Install
Install from npm into your project.
pnpm add @lov3kaizen/agentsea-ingest02Example
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 })ingester.ingestFile(path) / ingestUrl(url) / ingestBuffer(buffer, filename)ingester.ingestDirectory(path, { recursive, include, exclude })pipelines.simple() / full() / rag() / analysis() / ocr()createFixedChunker / createRecursiveChunker / createSemanticChunker / createHierarchicalChunker04Caveats
- 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.
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.
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.
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));