@absolutejs/absolute 0.19.0-beta.607 → 0.19.0-beta.608
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/dist/ai/client/index.js +136 -18
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +137 -18
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +365 -28
- package/dist/ai/index.js.map +7 -7
- package/dist/ai/rag/quality.js +86 -16
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +137 -18
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +135 -17
- package/dist/ai-client/react/ai/index.js +135 -17
- package/dist/ai-client/vue/ai/index.js +135 -17
- package/dist/angular/ai/index.js +136 -18
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +136 -18
- package/dist/react/ai/index.js.map +6 -6
- package/dist/src/ai/client/ui.d.ts +1 -1
- package/dist/src/ai/rag/index.d.ts +1 -1
- package/dist/src/ai/rag/presentation.d.ts +4 -1
- package/dist/src/ai/rag/ui.d.ts +1 -1
- package/dist/src/vue/ai/useRAG.d.ts +14 -4
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +12 -2
- package/dist/src/vue/ai/useRAGSearch.d.ts +2 -2
- package/dist/svelte/ai/index.js +136 -18
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +13 -2
- package/dist/vue/ai/index.js +136 -18
- package/dist/vue/ai/index.js.map +5 -5
- package/package.json +1 -1
package/dist/ai/client/index.js
CHANGED
|
@@ -347,6 +347,56 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
347
347
|
}
|
|
348
348
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
349
349
|
};
|
|
350
|
+
var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
|
|
351
|
+
if (!excerpts) {
|
|
352
|
+
return "";
|
|
353
|
+
}
|
|
354
|
+
const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
|
|
355
|
+
const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
|
|
356
|
+
const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
|
|
357
|
+
if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
|
|
358
|
+
if (sectionChunkCount <= 3 && sectionExcerpt) {
|
|
359
|
+
return sectionExcerpt;
|
|
360
|
+
}
|
|
361
|
+
if (windowExcerpt) {
|
|
362
|
+
return windowExcerpt;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return chunkExcerpt || windowExcerpt || sectionExcerpt;
|
|
366
|
+
};
|
|
367
|
+
var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
|
|
368
|
+
if (sources.length === 0) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
|
|
372
|
+
if (!activeSource) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
|
|
376
|
+
const activeMetadata = activeSource.metadata ?? {};
|
|
377
|
+
const previousChunkId = getContextString(activeMetadata.previousChunkId);
|
|
378
|
+
const nextChunkId = getContextString(activeMetadata.nextChunkId);
|
|
379
|
+
const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
|
|
380
|
+
const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
|
|
381
|
+
const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
382
|
+
const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
383
|
+
if (leftIndex !== rightIndex) {
|
|
384
|
+
return leftIndex - rightIndex;
|
|
385
|
+
}
|
|
386
|
+
return left.chunkId.localeCompare(right.chunkId);
|
|
387
|
+
}) : [activeSource];
|
|
388
|
+
const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
|
|
389
|
+
|
|
390
|
+
`);
|
|
391
|
+
const orderedWindowIds = [previousChunkId, activeSource.chunkId, nextChunkId].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
|
|
392
|
+
return {
|
|
393
|
+
chunkExcerpt: buildExcerpt(activeSource.text, 160),
|
|
394
|
+
sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
|
|
395
|
+
|
|
396
|
+
`), 320),
|
|
397
|
+
windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
|
|
398
|
+
};
|
|
399
|
+
};
|
|
350
400
|
var buildGroundingReferenceEvidenceLabel = (reference) => [reference.label, reference.locatorLabel, reference.contextLabel].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
351
401
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
352
402
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
@@ -365,7 +415,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
|
365
415
|
contextLabel: reference.contextLabel,
|
|
366
416
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
367
417
|
evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
|
|
368
|
-
excerpt: reference.excerpt,
|
|
418
|
+
excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
|
|
419
|
+
excerpts: reference.excerpts,
|
|
369
420
|
label: reference.label,
|
|
370
421
|
locatorLabel: reference.locatorLabel,
|
|
371
422
|
number: reference.number,
|
|
@@ -461,10 +512,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
461
512
|
const key = buildGroundingSectionKey(reference);
|
|
462
513
|
const existing = groups.get(key);
|
|
463
514
|
if (!existing) {
|
|
515
|
+
const excerpts = reference.excerpts ? {
|
|
516
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
517
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
518
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
519
|
+
} : undefined;
|
|
464
520
|
groups.set(key, {
|
|
465
521
|
chunkIds: [reference.chunkId],
|
|
466
522
|
contextLabel: reference.contextLabel,
|
|
467
523
|
count: 1,
|
|
524
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
|
|
525
|
+
excerpts,
|
|
468
526
|
key,
|
|
469
527
|
label: key,
|
|
470
528
|
locatorLabel: reference.locatorLabel,
|
|
@@ -492,6 +550,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
492
550
|
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
493
551
|
existing.provenanceLabel = reference.provenanceLabel;
|
|
494
552
|
}
|
|
553
|
+
if (!existing.excerpts && reference.excerpts) {
|
|
554
|
+
existing.excerpts = {
|
|
555
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
556
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
557
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
558
|
+
};
|
|
559
|
+
existing.excerpt = reference.excerpts.sectionExcerpt;
|
|
560
|
+
}
|
|
495
561
|
}
|
|
496
562
|
return [...groups.values()].map((group) => ({
|
|
497
563
|
...group,
|
|
@@ -509,20 +575,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
509
575
|
var buildRAGGroundingReferences = (sources) => {
|
|
510
576
|
const citations = buildRAGCitations(sources);
|
|
511
577
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
512
|
-
return citations.map((citation) =>
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
578
|
+
return citations.map((citation) => {
|
|
579
|
+
const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
|
|
580
|
+
return {
|
|
581
|
+
chunkId: citation.chunkId,
|
|
582
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
583
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
|
|
584
|
+
excerpts,
|
|
585
|
+
label: citation.label,
|
|
586
|
+
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
587
|
+
metadata: citation.metadata,
|
|
588
|
+
number: citationReferenceMap[citation.chunkId] ?? 0,
|
|
589
|
+
provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
|
|
590
|
+
score: citation.score,
|
|
591
|
+
source: citation.source,
|
|
592
|
+
text: citation.text,
|
|
593
|
+
title: citation.title
|
|
594
|
+
};
|
|
595
|
+
});
|
|
526
596
|
};
|
|
527
597
|
|
|
528
598
|
// src/ai/rag/quality.ts
|
|
@@ -4779,7 +4849,7 @@ var buildRAGChunkStructure = (metadata) => {
|
|
|
4779
4849
|
return;
|
|
4780
4850
|
}
|
|
4781
4851
|
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
|
|
4782
|
-
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
|
|
4852
|
+
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" || metadata.sectionKind === "office_heading" || metadata.sectionKind === "spreadsheet_rows" || metadata.sectionKind === "presentation_slide" ? metadata.sectionKind : undefined;
|
|
4783
4853
|
const section = {
|
|
4784
4854
|
depth: getContextNumber2(metadata.sectionDepth),
|
|
4785
4855
|
kind: sectionKind,
|
|
@@ -4808,6 +4878,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
|
|
|
4808
4878
|
}
|
|
4809
4879
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
4810
4880
|
};
|
|
4881
|
+
var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
|
|
4882
|
+
if (chunks.length === 0) {
|
|
4883
|
+
return;
|
|
4884
|
+
}
|
|
4885
|
+
const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
|
|
4886
|
+
chunkId: chunk.chunkId,
|
|
4887
|
+
metadata: chunk.metadata,
|
|
4888
|
+
structure: chunk.structure
|
|
4889
|
+
})));
|
|
4890
|
+
const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
|
|
4891
|
+
const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
|
|
4892
|
+
if (!activeChunk) {
|
|
4893
|
+
return;
|
|
4894
|
+
}
|
|
4895
|
+
const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
|
|
4896
|
+
const orderedWindowIds = [
|
|
4897
|
+
navigation.previousNode?.chunkId,
|
|
4898
|
+
activeChunk.chunkId,
|
|
4899
|
+
navigation.nextNode?.chunkId
|
|
4900
|
+
].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
|
|
4901
|
+
const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
|
|
4902
|
+
const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
|
|
4903
|
+
|
|
4904
|
+
`);
|
|
4905
|
+
return {
|
|
4906
|
+
chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
|
|
4907
|
+
sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
|
|
4908
|
+
windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
|
|
4909
|
+
};
|
|
4910
|
+
};
|
|
4911
|
+
var buildRAGPreferredExcerpt = (excerpts, structure) => {
|
|
4912
|
+
if (!excerpts) {
|
|
4913
|
+
return "";
|
|
4914
|
+
}
|
|
4915
|
+
const chunkLength = excerpts.chunkExcerpt.trim().length;
|
|
4916
|
+
const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
|
|
4917
|
+
if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
|
|
4918
|
+
if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
|
|
4919
|
+
return excerpts.sectionExcerpt;
|
|
4920
|
+
}
|
|
4921
|
+
if (excerpts.windowExcerpt.trim().length > 0) {
|
|
4922
|
+
return excerpts.windowExcerpt;
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
return excerpts.chunkExcerpt;
|
|
4926
|
+
};
|
|
4811
4927
|
var buildRAGChunkGraph = (chunks) => {
|
|
4812
4928
|
const nodes = [];
|
|
4813
4929
|
const edges = [];
|
|
@@ -5019,6 +5135,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
5019
5135
|
return sourceGroups.map((group) => {
|
|
5020
5136
|
const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
|
|
5021
5137
|
const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
|
|
5138
|
+
const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
|
|
5022
5139
|
return {
|
|
5023
5140
|
bestScore: group.bestScore,
|
|
5024
5141
|
citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
|
|
@@ -5026,7 +5143,8 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
5026
5143
|
chunkIds: group.chunks.map((chunk) => chunk.chunkId),
|
|
5027
5144
|
contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
|
|
5028
5145
|
count: group.count,
|
|
5029
|
-
excerpt: buildExcerpt2(leadChunk?.text ?? ""),
|
|
5146
|
+
excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
|
|
5147
|
+
excerpts,
|
|
5030
5148
|
key: group.key,
|
|
5031
5149
|
label: group.label,
|
|
5032
5150
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
@@ -6959,5 +7077,5 @@ export {
|
|
|
6959
7077
|
buildRAGEvaluationLeaderboard
|
|
6960
7078
|
};
|
|
6961
7079
|
|
|
6962
|
-
//# debugId=
|
|
7080
|
+
//# debugId=11D58D8CBC09035E64756E2164756E21
|
|
6963
7081
|
//# sourceMappingURL=index.js.map
|