@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/rag/quality.js
CHANGED
|
@@ -339,6 +339,56 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
339
339
|
}
|
|
340
340
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
341
341
|
};
|
|
342
|
+
var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
|
|
343
|
+
if (!excerpts) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
|
|
347
|
+
const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
|
|
348
|
+
const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
|
|
349
|
+
if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
|
|
350
|
+
if (sectionChunkCount <= 3 && sectionExcerpt) {
|
|
351
|
+
return sectionExcerpt;
|
|
352
|
+
}
|
|
353
|
+
if (windowExcerpt) {
|
|
354
|
+
return windowExcerpt;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return chunkExcerpt || windowExcerpt || sectionExcerpt;
|
|
358
|
+
};
|
|
359
|
+
var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
|
|
360
|
+
if (sources.length === 0) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
|
|
364
|
+
if (!activeSource) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
|
|
368
|
+
const activeMetadata = activeSource.metadata ?? {};
|
|
369
|
+
const previousChunkId = getContextString(activeMetadata.previousChunkId);
|
|
370
|
+
const nextChunkId = getContextString(activeMetadata.nextChunkId);
|
|
371
|
+
const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
|
|
372
|
+
const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
|
|
373
|
+
const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
374
|
+
const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
375
|
+
if (leftIndex !== rightIndex) {
|
|
376
|
+
return leftIndex - rightIndex;
|
|
377
|
+
}
|
|
378
|
+
return left.chunkId.localeCompare(right.chunkId);
|
|
379
|
+
}) : [activeSource];
|
|
380
|
+
const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
|
|
381
|
+
|
|
382
|
+
`);
|
|
383
|
+
const orderedWindowIds = [previousChunkId, activeSource.chunkId, nextChunkId].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
|
|
384
|
+
return {
|
|
385
|
+
chunkExcerpt: buildExcerpt(activeSource.text, 160),
|
|
386
|
+
sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
|
|
387
|
+
|
|
388
|
+
`), 320),
|
|
389
|
+
windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
|
|
390
|
+
};
|
|
391
|
+
};
|
|
342
392
|
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 ");
|
|
343
393
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
344
394
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
@@ -357,7 +407,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
|
357
407
|
contextLabel: reference.contextLabel,
|
|
358
408
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
359
409
|
evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
|
|
360
|
-
excerpt: reference.excerpt,
|
|
410
|
+
excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
|
|
411
|
+
excerpts: reference.excerpts,
|
|
361
412
|
label: reference.label,
|
|
362
413
|
locatorLabel: reference.locatorLabel,
|
|
363
414
|
number: reference.number,
|
|
@@ -453,10 +504,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
453
504
|
const key = buildGroundingSectionKey(reference);
|
|
454
505
|
const existing = groups.get(key);
|
|
455
506
|
if (!existing) {
|
|
507
|
+
const excerpts = reference.excerpts ? {
|
|
508
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
509
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
510
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
511
|
+
} : undefined;
|
|
456
512
|
groups.set(key, {
|
|
457
513
|
chunkIds: [reference.chunkId],
|
|
458
514
|
contextLabel: reference.contextLabel,
|
|
459
515
|
count: 1,
|
|
516
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
|
|
517
|
+
excerpts,
|
|
460
518
|
key,
|
|
461
519
|
label: key,
|
|
462
520
|
locatorLabel: reference.locatorLabel,
|
|
@@ -484,6 +542,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
484
542
|
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
485
543
|
existing.provenanceLabel = reference.provenanceLabel;
|
|
486
544
|
}
|
|
545
|
+
if (!existing.excerpts && reference.excerpts) {
|
|
546
|
+
existing.excerpts = {
|
|
547
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
548
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
549
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
550
|
+
};
|
|
551
|
+
existing.excerpt = reference.excerpts.sectionExcerpt;
|
|
552
|
+
}
|
|
487
553
|
}
|
|
488
554
|
return [...groups.values()].map((group) => ({
|
|
489
555
|
...group,
|
|
@@ -501,20 +567,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
|
501
567
|
var buildRAGGroundingReferences = (sources) => {
|
|
502
568
|
const citations = buildRAGCitations(sources);
|
|
503
569
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
504
|
-
return citations.map((citation) =>
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
570
|
+
return citations.map((citation) => {
|
|
571
|
+
const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
|
|
572
|
+
return {
|
|
573
|
+
chunkId: citation.chunkId,
|
|
574
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
575
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
|
|
576
|
+
excerpts,
|
|
577
|
+
label: citation.label,
|
|
578
|
+
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
579
|
+
metadata: citation.metadata,
|
|
580
|
+
number: citationReferenceMap[citation.chunkId] ?? 0,
|
|
581
|
+
provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
|
|
582
|
+
score: citation.score,
|
|
583
|
+
source: citation.source,
|
|
584
|
+
text: citation.text,
|
|
585
|
+
title: citation.title
|
|
586
|
+
};
|
|
587
|
+
});
|
|
518
588
|
};
|
|
519
589
|
|
|
520
590
|
// src/ai/rag/quality.ts
|
|
@@ -3675,5 +3745,5 @@ export {
|
|
|
3675
3745
|
buildRAGAnswerGroundingCaseDifficultyLeaderboard
|
|
3676
3746
|
};
|
|
3677
3747
|
|
|
3678
|
-
//# debugId=
|
|
3748
|
+
//# debugId=E6BD1B37FA2B2FD064756E2164756E21
|
|
3679
3749
|
//# sourceMappingURL=quality.js.map
|