UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

46 lines • 1.93 kB
/** * indexFolder — the one-call version, over the same pieces. * * Pattern: sugar. It composes `indexCorpus` and adds nothing the pieces do not * already do — which is the test a convenience has to pass here: if * it could not be written by a consumer in five lines using the * public API, it is hiding something instead of shortening it. * Role: rag/ layer. * Emits: whatever `indexCorpus` emits. * * The only judgement it adds is the splitter default, and it is the judgement * you would make yourself: a folder of Markdown gets `byHeading` (the document * declares its own sections), anything else gets `byParagraph`. Name a * `splitter` and that guess is not made. * * @example * ```ts * const report = await indexFolder('./docs', { * to: sqliteVectorStore({ file: './corpus.db' }), * embedder: staticEmbedder(), * }); * console.log(`${report.embedded} embedded, ${report.skipped} skipped`); * ``` */ import { indexCorpus } from './indexCorpus.js'; import { assertServesVectors } from '../memory/store/capability.js'; import { byHeading } from './splitters/byHeading.js'; import { byParagraph } from './splitters/byParagraph.js'; export async function indexFolder(dir, options) { const { to, include, recursive, splitter, ...rest } = options; // `indexCorpus` refuses this too — repeated here only so the message names // the call the reader actually wrote. assertServesVectors(to, 'indexFolder'); const looksLikeMarkdown = include === undefined || include.some((e) => e === '.md' || e === '.markdown'); return indexCorpus({ ...rest, source: { dir, ...(include && { include }), ...(recursive !== undefined && { recursive }), }, store: to, splitter: splitter ?? (looksLikeMarkdown ? byHeading() : byParagraph()), }); } //# sourceMappingURL=indexFolder.js.map