@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 +6 -0
- package/RESEARCH.md +8 -0
- package/changelog.json +16 -0
- package/dist/research/index.js +101 -56
- package/dist/research/index.js.map +3 -3
- package/dist/src/research/types.d.ts +15 -0
- package/dist/web-index/index.js +101 -56
- package/dist/web-index/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -45,6 +45,15 @@ export type ResearchResult<T = unknown> = {
|
|
|
45
45
|
supported: number;
|
|
46
46
|
complete: boolean;
|
|
47
47
|
};
|
|
48
|
+
/** Reviewed drafts, including rejected fields, retained for audit. */
|
|
49
|
+
reviewPasses?: Array<{
|
|
50
|
+
fields: ResearchField[];
|
|
51
|
+
coverage?: {
|
|
52
|
+
requested: number;
|
|
53
|
+
supported: number;
|
|
54
|
+
complete: boolean;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
48
57
|
id: string;
|
|
49
58
|
status: "reviewed" | "partial" | "empty" | "unavailable";
|
|
50
59
|
/** Only populated when every primitive field passed evidence review. */
|
|
@@ -68,6 +77,7 @@ export type ResearchTask<S extends ResearchSchema = ResearchSchema> = {
|
|
|
68
77
|
path: string;
|
|
69
78
|
minimum: number;
|
|
70
79
|
requiredFields: string[];
|
|
80
|
+
minimumSupportedFields?: Record<string, number>;
|
|
71
81
|
};
|
|
72
82
|
instructions?: string;
|
|
73
83
|
};
|
|
@@ -92,6 +102,11 @@ export type ResearchLimits = {
|
|
|
92
102
|
fields: number;
|
|
93
103
|
};
|
|
94
104
|
export type ResearchConfig = {
|
|
105
|
+
/** Bounded factual correction passes after review. Default 0, maximum 2. Every correction is extracted and independently reviewed again. */
|
|
106
|
+
evidenceRepairs?: number;
|
|
107
|
+
/** Capacity reserved within the existing limits for review-identified gaps. */
|
|
108
|
+
repairSearches?: number;
|
|
109
|
+
repairReads?: number;
|
|
95
110
|
/** Extra schema-validation attempts per extract/review, each separately admitted. Default 1; 0 disables repair. Provider/network failures are never retried. */
|
|
96
111
|
validationRepairs?: number;
|
|
97
112
|
/** Server-side diagnostics only. Errors are never serialized into public research results. */
|
package/dist/web-index/index.js
CHANGED
|
@@ -123405,11 +123405,16 @@ var createResearch = (config) => {
|
|
|
123405
123405
|
throw new Error(`Invalid research limit: ${key}`);
|
|
123406
123406
|
if (limits.fields > 256 || limits.rounds > 8 || limits.searches > 32 || limits.reads > 32 || limits.evidenceChars > 200000 || limits.timeoutMs > 600000 || limits.outputTokens > 32768)
|
|
123407
123407
|
throw new Error("Research limits exceed bounded runtime maximum");
|
|
123408
|
+
const evidenceRepairs = config.evidenceRepairs ?? 0;
|
|
123409
|
+
const repairSearches = config.repairSearches ?? 0;
|
|
123410
|
+
const repairReads = config.repairReads ?? 0;
|
|
123411
|
+
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))
|
|
123412
|
+
throw new Error("Invalid research evidence repair limits");
|
|
123408
123413
|
const search = config.cache ? withSearchCache(config.search, config.cache) : config.search;
|
|
123409
123414
|
const extract = async (task, input) => {
|
|
123410
123415
|
if (!input.query.trim() || input.query.length > 8000)
|
|
123411
123416
|
throw new Error("Research query must contain 1\u20138000 characters");
|
|
123412
|
-
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("/"))))
|
|
123417
|
+
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)))
|
|
123413
123418
|
throw new Error("Invalid research collection requirement");
|
|
123414
123419
|
const signal = AbortSignal.any([
|
|
123415
123420
|
AbortSignal.timeout(limits.timeoutMs),
|
|
@@ -123433,7 +123438,7 @@ var createResearch = (config) => {
|
|
|
123433
123438
|
}
|
|
123434
123439
|
} : {}
|
|
123435
123440
|
};
|
|
123436
|
-
const operationLimit = limits.searches + limits.reads + limits.rounds + 2 + 2 * validationRepairs;
|
|
123441
|
+
const operationLimit = limits.searches + limits.reads + limits.rounds + (2 + 2 * validationRepairs) * (1 + evidenceRepairs) + evidenceRepairs;
|
|
123437
123442
|
const operate = async (kind, call, usage = () => ({})) => {
|
|
123438
123443
|
signal.throwIfAborted();
|
|
123439
123444
|
const reservation = await admit?.({ runId: result.id, kind, signal });
|
|
@@ -123574,11 +123579,13 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123574
123579
|
});
|
|
123575
123580
|
rebalanceEvidence();
|
|
123576
123581
|
};
|
|
123582
|
+
let searchCeiling = limits.searches - repairSearches;
|
|
123583
|
+
let readCeiling = limits.reads - repairReads;
|
|
123577
123584
|
const doSearch = async (query) => {
|
|
123578
123585
|
for (const bounded of boundedQueries(query)) {
|
|
123579
123586
|
if (queries.has(bounded))
|
|
123580
123587
|
continue;
|
|
123581
|
-
if (queries.size >=
|
|
123588
|
+
if (queries.size >= searchCeiling) {
|
|
123582
123589
|
result.limitations.push("Search limit reached");
|
|
123583
123590
|
return;
|
|
123584
123591
|
}
|
|
@@ -123599,7 +123606,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123599
123606
|
}
|
|
123600
123607
|
};
|
|
123601
123608
|
const doRead = async (url) => {
|
|
123602
|
-
if (urls.has(url) || urls.size >=
|
|
123609
|
+
if (urls.has(url) || urls.size >= readCeiling)
|
|
123603
123610
|
return;
|
|
123604
123611
|
if (!discoveredLinks.has(url) && !result.searches.some((search) => search.sources.some((source) => source.url === url)))
|
|
123605
123612
|
return;
|
|
@@ -123705,7 +123712,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123705
123712
|
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.", {
|
|
123706
123713
|
query: input.query,
|
|
123707
123714
|
instructions: task.instructions,
|
|
123708
|
-
remainingSearches:
|
|
123715
|
+
remainingSearches: searchCeiling
|
|
123709
123716
|
});
|
|
123710
123717
|
for (const query of initial.queries)
|
|
123711
123718
|
await doSearch(query);
|
|
@@ -123714,7 +123721,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123714
123721
|
await doSearch(query);
|
|
123715
123722
|
}
|
|
123716
123723
|
for (let round = needsInitialPlan ? 1 : 0;round < limits.rounds; round++) {
|
|
123717
|
-
if (!result.sources.length && queries.size >=
|
|
123724
|
+
if (!result.sources.length && queries.size >= searchCeiling)
|
|
123718
123725
|
break;
|
|
123719
123726
|
let plan;
|
|
123720
123727
|
try {
|
|
@@ -123726,8 +123733,8 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123726
123733
|
discoveredLinks: [...discoveredLinks.values()].filter((link) => !urls.has(link.url)),
|
|
123727
123734
|
searched: [...queries],
|
|
123728
123735
|
read: [...urls],
|
|
123729
|
-
remainingSearches:
|
|
123730
|
-
remainingReads:
|
|
123736
|
+
remainingSearches: searchCeiling - queries.size,
|
|
123737
|
+
remainingReads: readCeiling - urls.size
|
|
123731
123738
|
});
|
|
123732
123739
|
} catch (error) {
|
|
123733
123740
|
if (!(error instanceof Error) || error.message !== "Invalid plan output")
|
|
@@ -123750,55 +123757,93 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123750
123757
|
}
|
|
123751
123758
|
if (evidenceChars >= limits.evidenceChars)
|
|
123752
123759
|
result.limitations.push("Evidence text limit reached");
|
|
123753
|
-
|
|
123754
|
-
|
|
123755
|
-
|
|
123756
|
-
|
|
123757
|
-
|
|
123758
|
-
|
|
123759
|
-
|
|
123760
|
-
|
|
123761
|
-
|
|
123760
|
+
let correction;
|
|
123761
|
+
for (let pass = 0;pass <= evidenceRepairs; pass++) {
|
|
123762
|
+
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 ?? ""}`, {
|
|
123763
|
+
query: input.query,
|
|
123764
|
+
asOf: result.generatedAt,
|
|
123765
|
+
...correction ? {
|
|
123766
|
+
correction,
|
|
123767
|
+
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."
|
|
123768
|
+
} : {},
|
|
123769
|
+
sources: result.sources.map(modelSource)
|
|
123770
|
+
});
|
|
123771
|
+
const leaves = researchLeaves(data, limits.fields);
|
|
123772
|
+
if (!leaves.length) {
|
|
123773
|
+
result.data = data;
|
|
123774
|
+
result.status = result.limitations.length ? "partial" : "empty";
|
|
123775
|
+
return result;
|
|
123776
|
+
}
|
|
123777
|
+
const reviewSources = researchPassages(result.sources);
|
|
123778
|
+
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.", {
|
|
123779
|
+
query: input.query,
|
|
123780
|
+
asOf: result.generatedAt,
|
|
123781
|
+
instructions: task.instructions,
|
|
123782
|
+
schema: task.schema,
|
|
123783
|
+
fields: leaves,
|
|
123784
|
+
sources: reviewSources.map(({ passages, ...source }) => ({
|
|
123785
|
+
...modelSource(source),
|
|
123786
|
+
passages: passages.map(({ id, text }) => ({ id, text }))
|
|
123787
|
+
}))
|
|
123788
|
+
});
|
|
123789
|
+
result.fields = bindResearchReview(leaves, reviewed.fields.map((field) => ({
|
|
123790
|
+
...field,
|
|
123791
|
+
citations: resolveResearchPassages(field.citations, reviewSources)
|
|
123792
|
+
})), result.sources);
|
|
123793
|
+
if (task.collection) {
|
|
123794
|
+
const { path, minimum, requiredFields, minimumSupportedFields } = task.collection;
|
|
123795
|
+
const indices = new Set(result.fields.flatMap((field) => {
|
|
123796
|
+
if (!field.path.startsWith(path + "/"))
|
|
123797
|
+
return [];
|
|
123798
|
+
const index = field.path.slice(path.length + 1).split("/")[0];
|
|
123799
|
+
return /^\d+$/.test(index) ? [index] : [];
|
|
123800
|
+
}));
|
|
123801
|
+
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;
|
|
123802
|
+
result.coverage = {
|
|
123803
|
+
requested: minimum,
|
|
123804
|
+
supported,
|
|
123805
|
+
complete: supported >= minimum
|
|
123806
|
+
};
|
|
123807
|
+
if (!result.coverage.complete && pass === evidenceRepairs)
|
|
123808
|
+
result.limitations.push(`Requested ${minimum} evidence-backed items; established ${supported}.`);
|
|
123809
|
+
}
|
|
123810
|
+
if (evidenceRepairs)
|
|
123811
|
+
(result.reviewPasses ??= []).push({
|
|
123812
|
+
fields: structuredClone(result.fields),
|
|
123813
|
+
...result.coverage ? { coverage: { ...result.coverage } } : {}
|
|
123814
|
+
});
|
|
123815
|
+
const needsCorrection = result.coverage ? !result.coverage.complete : result.fields.some((field) => field.verdict !== "supported");
|
|
123816
|
+
if (needsCorrection && pass < evidenceRepairs) {
|
|
123817
|
+
correction = { draft: data, fields: result.fields };
|
|
123818
|
+
searchCeiling = limits.searches;
|
|
123819
|
+
readCeiling = limits.reads;
|
|
123820
|
+
if (queries.size < searchCeiling || urls.size < readCeiling) {
|
|
123821
|
+
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.", {
|
|
123822
|
+
query: input.query,
|
|
123823
|
+
instructions: task.instructions,
|
|
123824
|
+
fields: result.fields,
|
|
123825
|
+
coverage: result.coverage,
|
|
123826
|
+
sources: result.sources.map(modelSource),
|
|
123827
|
+
discoveredLinks: [...discoveredLinks.values()],
|
|
123828
|
+
searched: [...queries],
|
|
123829
|
+
read: [...urls],
|
|
123830
|
+
remainingSearches: searchCeiling - queries.size,
|
|
123831
|
+
remainingReads: readCeiling - urls.size
|
|
123832
|
+
});
|
|
123833
|
+
for (const query of plan.queries)
|
|
123834
|
+
await doSearch(query);
|
|
123835
|
+
for (const url of plan.urls)
|
|
123836
|
+
await doRead(url);
|
|
123837
|
+
}
|
|
123838
|
+
continue;
|
|
123839
|
+
}
|
|
123840
|
+
const complete = result.fields.length > 0 && result.fields.every((field) => field.verdict === "supported");
|
|
123841
|
+
result.data = complete ? data : null;
|
|
123842
|
+
result.status = complete && !result.limitations.length ? "reviewed" : "partial";
|
|
123843
|
+
if (!complete)
|
|
123844
|
+
result.limitations.push("Some output fields lack supporting evidence; inspect field verdicts");
|
|
123762
123845
|
return result;
|
|
123763
123846
|
}
|
|
123764
|
-
const reviewSources = researchPassages(result.sources);
|
|
123765
|
-
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.", {
|
|
123766
|
-
query: input.query,
|
|
123767
|
-
asOf: result.generatedAt,
|
|
123768
|
-
instructions: task.instructions,
|
|
123769
|
-
schema: task.schema,
|
|
123770
|
-
fields: leaves,
|
|
123771
|
-
sources: reviewSources.map(({ passages, ...source }) => ({
|
|
123772
|
-
...modelSource(source),
|
|
123773
|
-
passages: passages.map(({ id, text }) => ({ id, text }))
|
|
123774
|
-
}))
|
|
123775
|
-
});
|
|
123776
|
-
result.fields = bindResearchReview(leaves, reviewed.fields.map((field) => ({
|
|
123777
|
-
...field,
|
|
123778
|
-
citations: resolveResearchPassages(field.citations, reviewSources)
|
|
123779
|
-
})), result.sources);
|
|
123780
|
-
if (task.collection) {
|
|
123781
|
-
const { path, minimum, requiredFields } = task.collection;
|
|
123782
|
-
const indices = new Set(result.fields.flatMap((field) => {
|
|
123783
|
-
if (!field.path.startsWith(path + "/"))
|
|
123784
|
-
return [];
|
|
123785
|
-
const index = field.path.slice(path.length + 1).split("/")[0];
|
|
123786
|
-
return /^\d+$/.test(index) ? [index] : [];
|
|
123787
|
-
}));
|
|
123788
|
-
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;
|
|
123789
|
-
result.coverage = {
|
|
123790
|
-
requested: minimum,
|
|
123791
|
-
supported,
|
|
123792
|
-
complete: supported >= minimum
|
|
123793
|
-
};
|
|
123794
|
-
if (!result.coverage.complete)
|
|
123795
|
-
result.limitations.push(`Requested ${minimum} evidence-backed items; established ${supported}.`);
|
|
123796
|
-
}
|
|
123797
|
-
const complete = result.fields.length > 0 && result.fields.every((field) => field.verdict === "supported");
|
|
123798
|
-
result.data = complete ? data : null;
|
|
123799
|
-
result.status = complete && !result.limitations.length ? "reviewed" : "partial";
|
|
123800
|
-
if (!complete)
|
|
123801
|
-
result.limitations.push("Some output fields lack supporting evidence; inspect field verdicts");
|
|
123802
123847
|
return result;
|
|
123803
123848
|
} catch (error) {
|
|
123804
123849
|
if (input.signal?.aborted)
|
|
@@ -123925,5 +123970,5 @@ export {
|
|
|
123925
123970
|
webIndexPostgresSchemaSql
|
|
123926
123971
|
};
|
|
123927
123972
|
|
|
123928
|
-
//# debugId=
|
|
123973
|
+
//# debugId=3F886F7566F912EF64756E2164756E21
|
|
123929
123974
|
//# sourceMappingURL=index.js.map
|