@absolutejs/rag 0.22.8 → 0.22.10
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 +12 -0
- package/changelog.json +31 -0
- package/dist/research/index.js +47 -15
- package/dist/research/index.js.map +8 -7
- package/dist/src/research/sourceExcerpts.d.ts +3 -0
- package/dist/src/research/types.d.ts +7 -0
- package/dist/src/web/index.d.ts +3 -0
- package/dist/src/web/website.d.ts +6 -0
- package/dist/web/index.js +19 -10
- package/dist/web/index.js.map +5 -5
- package/dist/web-index/index.js +47 -15
- package/dist/web-index/index.js.map +8 -7
- package/package.json +1 -1
package/dist/web-index/index.js
CHANGED
|
@@ -112384,6 +112384,28 @@ var startWebIndexWorker = (options) => {
|
|
|
112384
112384
|
// src/web-index/projector.ts
|
|
112385
112385
|
import { t as t2 } from "elysia";
|
|
112386
112386
|
|
|
112387
|
+
// src/research/sourceExcerpts.ts
|
|
112388
|
+
import { createAITextSource } from "@absolutejs/ai";
|
|
112389
|
+
var selectResearchExcerpts = (text, budget, query) => {
|
|
112390
|
+
if (budget <= 0)
|
|
112391
|
+
return [];
|
|
112392
|
+
if (text.length <= budget)
|
|
112393
|
+
return [text];
|
|
112394
|
+
const source = createAITextSource([{ role: "user", content: text }]);
|
|
112395
|
+
const hits = source.search(query);
|
|
112396
|
+
const passages = hits.length ? hits : source.search("");
|
|
112397
|
+
let remaining = budget;
|
|
112398
|
+
const selected = [];
|
|
112399
|
+
for (const passage of passages) {
|
|
112400
|
+
if (!remaining)
|
|
112401
|
+
break;
|
|
112402
|
+
const excerpt = passage.text.slice(0, remaining);
|
|
112403
|
+
selected.push({ start: passage.start, text: excerpt });
|
|
112404
|
+
remaining -= excerpt.length;
|
|
112405
|
+
}
|
|
112406
|
+
return selected.sort((a, b) => a.start - b.start).map((passage) => passage.text);
|
|
112407
|
+
};
|
|
112408
|
+
|
|
112387
112409
|
// src/research/budget.ts
|
|
112388
112410
|
var createResearchBudgetAdmission = (config) => {
|
|
112389
112411
|
if (!config.scope.trim())
|
|
@@ -122125,7 +122147,7 @@ var readRAGWebsite = async (options) => {
|
|
|
122125
122147
|
const page = await readRAGWebpage({
|
|
122126
122148
|
...options,
|
|
122127
122149
|
url: next.url,
|
|
122128
|
-
maxChars
|
|
122150
|
+
maxChars,
|
|
122129
122151
|
signal: AbortSignal.any([signal, AbortSignal.timeout(30000)])
|
|
122130
122152
|
});
|
|
122131
122153
|
pages.push(page);
|
|
@@ -122181,24 +122203,27 @@ var readRAGWebsite = async (options) => {
|
|
|
122181
122203
|
let remainingDocumentChars = maxChars;
|
|
122182
122204
|
const documents = sources.flatMap((source) => {
|
|
122183
122205
|
const page = pages.find((item) => item.finalUrl === source.url && item.text);
|
|
122184
|
-
if (!page
|
|
122206
|
+
if (!page)
|
|
122185
122207
|
return [];
|
|
122186
122208
|
const imageLabels = page.evidence.images.filter((image) => image.label).map((image) => `${image.context ? `${image.context}: ` : ""}${image.label}`);
|
|
122187
122209
|
const fullText = [
|
|
122188
|
-
page.text,
|
|
122210
|
+
page.fullText ?? page.text,
|
|
122189
122211
|
...imageLabels.length ? [
|
|
122190
122212
|
"Image labels supplied by the website (not independently verified customer relationships):",
|
|
122191
122213
|
...imageLabels
|
|
122192
122214
|
] : []
|
|
122193
122215
|
].join(`
|
|
122194
122216
|
`);
|
|
122195
|
-
const text = fullText.slice(0, remainingDocumentChars);
|
|
122217
|
+
const text = fullText.slice(0, Math.max(0, remainingDocumentChars));
|
|
122196
122218
|
remainingDocumentChars -= text.length;
|
|
122197
122219
|
return [
|
|
122198
122220
|
{
|
|
122199
122221
|
sourceId: source.id,
|
|
122200
122222
|
text,
|
|
122201
|
-
|
|
122223
|
+
fullText,
|
|
122224
|
+
originalChars: fullText.length,
|
|
122225
|
+
sourceTruncated: page.status !== "ok" || page.fullText === undefined && page.truncated,
|
|
122226
|
+
truncated: page.fullText === undefined && page.truncated || text.length < fullText.length
|
|
122202
122227
|
}
|
|
122203
122228
|
];
|
|
122204
122229
|
});
|
|
@@ -122217,10 +122242,11 @@ ${page.text}`).join(`
|
|
|
122217
122242
|
sources,
|
|
122218
122243
|
citationRequirements: "The final answer must contain clickable Markdown source links, not just source names or bare domain mentions. Reuse sources[].citation beside the factual paragraph, list or table row it supports. Cite the actual supporting page, not the homepage for everything. Every factual section needs its supporting links. Do not invent sources or use unread links as evidence. Before responding, check that company facts, service descriptions, customer examples and numerical claims have supporting links; retrieve or omit unsupported claims. A list of large customers does not prove smaller customers are excluded. Preserve the brands actually named in the evidence; do not append parent companies, ownership relationships, current-account status, market rankings or rebrand history from memory. Label reasoned inferences as such. A verified brand change needs at most one short, cited sentence unless the user asks for its history.",
|
|
122219
122244
|
...first,
|
|
122245
|
+
fullText: undefined,
|
|
122220
122246
|
status: readable.length ? incomplete ? "partial" : "ok" : "error",
|
|
122221
122247
|
text: evidenceText.slice(0, maxChars),
|
|
122222
122248
|
truncated: evidenceText.length > maxChars || pages.some((page) => page.truncated),
|
|
122223
|
-
pages: pages.map(({ text: _text, ...page }) => page),
|
|
122249
|
+
pages: pages.map(({ text: _text, fullText: _fullText, ...page }) => page),
|
|
122224
122250
|
captionEvidence,
|
|
122225
122251
|
coverage: {
|
|
122226
122252
|
pagesRead: pages.length,
|
|
@@ -122231,10 +122257,10 @@ ${page.text}`).join(`
|
|
|
122231
122257
|
deadlineReached: signal.aborted,
|
|
122232
122258
|
exhaustive: false,
|
|
122233
122259
|
stopReason: signal.aborted ? "deadline" : unvisited.length ? "page_limit" : "links_exhausted",
|
|
122234
|
-
incompleteReads: pages.filter((page) => page.status !== "ok" || page.truncated).map((page) => ({
|
|
122260
|
+
incompleteReads: pages.filter((page) => page.status !== "ok" || page.fullText === undefined && page.truncated).map((page) => ({
|
|
122235
122261
|
url: page.finalUrl,
|
|
122236
122262
|
status: page.status,
|
|
122237
|
-
truncated: page.truncated,
|
|
122263
|
+
truncated: page.fullText === undefined && page.truncated,
|
|
122238
122264
|
error: page.error
|
|
122239
122265
|
}))
|
|
122240
122266
|
},
|
|
@@ -122349,12 +122375,15 @@ var createWebpageReaderClient = (options) => {
|
|
|
122349
122375
|
if (![evidence.links, evidence.images, evidence.media].every(Array.isArray))
|
|
122350
122376
|
throw new Error("Invalid page evidence");
|
|
122351
122377
|
const limit = Math.max(1000, Math.min(input.maxChars ?? 24000, 1e5));
|
|
122378
|
+
const fullText = typeof document2.fullText === "string" ? document2.fullText : document2.text;
|
|
122352
122379
|
return {
|
|
122353
122380
|
status: result.status,
|
|
122354
122381
|
url: input.url,
|
|
122355
122382
|
finalUrl: result.finalUrl,
|
|
122356
122383
|
title: typeof result.title === "string" ? result.title : null,
|
|
122357
|
-
text:
|
|
122384
|
+
text: fullText.slice(0, limit),
|
|
122385
|
+
fullText,
|
|
122386
|
+
originalChars: fullText.length,
|
|
122358
122387
|
method: result.method,
|
|
122359
122388
|
truncated: result.truncated === true || document2.truncated === true || document2.text.length > limit,
|
|
122360
122389
|
fetchedAt: result.fetchedAt,
|
|
@@ -122397,6 +122426,8 @@ var readRAGWebpage = async (options) => {
|
|
|
122397
122426
|
finalUrl,
|
|
122398
122427
|
title,
|
|
122399
122428
|
text: text.slice(0, maxChars),
|
|
122429
|
+
fullText: text,
|
|
122430
|
+
originalChars: text.length,
|
|
122400
122431
|
method,
|
|
122401
122432
|
truncated: text.length > maxChars,
|
|
122402
122433
|
attempts,
|
|
@@ -122748,8 +122779,8 @@ ${prompt}`,
|
|
|
122748
122779
|
const text = sourceText.get(source.url);
|
|
122749
122780
|
const allowance = Math.floor(remaining * weight(source) / remainingWeight);
|
|
122750
122781
|
remainingWeight -= weight(source);
|
|
122751
|
-
source.excerpts = [
|
|
122752
|
-
remaining -= source.excerpts
|
|
122782
|
+
source.excerpts = selectResearchExcerpts(text, allowance, [input.query, ...input.queries ?? []].join(" "));
|
|
122783
|
+
remaining -= source.excerpts.reduce((sum, excerpt) => sum + excerpt.length, 0);
|
|
122753
122784
|
}
|
|
122754
122785
|
evidenceChars = limits.evidenceChars - remaining;
|
|
122755
122786
|
};
|
|
@@ -122770,7 +122801,7 @@ ${prompt}`,
|
|
|
122770
122801
|
return;
|
|
122771
122802
|
}
|
|
122772
122803
|
const text = source.excerpts.join(`
|
|
122773
|
-
`)
|
|
122804
|
+
`);
|
|
122774
122805
|
if (!text.trim())
|
|
122775
122806
|
return;
|
|
122776
122807
|
sourceText.set(source.url, text);
|
|
@@ -122833,7 +122864,7 @@ ${prompt}`,
|
|
|
122833
122864
|
}
|
|
122834
122865
|
const prior = result.sources.find((source) => source.url === url);
|
|
122835
122866
|
if (prior) {
|
|
122836
|
-
sourceText.set(prior.url, page.
|
|
122867
|
+
sourceText.set(prior.url, page.fullText ?? page.text);
|
|
122837
122868
|
prior.contentFetchedAt = page.fetchedAt;
|
|
122838
122869
|
prior.metadata = { ...prior.metadata, readFinalUrl: page.finalUrl };
|
|
122839
122870
|
if (page.finalUrl !== prior.url)
|
|
@@ -122844,7 +122875,7 @@ ${prompt}`,
|
|
|
122844
122875
|
id: "",
|
|
122845
122876
|
url: page.finalUrl,
|
|
122846
122877
|
title: page.title ?? url,
|
|
122847
|
-
excerpts: [page.text],
|
|
122878
|
+
excerpts: [page.fullText ?? page.text],
|
|
122848
122879
|
retrievedAt: page.fetchedAt,
|
|
122849
122880
|
contentFetchedAt: page.fetchedAt
|
|
122850
122881
|
});
|
|
@@ -122946,6 +122977,7 @@ ${prompt}`,
|
|
|
122946
122977
|
result.status = result.sources.length ? "partial" : "unavailable";
|
|
122947
122978
|
return result;
|
|
122948
122979
|
} finally {
|
|
122980
|
+
result.documents = result.sources.filter((source) => source.contentFetchedAt).map((source) => ({ sourceId: source.id, url: source.url, text: sourceText.get(source.url) ?? "", originalChars: (sourceText.get(source.url) ?? "").length }));
|
|
122949
122981
|
result.limitations = [...new Set(result.limitations)];
|
|
122950
122982
|
input.onProgress?.({
|
|
122951
122983
|
phase: "complete",
|
|
@@ -123050,5 +123082,5 @@ export {
|
|
|
123050
123082
|
webIndexPostgresSchemaSql
|
|
123051
123083
|
};
|
|
123052
123084
|
|
|
123053
|
-
//# debugId=
|
|
123085
|
+
//# debugId=6158AC15C0E8567F64756E2164756E21
|
|
123054
123086
|
//# sourceMappingURL=index.js.map
|