@absolutejs/absolute 0.19.0-beta.606 → 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 +195 -18
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +197 -18
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +424 -28
- package/dist/ai/index.js.map +7 -7
- package/dist/ai/rag/quality.js +145 -16
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +197 -18
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +194 -17
- package/dist/ai-client/react/ai/index.js +194 -17
- package/dist/ai-client/vue/ai/index.js +194 -17
- package/dist/angular/ai/index.js +195 -18
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +195 -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/grounding.d.ts +2 -1
- package/dist/src/ai/rag/index.d.ts +1 -1
- package/dist/src/ai/rag/presentation.d.ts +6 -3
- 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 +195 -18
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +26 -2
- package/dist/vue/ai/index.js +195 -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,
|
|
@@ -346,11 +396,19 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
|
346
396
|
reference.contextLabel,
|
|
347
397
|
reference.provenanceLabel
|
|
348
398
|
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
399
|
+
var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
400
|
+
var buildGroundingSectionSummaryLine = (reference) => [
|
|
401
|
+
reference.source ?? reference.title ?? reference.chunkId,
|
|
402
|
+
reference.locatorLabel,
|
|
403
|
+
reference.contextLabel,
|
|
404
|
+
reference.provenanceLabel
|
|
405
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
349
406
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
350
407
|
contextLabel: reference.contextLabel,
|
|
351
408
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
352
409
|
evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
|
|
353
|
-
excerpt: reference.excerpt,
|
|
410
|
+
excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
|
|
411
|
+
excerpts: reference.excerpts,
|
|
354
412
|
label: reference.label,
|
|
355
413
|
locatorLabel: reference.locatorLabel,
|
|
356
414
|
number: reference.number,
|
|
@@ -436,26 +494,97 @@ var buildRAGGroundedAnswer = (content, sources) => {
|
|
|
436
494
|
hasCitations,
|
|
437
495
|
parts,
|
|
438
496
|
references,
|
|
497
|
+
sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
|
|
439
498
|
ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
|
|
440
499
|
};
|
|
441
500
|
};
|
|
501
|
+
var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
502
|
+
const groups = new Map;
|
|
503
|
+
for (const reference of references) {
|
|
504
|
+
const key = buildGroundingSectionKey(reference);
|
|
505
|
+
const existing = groups.get(key);
|
|
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;
|
|
512
|
+
groups.set(key, {
|
|
513
|
+
chunkIds: [reference.chunkId],
|
|
514
|
+
contextLabel: reference.contextLabel,
|
|
515
|
+
count: 1,
|
|
516
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
|
|
517
|
+
excerpts,
|
|
518
|
+
key,
|
|
519
|
+
label: key,
|
|
520
|
+
locatorLabel: reference.locatorLabel,
|
|
521
|
+
provenanceLabel: reference.provenanceLabel,
|
|
522
|
+
referenceNumbers: [reference.number],
|
|
523
|
+
references: [reference],
|
|
524
|
+
summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
|
|
525
|
+
});
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
existing.count += 1;
|
|
529
|
+
if (!existing.chunkIds.includes(reference.chunkId)) {
|
|
530
|
+
existing.chunkIds.push(reference.chunkId);
|
|
531
|
+
}
|
|
532
|
+
if (!existing.referenceNumbers.includes(reference.number)) {
|
|
533
|
+
existing.referenceNumbers.push(reference.number);
|
|
534
|
+
}
|
|
535
|
+
existing.references.push(reference);
|
|
536
|
+
if (!existing.contextLabel && reference.contextLabel) {
|
|
537
|
+
existing.contextLabel = reference.contextLabel;
|
|
538
|
+
}
|
|
539
|
+
if (!existing.locatorLabel && reference.locatorLabel) {
|
|
540
|
+
existing.locatorLabel = reference.locatorLabel;
|
|
541
|
+
}
|
|
542
|
+
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
543
|
+
existing.provenanceLabel = reference.provenanceLabel;
|
|
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
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return [...groups.values()].map((group) => ({
|
|
555
|
+
...group,
|
|
556
|
+
referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
|
|
557
|
+
references: group.references.slice().sort((left, right) => left.number - right.number)
|
|
558
|
+
})).sort((left, right) => {
|
|
559
|
+
const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
560
|
+
const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
561
|
+
if (leftFirst !== rightFirst) {
|
|
562
|
+
return leftFirst - rightFirst;
|
|
563
|
+
}
|
|
564
|
+
return left.label.localeCompare(right.label);
|
|
565
|
+
});
|
|
566
|
+
};
|
|
442
567
|
var buildRAGGroundingReferences = (sources) => {
|
|
443
568
|
const citations = buildRAGCitations(sources);
|
|
444
569
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
445
|
-
return citations.map((citation) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
+
});
|
|
459
588
|
};
|
|
460
589
|
|
|
461
590
|
// src/ai/rag/quality.ts
|
|
@@ -3616,5 +3745,5 @@ export {
|
|
|
3616
3745
|
buildRAGAnswerGroundingCaseDifficultyLeaderboard
|
|
3617
3746
|
};
|
|
3618
3747
|
|
|
3619
|
-
//# debugId=
|
|
3748
|
+
//# debugId=E6BD1B37FA2B2FD064756E2164756E21
|
|
3620
3749
|
//# sourceMappingURL=quality.js.map
|