@absolutejs/rag 0.22.15 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ This file is generated by `absolute-changelog` from the entries in
6
6
  `changelog/`. Edit an entry, not this file — and add new ones under
7
7
  `changelog/unreleased/`.
8
8
 
9
+ ## 0.23.0 — 2026-11-02
10
+
11
+ ### Added
12
+
13
+ - **Opt-in bounded evidence correction with fresh independent review, reserved retrieval, retained review history and atomic collection fact coverage.** (`createResearch`, `ResearchConfig`, `ResearchResult`, `ResearchTask`)
14
+
9
15
  ## 0.22.15 — 2026-11-01
10
16
 
11
17
  ### Fixed
package/RESEARCH.md CHANGED
@@ -305,3 +305,11 @@ to a different model. A stronger reviewer does not repair missing retrieval.
305
305
  An invalid planner schema no longer discards retrieved evidence: extraction and
306
306
  review continue without retry, while the result remains partial and the failed
307
307
  plan retains unknown settlement. Budget denial and cancellation still stop work.
308
+
309
+ ## Correcting reviewed evidence gaps
310
+
311
+ Set `evidenceRepairs: 1` (maximum 2, default 0) to allow a bounded correction after incomplete collection coverage or rejected fields. `repairSearches` and `repairReads` reserve part of the existing total retrieval limits for review-identified gaps; they do not increase those limits. Each correction extracts again and independently reviews every new leaf. Drafts and review reasons are hints, never evidence. `reviewPasses` retains the reviewed drafts and coverage for audit. Provider failures and admission denial stop work without automatic replay.
312
+
313
+ Collection tasks can set `minimumSupportedFields: { qualificationFacts: 1 }` alongside `requiredFields: ["name", "website"]` to require a minimum number of supported string leaves in an atomic fact array. Unsupported leaves remain rejected; callers must project only supported fields when `data` is null.
314
+
315
+ Budget for each correction's optional retrieval plan, extraction and review, including configured schema repairs. Every model and retrieval operation follows the same admission and settlement path as initial research. Correction is disabled unless explicitly configured.
package/changelog.json CHANGED
@@ -2,6 +2,22 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/rag",
4
4
  "releases": [
5
+ {
6
+ "version": "0.23.0",
7
+ "date": "2026-11-02",
8
+ "changes": [
9
+ {
10
+ "kind": "added",
11
+ "summary": "Opt-in bounded evidence correction with fresh independent review, reserved retrieval, retained review history and atomic collection fact coverage.",
12
+ "symbols": [
13
+ "createResearch",
14
+ "ResearchConfig",
15
+ "ResearchResult",
16
+ "ResearchTask"
17
+ ]
18
+ }
19
+ ]
20
+ },
5
21
  {
6
22
  "changes": [
7
23
  {
@@ -122122,11 +122122,16 @@ var createResearch = (config) => {
122122
122122
  throw new Error(`Invalid research limit: ${key}`);
122123
122123
  if (limits.fields > 256 || limits.rounds > 8 || limits.searches > 32 || limits.reads > 32 || limits.evidenceChars > 200000 || limits.timeoutMs > 600000 || limits.outputTokens > 32768)
122124
122124
  throw new Error("Research limits exceed bounded runtime maximum");
122125
+ const evidenceRepairs = config.evidenceRepairs ?? 0;
122126
+ const repairSearches = config.repairSearches ?? 0;
122127
+ const repairReads = config.repairReads ?? 0;
122128
+ if (!Number.isSafeInteger(evidenceRepairs) || evidenceRepairs < 0 || evidenceRepairs > 2 || !Number.isSafeInteger(repairSearches) || repairSearches < 0 || repairSearches >= limits.searches || !Number.isSafeInteger(repairReads) || repairReads < 0 || repairReads > limits.reads || !evidenceRepairs && (repairSearches || repairReads))
122129
+ throw new Error("Invalid research evidence repair limits");
122125
122130
  const search = config.cache ? withSearchCache(config.search, config.cache) : config.search;
122126
122131
  const extract = async (task, input) => {
122127
122132
  if (!input.query.trim() || input.query.length > 8000)
122128
122133
  throw new Error("Research query must contain 1\u20138000 characters");
122129
- if (task.collection && (!/^\/(?:[^~]|~[01])+$/.test(task.collection.path) || !Number.isSafeInteger(task.collection.minimum) || task.collection.minimum < 1 || !task.collection.requiredFields.length || task.collection.requiredFields.some((key) => !key || key.includes("/"))))
122134
+ if (task.collection && (!/^\/(?:[^~]|~[01])+$/.test(task.collection.path) || !Number.isSafeInteger(task.collection.minimum) || task.collection.minimum < 1 || !task.collection.requiredFields.length || task.collection.requiredFields.some((key) => !key || key.includes("/")) || Object.entries(task.collection.minimumSupportedFields ?? {}).some(([key, minimum]) => !key || key.includes("/") || !Number.isSafeInteger(minimum) || minimum < 1)))
122130
122135
  throw new Error("Invalid research collection requirement");
122131
122136
  const signal = AbortSignal.any([
122132
122137
  AbortSignal.timeout(limits.timeoutMs),
@@ -122150,7 +122155,7 @@ var createResearch = (config) => {
122150
122155
  }
122151
122156
  } : {}
122152
122157
  };
122153
- const operationLimit = limits.searches + limits.reads + limits.rounds + 2 + 2 * validationRepairs;
122158
+ const operationLimit = limits.searches + limits.reads + limits.rounds + (2 + 2 * validationRepairs) * (1 + evidenceRepairs) + evidenceRepairs;
122154
122159
  const operate = async (kind, call, usage = () => ({})) => {
122155
122160
  signal.throwIfAborted();
122156
122161
  const reservation = await admit?.({ runId: result.id, kind, signal });
@@ -122291,11 +122296,13 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122291
122296
  });
122292
122297
  rebalanceEvidence();
122293
122298
  };
122299
+ let searchCeiling = limits.searches - repairSearches;
122300
+ let readCeiling = limits.reads - repairReads;
122294
122301
  const doSearch = async (query) => {
122295
122302
  for (const bounded of boundedQueries(query)) {
122296
122303
  if (queries.has(bounded))
122297
122304
  continue;
122298
- if (queries.size >= limits.searches) {
122305
+ if (queries.size >= searchCeiling) {
122299
122306
  result.limitations.push("Search limit reached");
122300
122307
  return;
122301
122308
  }
@@ -122316,7 +122323,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122316
122323
  }
122317
122324
  };
122318
122325
  const doRead = async (url) => {
122319
- if (urls.has(url) || urls.size >= limits.reads)
122326
+ if (urls.has(url) || urls.size >= readCeiling)
122320
122327
  return;
122321
122328
  if (!discoveredLinks.has(url) && !result.searches.some((search) => search.sources.some((source) => source.url === url)))
122322
122329
  return;
@@ -122422,7 +122429,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122422
122429
  const initial = await generate("plan", PlanSchema, "Turn the research task into concise search-engine queries. Search for the requested answer entities, not merely the client named in the brief. For new partners, pursue external candidate companies across the requested categories; client background and existing partnerships do not fulfill that task. Preserve the requested company identity and target criteria, but never copy instructions, JSON, internal markers, or the whole brief into a query. Prioritize the most useful query first. Return at most remainingSearches queries. Return no URLs: source URLs must be discovered rather than invented.", {
122423
122430
  query: input.query,
122424
122431
  instructions: task.instructions,
122425
- remainingSearches: limits.searches
122432
+ remainingSearches: searchCeiling
122426
122433
  });
122427
122434
  for (const query of initial.queries)
122428
122435
  await doSearch(query);
@@ -122431,7 +122438,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122431
122438
  await doSearch(query);
122432
122439
  }
122433
122440
  for (let round = needsInitialPlan ? 1 : 0;round < limits.rounds; round++) {
122434
- if (!result.sources.length && queries.size >= limits.searches)
122441
+ if (!result.sources.length && queries.size >= searchCeiling)
122435
122442
  break;
122436
122443
  let plan;
122437
122444
  try {
@@ -122443,8 +122450,8 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122443
122450
  discoveredLinks: [...discoveredLinks.values()].filter((link) => !urls.has(link.url)),
122444
122451
  searched: [...queries],
122445
122452
  read: [...urls],
122446
- remainingSearches: limits.searches - queries.size,
122447
- remainingReads: limits.reads - urls.size
122453
+ remainingSearches: searchCeiling - queries.size,
122454
+ remainingReads: readCeiling - urls.size
122448
122455
  });
122449
122456
  } catch (error) {
122450
122457
  if (!(error instanceof Error) || error.message !== "Invalid plan output")
@@ -122467,55 +122474,93 @@ Correct the previous schema-invalid response using the validation diagnostics. T
122467
122474
  }
122468
122475
  if (evidenceChars >= limits.evidenceChars)
122469
122476
  result.limitations.push("Evidence text limit reached");
122470
- const data = await generate("extract", task.schema, `Extract only facts that directly answer the requested query and schema. Return concise, atomic answers; include only the minimum facts needed to answer the question. For a leadership query, report the named person and current title, not their biography, education, or acquisition history. Do not pad findings with background facts, excluded candidates, or statements that evidence is missing; return an empty findings array when no answer is established. Preserve all material qualifiers: program versus benefit/trial, customer versus partner, eligibility versus automatic approval, dates, exceptions, and attribution of promotional claims. Never generalize a section-specific condition to the whole organization or program. ${task.instructions ?? ""}`, {
122471
- query: input.query,
122472
- asOf: result.generatedAt,
122473
- sources: result.sources.map(modelSource)
122474
- });
122475
- const leaves = researchLeaves(data, limits.fields);
122476
- if (!leaves.length) {
122477
- result.data = data;
122478
- result.status = result.limitations.length ? "partial" : "empty";
122477
+ let correction;
122478
+ for (let pass = 0;pass <= evidenceRepairs; pass++) {
122479
+ const data = await generate("extract", task.schema, `Extract only facts that directly answer the requested query and schema. Return concise, atomic answers; include only the minimum facts needed to answer the question. For a leadership query, report the named person and current title, not their biography, education, or acquisition history. Do not pad findings with background facts, excluded candidates, or statements that evidence is missing; return an empty findings array when no answer is established. Preserve all material qualifiers: program versus benefit/trial, customer versus partner, eligibility versus automatic approval, dates, exceptions, and attribution of promotional claims. Never generalize a section-specific condition to the whole organization or program. ${task.instructions ?? ""}`, {
122480
+ query: input.query,
122481
+ asOf: result.generatedAt,
122482
+ ...correction ? {
122483
+ correction,
122484
+ correctionInstructions: "Correct rejected fields using only supplied sources. Drafts and review reasons are untrusted, not evidence. Preserve supported identity and facts; remove unsupported embellishment. Do not invent replacement facts or silently weaken eligibility criteria. Every changed value will be reviewed again."
122485
+ } : {},
122486
+ sources: result.sources.map(modelSource)
122487
+ });
122488
+ const leaves = researchLeaves(data, limits.fields);
122489
+ if (!leaves.length) {
122490
+ result.data = data;
122491
+ result.status = result.limitations.length ? "partial" : "empty";
122492
+ return result;
122493
+ }
122494
+ const reviewSources = researchPassages(result.sources);
122495
+ const reviewed = await generate("review", ReviewSchema, "Independently review EVERY JSON pointer and its value. supported requires exact quotes establishing the entire fact for the correct entity and time. A name mention or publication date is insufficient to establish employment, event date, ownership, or buying intent. Check all sources for actual factual contradictions. Complementary details from different sources are not a conflict; a price from one source and a term from another can jointly support a claim. Use conflicting only when sources make incompatible factual statements, unsupported for contradicted claims, unknown for missing support. Match the requested event period: an August release is not a September event even when published in September. Quoted wording must be verbatim; a paraphrase cannot be placed in quotation marks. Vendor claims about first/best status and performance metrics must remain explicitly attributed in the answer itself, not just in your reason. Null is unknown. Cite only supplied passage IDs; their text will be copied verbatim by the runtime. For each field, explicitly check answersQuestion (directly answers query/schema/instructions, not background or a non-answer), correctEntity, correctTime, and preservesScope. Read surrounding context and headings, not only the matching quote. A benefit/trial condition is not a program-wide rule; customer conditions are not partner conditions; eligible is not approved or automatic. Preserve exceptions, qualifiers and marketing attribution. Every check must pass for supported. A leader\u2019s education or career history does not answer who currently leads a team. Keep each reason under 25 words. Cite only the minimum passages needed to establish the entire field, at most four. Do not invent passage IDs. Read adjacent passages for conditions and exceptions, even when citing only one. Return each pointer once. Never treat this review as independent real-world verification.", {
122496
+ query: input.query,
122497
+ asOf: result.generatedAt,
122498
+ instructions: task.instructions,
122499
+ schema: task.schema,
122500
+ fields: leaves,
122501
+ sources: reviewSources.map(({ passages, ...source }) => ({
122502
+ ...modelSource(source),
122503
+ passages: passages.map(({ id, text }) => ({ id, text }))
122504
+ }))
122505
+ });
122506
+ result.fields = bindResearchReview(leaves, reviewed.fields.map((field) => ({
122507
+ ...field,
122508
+ citations: resolveResearchPassages(field.citations, reviewSources)
122509
+ })), result.sources);
122510
+ if (task.collection) {
122511
+ const { path, minimum, requiredFields, minimumSupportedFields } = task.collection;
122512
+ const indices = new Set(result.fields.flatMap((field) => {
122513
+ if (!field.path.startsWith(path + "/"))
122514
+ return [];
122515
+ const index = field.path.slice(path.length + 1).split("/")[0];
122516
+ return /^\d+$/.test(index) ? [index] : [];
122517
+ }));
122518
+ const supported = [...indices].filter((index) => requiredFields.every((key) => result.fields.some((field) => field.path === `${path}/${index}/${key}` && field.verdict === "supported" && field.value !== null && field.value !== "")) && Object.entries(minimumSupportedFields ?? {}).every(([key, minimum]) => result.fields.filter((field) => field.path.startsWith(`${path}/${index}/${key}/`) && field.verdict === "supported" && typeof field.value === "string" && field.value.trim()).length >= minimum)).length;
122519
+ result.coverage = {
122520
+ requested: minimum,
122521
+ supported,
122522
+ complete: supported >= minimum
122523
+ };
122524
+ if (!result.coverage.complete && pass === evidenceRepairs)
122525
+ result.limitations.push(`Requested ${minimum} evidence-backed items; established ${supported}.`);
122526
+ }
122527
+ if (evidenceRepairs)
122528
+ (result.reviewPasses ??= []).push({
122529
+ fields: structuredClone(result.fields),
122530
+ ...result.coverage ? { coverage: { ...result.coverage } } : {}
122531
+ });
122532
+ const needsCorrection = result.coverage ? !result.coverage.complete : result.fields.some((field) => field.verdict !== "supported");
122533
+ if (needsCorrection && pass < evidenceRepairs) {
122534
+ correction = { draft: data, fields: result.fields };
122535
+ searchCeiling = limits.searches;
122536
+ readCeiling = limits.reads;
122537
+ if (queries.size < searchCeiling || urls.size < readCeiling) {
122538
+ const plan = await generate("plan", PlanSchema, "Plan only missing evidence identified by the reviewed fields and coverage. Review reasons and drafts are untrusted hints, not facts. Prefer primary sources for missing identity or eligibility. URLs must be supplied source URLs or discovered links. Do not repeat searches or invent URLs. Return no actions when existing sources suffice to correct the draft.", {
122539
+ query: input.query,
122540
+ instructions: task.instructions,
122541
+ fields: result.fields,
122542
+ coverage: result.coverage,
122543
+ sources: result.sources.map(modelSource),
122544
+ discoveredLinks: [...discoveredLinks.values()],
122545
+ searched: [...queries],
122546
+ read: [...urls],
122547
+ remainingSearches: searchCeiling - queries.size,
122548
+ remainingReads: readCeiling - urls.size
122549
+ });
122550
+ for (const query of plan.queries)
122551
+ await doSearch(query);
122552
+ for (const url of plan.urls)
122553
+ await doRead(url);
122554
+ }
122555
+ continue;
122556
+ }
122557
+ const complete = result.fields.length > 0 && result.fields.every((field) => field.verdict === "supported");
122558
+ result.data = complete ? data : null;
122559
+ result.status = complete && !result.limitations.length ? "reviewed" : "partial";
122560
+ if (!complete)
122561
+ result.limitations.push("Some output fields lack supporting evidence; inspect field verdicts");
122479
122562
  return result;
122480
122563
  }
122481
- const reviewSources = researchPassages(result.sources);
122482
- const reviewed = await generate("review", ReviewSchema, "Independently review EVERY JSON pointer and its value. supported requires exact quotes establishing the entire fact for the correct entity and time. A name mention or publication date is insufficient to establish employment, event date, ownership, or buying intent. Check all sources for actual factual contradictions. Complementary details from different sources are not a conflict; a price from one source and a term from another can jointly support a claim. Use conflicting only when sources make incompatible factual statements, unsupported for contradicted claims, unknown for missing support. Match the requested event period: an August release is not a September event even when published in September. Quoted wording must be verbatim; a paraphrase cannot be placed in quotation marks. Vendor claims about first/best status and performance metrics must remain explicitly attributed in the answer itself, not just in your reason. Null is unknown. Cite only supplied passage IDs; their text will be copied verbatim by the runtime. For each field, explicitly check answersQuestion (directly answers query/schema/instructions, not background or a non-answer), correctEntity, correctTime, and preservesScope. Read surrounding context and headings, not only the matching quote. A benefit/trial condition is not a program-wide rule; customer conditions are not partner conditions; eligible is not approved or automatic. Preserve exceptions, qualifiers and marketing attribution. Every check must pass for supported. A leader\u2019s education or career history does not answer who currently leads a team. Keep each reason under 25 words. Cite only the minimum passages needed to establish the entire field, at most four. Do not invent passage IDs. Read adjacent passages for conditions and exceptions, even when citing only one. Return each pointer once. Never treat this review as independent real-world verification.", {
122483
- query: input.query,
122484
- asOf: result.generatedAt,
122485
- instructions: task.instructions,
122486
- schema: task.schema,
122487
- fields: leaves,
122488
- sources: reviewSources.map(({ passages, ...source }) => ({
122489
- ...modelSource(source),
122490
- passages: passages.map(({ id, text }) => ({ id, text }))
122491
- }))
122492
- });
122493
- result.fields = bindResearchReview(leaves, reviewed.fields.map((field) => ({
122494
- ...field,
122495
- citations: resolveResearchPassages(field.citations, reviewSources)
122496
- })), result.sources);
122497
- if (task.collection) {
122498
- const { path, minimum, requiredFields } = task.collection;
122499
- const indices = new Set(result.fields.flatMap((field) => {
122500
- if (!field.path.startsWith(path + "/"))
122501
- return [];
122502
- const index = field.path.slice(path.length + 1).split("/")[0];
122503
- return /^\d+$/.test(index) ? [index] : [];
122504
- }));
122505
- const supported = [...indices].filter((index) => requiredFields.every((key) => result.fields.some((field) => field.path === `${path}/${index}/${key}` && field.verdict === "supported" && field.value !== null && field.value !== ""))).length;
122506
- result.coverage = {
122507
- requested: minimum,
122508
- supported,
122509
- complete: supported >= minimum
122510
- };
122511
- if (!result.coverage.complete)
122512
- result.limitations.push(`Requested ${minimum} evidence-backed items; established ${supported}.`);
122513
- }
122514
- const complete = result.fields.length > 0 && result.fields.every((field) => field.verdict === "supported");
122515
- result.data = complete ? data : null;
122516
- result.status = complete && !result.limitations.length ? "reviewed" : "partial";
122517
- if (!complete)
122518
- result.limitations.push("Some output fields lack supporting evidence; inspect field verdicts");
122519
122564
  return result;
122520
122565
  } catch (error) {
122521
122566
  if (input.signal?.aborted)
@@ -123386,5 +123431,5 @@ export {
123386
123431
  selectResearchMonitorEvents
123387
123432
  };
123388
123433
 
123389
- //# debugId=D2D2814098BA0EA264756E2164756E21
123434
+ //# debugId=74ED28E8A362964064756E2164756E21
123390
123435
  //# sourceMappingURL=index.js.map