UNPKG

agentfootprint

Version:

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

53 lines • 2.73 kB
/** * The ceiling used when nothing better is known: the measured `localEmbedder` * cliff (512 wordpiece tokens ≈ 1,800–2,000 characters of English). * * It is the floor of the shipped range, deliberately — a ceiling that is too * LOW only over-reports, and a ceiling that is too HIGH clips in silence. */ export const DEFAULT_MAX_CHUNK_CHARS = 2000; /** * Resolve the ceiling for one indexing call. * * A non-positive or non-finite value is treated as absent at BOTH levels: it * cannot describe a real ceiling, and honouring it would mark every chunk in * the corpus as truncated (or none of them) on the strength of a typo. */ export function resolveChunkCeiling(explicit, embedder) { if (isUsable(explicit)) return { chars: Math.floor(explicit), source: 'explicit' }; const declared = embedder?.maxInputChars; if (isUsable(declared)) return { chars: Math.floor(declared), source: 'embedder' }; return { chars: DEFAULT_MAX_CHUNK_CHARS, source: 'default' }; } function isUsable(value) { return typeof value === 'number' && Number.isFinite(value) && value > 0; } /** * The one sentence a run says out loud when something was clipped. * * It names the count (so the size of the hole is known), the ceiling AND where * it came from (so the reader knows which knob is theirs to turn), and the two * fixes — because "your index is silently incomplete" is useless without * "here is the line to change". */ export function truncationWarning(args) { const { caller, count, total, noun, ceiling } = args; const who = args.embedderId ? `'${args.embedderId}'` : 'the embedder'; const provenance = ceiling.source === 'explicit' ? `the maxChunkChars you passed` : ceiling.source === 'embedder' ? `${who}'s declared maxInputChars` : `the default — ${who} declares no maxInputChars`; return (`${caller}: ${count} of ${total} ${noun}(s) are longer than the ${ceiling.chars}-character ` + `input ceiling in effect (${provenance}), so they were embedded CLIPPED.\n` + ` The vector represents only the opening of each one, while the FULL text is stored and ` + `served as the passage — so retrieval cannot find wording that is plainly visible in the ` + `block the model is shown. Nothing throws and nothing scores zero; the corpus is quietly ` + `partially indexed.\n` + ` Fix: ${args.resplitHint ?? "re-split smaller (lower the splitter's maxChars)"}, or raise ` + `maxChunkChars if ${who} really reads more than ${ceiling.chars} characters.` + (args.idsIn ? `\n The affected ids are in ${args.idsIn}.` : '')); } //# sourceMappingURL=inputCeiling.js.map