@absolutejs/rag 0.0.15 → 0.0.17
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/index.js +471 -40
- package/dist/index.js.map +5 -3
- package/dist/presentation/ui.js +454 -2
- package/dist/presentation/ui.js.map +6 -4
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/src/presentation/htmxCitationFragments.d.ts +76 -0
- package/dist/src/presentation/htmxRenderers.d.ts +35 -0
- package/dist/src/presentation/ui.d.ts +4 -0
- package/dist/svelte/index.js +1 -1
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11221,6 +11221,437 @@ var summarizeRAGRetrievalComparison = (entries) => ({
|
|
|
11221
11221
|
bestByLowestRuntimeCandidateBudgetExhaustedCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeCandidateBudgetExhaustedCases"),
|
|
11222
11222
|
bestByLowestRuntimeUnderfilledTopKCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeUnderfilledTopKCases")
|
|
11223
11223
|
});
|
|
11224
|
+
// src/presentation/htmxCitationFragments.ts
|
|
11225
|
+
var formatScore = (value) => Number.isFinite(value) ? value.toFixed(3) : "0.000";
|
|
11226
|
+
var buildSearchTargetId = (prefix, value) => {
|
|
11227
|
+
const normalized = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
11228
|
+
return `${prefix}-${normalized || "item"}`;
|
|
11229
|
+
};
|
|
11230
|
+
var buildSourceSummarySectionGroups = (summaries) => {
|
|
11231
|
+
const groups = new Map;
|
|
11232
|
+
for (const summary of summaries ?? []) {
|
|
11233
|
+
const label = summary.contextLabel ?? summary.label;
|
|
11234
|
+
const id = buildSearchTargetId("source-summary-section", label);
|
|
11235
|
+
const existing = groups.get(id);
|
|
11236
|
+
if (existing) {
|
|
11237
|
+
existing.summaries.push(summary);
|
|
11238
|
+
existing.summary = `${existing.summaries.length} evidence summar${existing.summaries.length === 1 ? "y" : "ies"}`;
|
|
11239
|
+
continue;
|
|
11240
|
+
}
|
|
11241
|
+
groups.set(id, {
|
|
11242
|
+
id,
|
|
11243
|
+
label,
|
|
11244
|
+
targetId: id,
|
|
11245
|
+
summary: "1 evidence summary",
|
|
11246
|
+
summaries: [summary]
|
|
11247
|
+
});
|
|
11248
|
+
}
|
|
11249
|
+
return [...groups.values()].sort((left, right) => {
|
|
11250
|
+
const leftScore = Math.max(...left.summaries.map((summary) => summary.bestScore));
|
|
11251
|
+
const rightScore = Math.max(...right.summaries.map((summary) => summary.bestScore));
|
|
11252
|
+
return rightScore - leftScore;
|
|
11253
|
+
});
|
|
11254
|
+
};
|
|
11255
|
+
var buildGroundingReferenceGroups = (references) => {
|
|
11256
|
+
const groups = new Map;
|
|
11257
|
+
for (const reference of references ?? []) {
|
|
11258
|
+
const label = reference.contextLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
11259
|
+
const id = buildSearchTargetId("grounding-reference-section", label);
|
|
11260
|
+
const existing = groups.get(id);
|
|
11261
|
+
if (existing) {
|
|
11262
|
+
existing.references.push(reference);
|
|
11263
|
+
existing.summary = `${existing.references.length} grounding reference${existing.references.length === 1 ? "" : "s"}`;
|
|
11264
|
+
continue;
|
|
11265
|
+
}
|
|
11266
|
+
groups.set(id, {
|
|
11267
|
+
id,
|
|
11268
|
+
label,
|
|
11269
|
+
targetId: id,
|
|
11270
|
+
summary: "1 grounding reference",
|
|
11271
|
+
references: [reference]
|
|
11272
|
+
});
|
|
11273
|
+
}
|
|
11274
|
+
return [...groups.values()].sort((left, right) => {
|
|
11275
|
+
const leftScore = Math.max(...left.references.map((reference) => reference.score));
|
|
11276
|
+
const rightScore = Math.max(...right.references.map((reference) => reference.score));
|
|
11277
|
+
return rightScore - leftScore;
|
|
11278
|
+
});
|
|
11279
|
+
};
|
|
11280
|
+
var buildCitationGroups = (citations) => {
|
|
11281
|
+
const groups = new Map;
|
|
11282
|
+
for (const citation of citations ?? []) {
|
|
11283
|
+
const label = citation.contextLabel ?? citation.label ?? citation.source ?? citation.chunkId;
|
|
11284
|
+
const id = buildSearchTargetId("citation-section", label);
|
|
11285
|
+
const existing = groups.get(id);
|
|
11286
|
+
if (existing) {
|
|
11287
|
+
existing.citations.push(citation);
|
|
11288
|
+
existing.summary = `${existing.citations.length} citation${existing.citations.length === 1 ? "" : "s"}`;
|
|
11289
|
+
continue;
|
|
11290
|
+
}
|
|
11291
|
+
groups.set(id, {
|
|
11292
|
+
id,
|
|
11293
|
+
label,
|
|
11294
|
+
targetId: id,
|
|
11295
|
+
summary: "1 citation",
|
|
11296
|
+
citations: [citation]
|
|
11297
|
+
});
|
|
11298
|
+
}
|
|
11299
|
+
return [...groups.values()].sort((left, right) => {
|
|
11300
|
+
const leftScore = Math.max(...left.citations.map((citation) => citation.score));
|
|
11301
|
+
const rightScore = Math.max(...right.citations.map((citation) => citation.score));
|
|
11302
|
+
return rightScore - leftScore;
|
|
11303
|
+
});
|
|
11304
|
+
};
|
|
11305
|
+
var formatCitationLabel = (citation) => [citation.label, citation.contextLabel, citation.locatorLabel].filter(Boolean).join(" \xB7 ");
|
|
11306
|
+
var formatCitationSummary = (citation) => citation.source ?? citation.title ?? citation.chunkId;
|
|
11307
|
+
var formatCitationExcerpt = (citation) => citation.excerpt || citation.text;
|
|
11308
|
+
var formatEvidenceDetailLine = (label, value) => value && value.length > 0 ? `${label}: ${value}` : "";
|
|
11309
|
+
var formatEvidenceContextLine = (contextLabel, locatorLabel) => {
|
|
11310
|
+
const value = [locatorLabel, contextLabel].filter((entry) => Boolean(entry && entry.length > 0)).join(" \xB7 ");
|
|
11311
|
+
return value.length > 0 ? `location: ${value}` : "";
|
|
11312
|
+
};
|
|
11313
|
+
var formatSourceSummaryDetails = (summary) => [
|
|
11314
|
+
`best score: ${formatScore(summary.bestScore)}`,
|
|
11315
|
+
`coverage: ${summary.count} chunk(s) \xB7 citations ${summary.citationNumbers.map((value) => `[${value}]`).join(" ") || "none"}`,
|
|
11316
|
+
formatEvidenceContextLine(summary.contextLabel, summary.locatorLabel),
|
|
11317
|
+
formatEvidenceDetailLine("provenance", summary.provenanceLabel)
|
|
11318
|
+
].filter((value) => value.length > 0);
|
|
11319
|
+
var formatCitationDetails = (citation) => [
|
|
11320
|
+
formatEvidenceDetailLine("evidence", citation.source ?? citation.title ?? citation.chunkId),
|
|
11321
|
+
formatEvidenceContextLine(citation.contextLabel, citation.locatorLabel),
|
|
11322
|
+
formatEvidenceDetailLine("provenance", citation.provenanceLabel),
|
|
11323
|
+
`score: ${formatScore(citation.score)}`
|
|
11324
|
+
].filter((value) => value.length > 0);
|
|
11325
|
+
var formatSectionDiagnosticPercent = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : null;
|
|
11326
|
+
var formatSectionDiagnosticReason = (reason) => reason.replaceAll("_", " ");
|
|
11327
|
+
var formatSectionDiagnosticStage = (stage) => stage.replaceAll("_", " ");
|
|
11328
|
+
var formatSectionDiagnosticWeightReason = (reason) => ({
|
|
11329
|
+
final_stage_concentration: "final stage concentrated on this section",
|
|
11330
|
+
final_stage_dominant_within_parent: "final stage stayed ahead inside its parent",
|
|
11331
|
+
rerank_preserved_lead: "rerank kept this section in front",
|
|
11332
|
+
stage_runner_up_pressure: "runner-up stayed close in this stage",
|
|
11333
|
+
stage_expanded: "this section expanded in this stage",
|
|
11334
|
+
stage_held: "this section held steady in this stage",
|
|
11335
|
+
stage_narrowed: "this section narrowed in this stage"
|
|
11336
|
+
})[reason] ?? reason.replaceAll("_", " ");
|
|
11337
|
+
var formatSectionQueryAttributionReason = (reason) => ({
|
|
11338
|
+
base_query_only: "came only from the base query",
|
|
11339
|
+
transformed_query_only: "came only from the transformed query",
|
|
11340
|
+
variant_only: "came only from query variants",
|
|
11341
|
+
transform_introduced: "the transformed query introduced this section",
|
|
11342
|
+
variant_supported: "query variants reinforced this section",
|
|
11343
|
+
mixed_query_sources: "multiple query forms contributed"
|
|
11344
|
+
})[reason] ?? reason.replaceAll("_", " ");
|
|
11345
|
+
var formatSectionDiagnosticChannels = (diagnostic) => `Channels \xB7 hybrid ${diagnostic.hybridHits} \xB7 vector ${diagnostic.vectorHits} \xB7 lexical ${diagnostic.lexicalHits}`;
|
|
11346
|
+
var formatSectionDiagnosticAttributionFocus = (diagnostic) => {
|
|
11347
|
+
const mode = diagnostic.queryAttribution?.mode ?? "mixed";
|
|
11348
|
+
const label = mode === "primary" ? "Attribution \xB7 base-query-only" : mode === "transformed" ? "Attribution \xB7 transformed-only" : mode === "variant" ? "Attribution \xB7 variant-only" : "Attribution \xB7 mixed";
|
|
11349
|
+
const parts = [label];
|
|
11350
|
+
if ((diagnostic.queryAttribution?.primaryHits ?? 0) > 0)
|
|
11351
|
+
parts.push(`base ${diagnostic.queryAttribution?.primaryHits}`);
|
|
11352
|
+
if ((diagnostic.queryAttribution?.transformedHits ?? 0) > 0)
|
|
11353
|
+
parts.push(`transformed ${diagnostic.queryAttribution?.transformedHits}`);
|
|
11354
|
+
if ((diagnostic.queryAttribution?.variantHits ?? 0) > 0)
|
|
11355
|
+
parts.push(`variant ${diagnostic.queryAttribution?.variantHits}`);
|
|
11356
|
+
return parts.join(" \xB7 ");
|
|
11357
|
+
};
|
|
11358
|
+
var formatSectionDiagnosticPipeline = (diagnostic) => {
|
|
11359
|
+
const requestedMode = diagnostic.requestedMode ?? diagnostic.retrievalMode ?? "n/a";
|
|
11360
|
+
const selectedMode = diagnostic.retrievalMode ?? "n/a";
|
|
11361
|
+
const routeLabel = diagnostic.routingLabel ?? "default route";
|
|
11362
|
+
const transformLabel = diagnostic.queryTransformLabel ?? "no transform";
|
|
11363
|
+
return `Mode ${selectedMode} \xB7 requested ${requestedMode} \xB7 route ${routeLabel} \xB7 transform ${transformLabel} \xB7 rerank ${diagnostic.rerankApplied ? "on" : "off"} \xB7 source balance ${diagnostic.sourceBalanceApplied ? "on" : "off"} \xB7 threshold ${diagnostic.scoreThresholdApplied ? "on" : "off"} \xB7 query ${diagnostic.queryAttribution?.mode ?? "n/a"}`;
|
|
11364
|
+
};
|
|
11365
|
+
var formatSectionDiagnosticStageFlow = (diagnostic) => diagnostic.stageCounts.length > 0 ? `Stage flow \xB7 ${diagnostic.stageCounts.map((entry) => `${formatSectionDiagnosticStage(entry.stage)} ${entry.count}`).join(" \u2192 ")}` : null;
|
|
11366
|
+
var formatSectionDiagnosticStageBounds = (diagnostic) => {
|
|
11367
|
+
const parts = [];
|
|
11368
|
+
if (diagnostic.firstSeenStage)
|
|
11369
|
+
parts.push(`first seen ${formatSectionDiagnosticStage(diagnostic.firstSeenStage)}`);
|
|
11370
|
+
if (diagnostic.lastSeenStage)
|
|
11371
|
+
parts.push(`last seen ${formatSectionDiagnosticStage(diagnostic.lastSeenStage)}`);
|
|
11372
|
+
if (diagnostic.peakStage)
|
|
11373
|
+
parts.push(`peak ${formatSectionDiagnosticStage(diagnostic.peakStage)} ${diagnostic.peakCount}`);
|
|
11374
|
+
const finalRetention = formatSectionDiagnosticPercent(diagnostic.finalRetentionRate);
|
|
11375
|
+
if (finalRetention)
|
|
11376
|
+
parts.push(`final retention ${finalRetention}`);
|
|
11377
|
+
if (typeof diagnostic.dropFromPeak === "number")
|
|
11378
|
+
parts.push(`drop from peak ${diagnostic.dropFromPeak}`);
|
|
11379
|
+
return parts.length > 0 ? parts.join(" \xB7 ") : null;
|
|
11380
|
+
};
|
|
11381
|
+
var formatSectionDiagnosticStageWeightRows = (diagnostic) => (diagnostic.stageWeights ?? []).filter((entry) => entry.reasons.length > 0 || entry.stage === "rerank" || entry.stage === "finalize").map((entry) => {
|
|
11382
|
+
const parts = [
|
|
11383
|
+
`${formatSectionDiagnosticStage(entry.stage)} ${(entry.stageShare * 100).toFixed(0)}% of stage`,
|
|
11384
|
+
typeof entry.stageScoreShare === "number" ? `${(entry.stageScoreShare * 100).toFixed(0)}% of stage score` : null,
|
|
11385
|
+
typeof entry.retentionRate === "number" && entry.previousStage && entry.retentionRate !== 1 ? `${(entry.retentionRate * 100).toFixed(0)}% retained from ${formatSectionDiagnosticStage(entry.previousStage)}` : null,
|
|
11386
|
+
typeof entry.countDelta === "number" && entry.countDelta !== 0 ? `delta ${entry.countDelta >= 0 ? "+" : ""}${entry.countDelta}` : null,
|
|
11387
|
+
typeof entry.parentStageShare === "number" && entry.strongestSiblingLabel ? `${(entry.parentStageShare * 100).toFixed(0)}% of parent stage` : null,
|
|
11388
|
+
typeof entry.parentStageScoreShare === "number" && entry.strongestSiblingLabel ? `${(entry.parentStageScoreShare * 100).toFixed(0)}% of parent stage score` : null,
|
|
11389
|
+
typeof entry.stageShareGap === "number" ? `gap ${(entry.stageShareGap * 100).toFixed(0)}%` : null,
|
|
11390
|
+
typeof entry.stageScoreShareGap === "number" ? `score gap ${(entry.stageScoreShareGap * 100).toFixed(0)}%` : null,
|
|
11391
|
+
entry.strongestSiblingLabel ? `runner-up ${entry.strongestSiblingLabel}` : null
|
|
11392
|
+
].filter((value) => Boolean(value));
|
|
11393
|
+
return parts.join(" \xB7 ");
|
|
11394
|
+
});
|
|
11395
|
+
var formatSectionDiagnosticStageWeightReasons = (diagnostic) => (diagnostic.stageWeights ?? []).flatMap((entry) => entry.reasons.map((reason) => `${formatSectionDiagnosticStage(entry.stage)} \xB7 ${formatSectionDiagnosticWeightReason(reason)}`));
|
|
11396
|
+
var formatSectionDiagnosticQueryAttributionReasons = (diagnostic) => (diagnostic.queryAttribution?.reasons ?? []).map((reason) => formatSectionQueryAttributionReason(reason));
|
|
11397
|
+
var formatSectionDiagnosticCompetition = (diagnostic) => {
|
|
11398
|
+
const parts = [];
|
|
11399
|
+
const parentShare = formatSectionDiagnosticPercent(diagnostic.parentShare);
|
|
11400
|
+
const parentShareGap = formatSectionDiagnosticPercent(diagnostic.parentShareGap);
|
|
11401
|
+
if (!diagnostic.strongestSiblingLabel)
|
|
11402
|
+
return "";
|
|
11403
|
+
if (parentShare)
|
|
11404
|
+
parts.push(`parent share ${parentShare}`);
|
|
11405
|
+
if (parentShareGap)
|
|
11406
|
+
parts.push(`gap ${parentShareGap}`);
|
|
11407
|
+
parts.push(`runner-up ${diagnostic.strongestSiblingLabel}`);
|
|
11408
|
+
return parts.join(" \xB7 ");
|
|
11409
|
+
};
|
|
11410
|
+
var formatSectionDiagnosticTopEntry = (diagnostic) => {
|
|
11411
|
+
const parts = [];
|
|
11412
|
+
if (diagnostic.topSource)
|
|
11413
|
+
parts.push(`top source ${diagnostic.topSource}`);
|
|
11414
|
+
if (diagnostic.topChunkId)
|
|
11415
|
+
parts.push(`lead chunk ${diagnostic.topChunkId}`);
|
|
11416
|
+
parts.push(`${diagnostic.sourceCount} source${diagnostic.sourceCount === 1 ? "" : "s"}`);
|
|
11417
|
+
parts.push(`primary ${diagnostic.queryAttribution?.primaryHits ?? 0} \xB7 transformed ${diagnostic.queryAttribution?.transformedHits ?? 0} \xB7 variant ${diagnostic.queryAttribution?.variantHits ?? 0}`);
|
|
11418
|
+
return parts.join(" \xB7 ");
|
|
11419
|
+
};
|
|
11420
|
+
var formatSectionDiagnosticReasons = (diagnostic) => [
|
|
11421
|
+
...diagnostic.reasons.map((reason) => formatSectionDiagnosticReason(reason)),
|
|
11422
|
+
...formatSectionDiagnosticQueryAttributionReasons(diagnostic),
|
|
11423
|
+
...diagnostic.routingReason ? [`routing \xB7 ${diagnostic.routingReason}`] : [],
|
|
11424
|
+
...diagnostic.queryTransformReason ? [`transform \xB7 ${diagnostic.queryTransformReason}`] : []
|
|
11425
|
+
];
|
|
11426
|
+
var formatSectionDiagnosticDistributionRows = (diagnostic) => diagnostic.parentDistribution.map((entry) => `${entry.isActive ? "Active" : "Peer"} \xB7 ${entry.label} \xB7 ${entry.count} hit${entry.count === 1 ? "" : "s"} \xB7 ${formatSectionDiagnosticPercent(entry.parentShare) ?? "0%"}`);
|
|
11427
|
+
|
|
11428
|
+
// src/presentation/htmxRenderers.ts
|
|
11429
|
+
var STREAM_STAGES = [
|
|
11430
|
+
"submitting",
|
|
11431
|
+
"retrieving",
|
|
11432
|
+
"retrieved",
|
|
11433
|
+
"streaming",
|
|
11434
|
+
"complete"
|
|
11435
|
+
];
|
|
11436
|
+
var escapeHtml = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
11437
|
+
var formatTime = (timestamp) => {
|
|
11438
|
+
if (!timestamp) {
|
|
11439
|
+
return "n/a";
|
|
11440
|
+
}
|
|
11441
|
+
return new Date(timestamp).toLocaleTimeString([], {
|
|
11442
|
+
hour: "numeric",
|
|
11443
|
+
minute: "2-digit",
|
|
11444
|
+
second: "2-digit"
|
|
11445
|
+
});
|
|
11446
|
+
};
|
|
11447
|
+
var formatDuration = (durationMs) => typeof durationMs !== "number" || durationMs < 0 ? "n/a" : `${durationMs}ms`;
|
|
11448
|
+
var makeTracePanel = (prefix) => ({
|
|
11449
|
+
title,
|
|
11450
|
+
summary,
|
|
11451
|
+
trace
|
|
11452
|
+
}) => {
|
|
11453
|
+
if (!trace) {
|
|
11454
|
+
return "";
|
|
11455
|
+
}
|
|
11456
|
+
const presentation = buildRAGRetrievalTracePresentation(trace);
|
|
11457
|
+
return [
|
|
11458
|
+
`<div class="${prefix}-results">`,
|
|
11459
|
+
`<h4>${escapeHtml(title)}</h4>`,
|
|
11460
|
+
`<p class="${prefix}-metadata">${escapeHtml(summary)}</p>`,
|
|
11461
|
+
`<div class="${prefix}-stat-grid">`,
|
|
11462
|
+
presentation.stats.map((row) => `<article class="${prefix}-stat-card"><p class="${prefix}-section-caption">${escapeHtml(row.label)}</p><strong>${escapeHtml(row.value)}</strong></article>`).join(""),
|
|
11463
|
+
"</div>",
|
|
11464
|
+
"<div>",
|
|
11465
|
+
presentation.details.map((row) => `<p class="${prefix}-key-value-row"><strong>${escapeHtml(row.label)}</strong><span>${escapeHtml(row.value)}</span></p>`).join(""),
|
|
11466
|
+
"</div>",
|
|
11467
|
+
`<div class="${prefix}-result-grid">`,
|
|
11468
|
+
presentation.steps.map((step, index) => `<details class="${prefix}-collapsible ${prefix}-result-item" ${index === 0 ? "open" : ""}><summary><strong>${index + 1}. ${escapeHtml(step.label)}</strong></summary>${step.rows.map((row) => `<p class="${prefix}-key-value-row"><strong>${escapeHtml(row.label)}</strong><span>${escapeHtml(row.value)}</span></p>`).join("")}</details>`).join(""),
|
|
11469
|
+
"</div>",
|
|
11470
|
+
"</div>"
|
|
11471
|
+
].join("");
|
|
11472
|
+
};
|
|
11473
|
+
var makeStageRow = (prefix) => (currentStage) => `<div class="${prefix}-stage-row">${STREAM_STAGES.map((stage) => {
|
|
11474
|
+
const classNames = [`${prefix}-stage-pill`];
|
|
11475
|
+
if (stage === "complete") {
|
|
11476
|
+
classNames.push("complete");
|
|
11477
|
+
}
|
|
11478
|
+
if (stage === currentStage) {
|
|
11479
|
+
classNames.push("current");
|
|
11480
|
+
}
|
|
11481
|
+
return `<span class="${classNames.join(" ")}">${escapeHtml(stage)}</span>`;
|
|
11482
|
+
}).join("")}</div>`;
|
|
11483
|
+
var makeCapabilities = (prefix) => (capabilities) => {
|
|
11484
|
+
if (!capabilities) {
|
|
11485
|
+
return `<p class="${prefix}-metadata">Backend capabilities unavailable.</p>`;
|
|
11486
|
+
}
|
|
11487
|
+
const values = [
|
|
11488
|
+
capabilities.backend,
|
|
11489
|
+
capabilities.persistence,
|
|
11490
|
+
capabilities.nativeVectorSearch ? "native vector search" : "managed fallback search",
|
|
11491
|
+
capabilities.serverSideFiltering ? "server-side filters" : "client-side filters",
|
|
11492
|
+
capabilities.streamingIngestStatus ? "streaming ingest status" : "polled ingest status"
|
|
11493
|
+
];
|
|
11494
|
+
return `<p class="${prefix}-metadata">Backend capabilities: <strong>${escapeHtml(values.join(" \xB7 "))}</strong></p>`;
|
|
11495
|
+
};
|
|
11496
|
+
var defaultNativeSource = (status) => {
|
|
11497
|
+
const native = status?.native;
|
|
11498
|
+
if (!native || !native.active) {
|
|
11499
|
+
return "Not applicable";
|
|
11500
|
+
}
|
|
11501
|
+
if (status?.backend === "sqlite") {
|
|
11502
|
+
return "Packaged sqlite-vec";
|
|
11503
|
+
}
|
|
11504
|
+
if (status?.backend === "postgres") {
|
|
11505
|
+
return "PostgreSQL pgvector extension";
|
|
11506
|
+
}
|
|
11507
|
+
return "Managed by AbsoluteJS";
|
|
11508
|
+
};
|
|
11509
|
+
var defaultStatusSummary = (status) => {
|
|
11510
|
+
if (!status) {
|
|
11511
|
+
return "No backend status is available.";
|
|
11512
|
+
}
|
|
11513
|
+
if (status.native?.active) {
|
|
11514
|
+
return "Native vector acceleration is active.";
|
|
11515
|
+
}
|
|
11516
|
+
if (status.vectorMode === "json_fallback") {
|
|
11517
|
+
return "Owned JSON fallback retrieval is active.";
|
|
11518
|
+
}
|
|
11519
|
+
return `Vector mode ${status.vectorMode} is active.`;
|
|
11520
|
+
};
|
|
11521
|
+
var defaultStatusMessage = (status) => {
|
|
11522
|
+
if (!status) {
|
|
11523
|
+
return "Backend status unavailable.";
|
|
11524
|
+
}
|
|
11525
|
+
return status.native?.fallbackReason ?? defaultStatusSummary(status);
|
|
11526
|
+
};
|
|
11527
|
+
var makeDetailList = (prefix) => (lines, fallback) => {
|
|
11528
|
+
const values = lines.length > 0 ? lines : [fallback];
|
|
11529
|
+
return `<ul class="${prefix}-detail-list">${values.map((line) => `<li>${escapeHtml(line)}</li>`).join("")}</ul>`;
|
|
11530
|
+
};
|
|
11531
|
+
var makeAdminJobCards = (prefix) => (jobs) => {
|
|
11532
|
+
const records = (jobs ?? []).slice(0, 3);
|
|
11533
|
+
if (records.length === 0) {
|
|
11534
|
+
return `<p class="${prefix}-metadata">No admin jobs recorded yet.</p>`;
|
|
11535
|
+
}
|
|
11536
|
+
return `<div class="${prefix}-stat-grid">${records.map((job) => {
|
|
11537
|
+
const target = job.target ?? "global";
|
|
11538
|
+
const timing = typeof job.startedAt === "number" ? formatTime(job.startedAt) : "n/a";
|
|
11539
|
+
return `<article class="${prefix}-stat-card">
|
|
11540
|
+
<span class="${prefix}-stat-label">${escapeHtml(job.action)}</span>
|
|
11541
|
+
<strong>${escapeHtml(job.status.toUpperCase())}</strong>
|
|
11542
|
+
<p>${escapeHtml(target)}</p>
|
|
11543
|
+
<div class="${prefix}-key-value-list">
|
|
11544
|
+
<div class="${prefix}-key-value-row"><span>Started</span><strong>${escapeHtml(timing)}</strong></div>
|
|
11545
|
+
${typeof job.elapsedMs === "number" ? `<div class="${prefix}-key-value-row"><span>Elapsed</span><strong>${escapeHtml(formatDuration(job.elapsedMs))}</strong></div>` : ""}
|
|
11546
|
+
</div>
|
|
11547
|
+
</article>`;
|
|
11548
|
+
}).join("")}</div>`;
|
|
11549
|
+
};
|
|
11550
|
+
var makeAdminActionCards = (prefix) => (actions) => {
|
|
11551
|
+
const records = (actions ?? []).slice(0, 3);
|
|
11552
|
+
if (records.length === 0) {
|
|
11553
|
+
return `<p class="${prefix}-metadata">No admin actions recorded yet.</p>`;
|
|
11554
|
+
}
|
|
11555
|
+
return `<div class="${prefix}-stat-grid">${records.map((action) => {
|
|
11556
|
+
const target = action.documentId ?? action.target ?? "global";
|
|
11557
|
+
const timing = typeof action.elapsedMs === "number" ? formatDuration(action.elapsedMs) : typeof action.startedAt === "number" ? formatTime(action.startedAt) : "n/a";
|
|
11558
|
+
return `<article class="${prefix}-stat-card">
|
|
11559
|
+
<span class="${prefix}-stat-label">${escapeHtml(action.action)}</span>
|
|
11560
|
+
<strong>${escapeHtml(action.status.toUpperCase())}</strong>
|
|
11561
|
+
<p>${escapeHtml(target)}</p>
|
|
11562
|
+
<div class="${prefix}-key-value-list">
|
|
11563
|
+
<div class="${prefix}-key-value-row"><span>When</span><strong>${escapeHtml(timing)}</strong></div>
|
|
11564
|
+
</div>
|
|
11565
|
+
</article>`;
|
|
11566
|
+
}).join("")}</div>`;
|
|
11567
|
+
};
|
|
11568
|
+
var makeCitations = (prefix) => (sources) => {
|
|
11569
|
+
const citations = buildRAGCitations(sources);
|
|
11570
|
+
if (citations.length === 0) {
|
|
11571
|
+
return "";
|
|
11572
|
+
}
|
|
11573
|
+
return [
|
|
11574
|
+
`<div class="${prefix}-results">`,
|
|
11575
|
+
"<h4>Citation Trail</h4>",
|
|
11576
|
+
`<p class="${prefix}-metadata">Each citation maps a concrete retrieved chunk to a stable reference number you can carry into the answer UI.</p>`,
|
|
11577
|
+
`<div class="${prefix}-result-grid">`,
|
|
11578
|
+
buildCitationGroups(citations).map((group) => `
|
|
11579
|
+
<article class="${prefix}-result-item" id="${escapeHtml(group.targetId)}">
|
|
11580
|
+
<h3>${escapeHtml(group.label)}</h3>
|
|
11581
|
+
<p class="${prefix}-result-source">${escapeHtml(group.summary)}</p>
|
|
11582
|
+
<div class="${prefix}-result-grid">
|
|
11583
|
+
${group.citations.map((citation, index) => `
|
|
11584
|
+
<article class="${prefix}-result-item ${prefix}-citation-card">
|
|
11585
|
+
<p class="${prefix}-citation-badge">[${index + 1}] ${escapeHtml(formatCitationLabel(citation))}</p>
|
|
11586
|
+
<p class="${prefix}-result-score">${escapeHtml(formatCitationSummary(citation))}</p>
|
|
11587
|
+
${formatCitationDetails(citation).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}
|
|
11588
|
+
<p class="${prefix}-result-text">${escapeHtml(formatCitationExcerpt(citation))}</p>
|
|
11589
|
+
</article>`).join("")}
|
|
11590
|
+
</div>
|
|
11591
|
+
</article>`).join(""),
|
|
11592
|
+
"</div>",
|
|
11593
|
+
"</div>"
|
|
11594
|
+
].join("");
|
|
11595
|
+
};
|
|
11596
|
+
var makeSourceSummaries = (prefix) => (sources) => {
|
|
11597
|
+
const summaries = buildRAGSourceSummaries(sources);
|
|
11598
|
+
if (summaries.length === 0) {
|
|
11599
|
+
return `<p class="${prefix}-metadata">Retrieved source groups: 0</p>`;
|
|
11600
|
+
}
|
|
11601
|
+
const groups = buildSourceSummarySectionGroups(summaries);
|
|
11602
|
+
return [
|
|
11603
|
+
`<p class="${prefix}-metadata">Retrieved source groups: ${summaries.length}</p>`,
|
|
11604
|
+
`<div class="${prefix}-result-grid">`,
|
|
11605
|
+
groups.map((group) => `
|
|
11606
|
+
<article class="${prefix}-result-item" id="${escapeHtml(group.targetId)}">
|
|
11607
|
+
<h3>${escapeHtml(group.label)}</h3>
|
|
11608
|
+
<p class="${prefix}-result-source">${escapeHtml(group.summary)}</p>
|
|
11609
|
+
<div class="${prefix}-result-grid">
|
|
11610
|
+
${group.summaries.map((summary) => `
|
|
11611
|
+
<article class="${prefix}-result-item">
|
|
11612
|
+
<h4>${escapeHtml(summary.label)}</h4>
|
|
11613
|
+
${formatSourceSummaryDetails(summary).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}
|
|
11614
|
+
<p class="${prefix}-result-text">${escapeHtml(summary.excerpt)}</p>
|
|
11615
|
+
</article>`).join("")}
|
|
11616
|
+
</div>
|
|
11617
|
+
</article>`).join(""),
|
|
11618
|
+
"</div>"
|
|
11619
|
+
].join("");
|
|
11620
|
+
};
|
|
11621
|
+
var makeSectionDiagnosticCard = (prefix) => (diagnostic) => [
|
|
11622
|
+
`<article class="${prefix}-result-item">`,
|
|
11623
|
+
`<h4>${escapeHtml(diagnostic.label)}</h4>`,
|
|
11624
|
+
`<p class="${prefix}-result-source">${escapeHtml(diagnostic.summary)}</p>`,
|
|
11625
|
+
`<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticChannels(diagnostic))}</p>`,
|
|
11626
|
+
`<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticAttributionFocus(diagnostic))}</p>`,
|
|
11627
|
+
`<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticPipeline(diagnostic))}</p>`,
|
|
11628
|
+
`${formatSectionDiagnosticStageFlow(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticStageFlow(diagnostic) ?? "")}</p>` : ""}`,
|
|
11629
|
+
`${formatSectionDiagnosticStageBounds(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticStageBounds(diagnostic) ?? "")}</p>` : ""}`,
|
|
11630
|
+
`${formatSectionDiagnosticStageWeightRows(diagnostic).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}`,
|
|
11631
|
+
`<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticTopEntry(diagnostic))}</p>`,
|
|
11632
|
+
`${formatSectionDiagnosticCompetition(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticCompetition(diagnostic) ?? "")}</p>` : ""}`,
|
|
11633
|
+
`${[...formatSectionDiagnosticReasons(diagnostic), ...formatSectionDiagnosticStageWeightReasons(diagnostic)].length > 0 ? `<div class="${prefix}-badge-row">${[...formatSectionDiagnosticReasons(diagnostic), ...formatSectionDiagnosticStageWeightReasons(diagnostic)].map((reason) => `<span class="${prefix}-state-chip">${escapeHtml(reason)}</span>`).join("")}</div>` : ""}`,
|
|
11634
|
+
`${formatSectionDiagnosticDistributionRows(diagnostic).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}`,
|
|
11635
|
+
`</article>`
|
|
11636
|
+
].join("");
|
|
11637
|
+
var resolveRAGHTMXRenderers = (custom = {}) => {
|
|
11638
|
+
const classPrefix = custom.classPrefix ?? "rag";
|
|
11639
|
+
return {
|
|
11640
|
+
adminActionCards: custom.adminActionCards ?? makeAdminActionCards(classPrefix),
|
|
11641
|
+
adminJobCards: custom.adminJobCards ?? makeAdminJobCards(classPrefix),
|
|
11642
|
+
capabilities: custom.capabilities ?? makeCapabilities(classPrefix),
|
|
11643
|
+
citations: custom.citations ?? makeCitations(classPrefix),
|
|
11644
|
+
classPrefix,
|
|
11645
|
+
detailList: custom.detailList ?? makeDetailList(classPrefix),
|
|
11646
|
+
nativeSource: custom.nativeSource ?? defaultNativeSource,
|
|
11647
|
+
sectionDiagnosticCard: custom.sectionDiagnosticCard ?? makeSectionDiagnosticCard(classPrefix),
|
|
11648
|
+
sourceSummaries: custom.sourceSummaries ?? makeSourceSummaries(classPrefix),
|
|
11649
|
+
stageRow: custom.stageRow ?? makeStageRow(classPrefix),
|
|
11650
|
+
statusMessage: custom.statusMessage ?? defaultStatusMessage,
|
|
11651
|
+
statusSummary: custom.statusSummary ?? defaultStatusSummary,
|
|
11652
|
+
tracePanel: custom.tracePanel ?? makeTracePanel(classPrefix)
|
|
11653
|
+
};
|
|
11654
|
+
};
|
|
11224
11655
|
// src/chat/chat.ts
|
|
11225
11656
|
import { Elysia } from "elysia";
|
|
11226
11657
|
|
|
@@ -21131,8 +21562,8 @@ var ingestRAGDocuments = async (collection, input) => collection.ingest(buildRAG
|
|
|
21131
21562
|
var searchDocuments = async (collection, input) => collection.search(input);
|
|
21132
21563
|
|
|
21133
21564
|
// src/presentation/htmxWorkflowRenderers.ts
|
|
21134
|
-
var
|
|
21135
|
-
var renderLabelValueRows = (rows) => rows.length > 0 ? `<dl class="rag-status">${rows.map((row) => `<div><dt>${
|
|
21565
|
+
var escapeHtml2 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
21566
|
+
var renderLabelValueRows = (rows) => rows.length > 0 ? `<dl class="rag-status">${rows.map((row) => `<div><dt>${escapeHtml2(row.label)}</dt><dd>${escapeHtml2(row.value)}</dd></div>`).join("")}</dl>` : "";
|
|
21136
21567
|
var renderBenchmarkRuntimePanel = (input) => {
|
|
21137
21568
|
const rows = [
|
|
21138
21569
|
{
|
|
@@ -21146,7 +21577,7 @@ var renderBenchmarkRuntimePanel = (input) => {
|
|
|
21146
21577
|
const recentRuns = input.response.historyPresentation?.recentRuns ?? [];
|
|
21147
21578
|
const snapshotRows = input.response.snapshotHistoryPresentation?.rows ?? [];
|
|
21148
21579
|
const snapshots = input.response.snapshotHistoryPresentation?.snapshots ?? [];
|
|
21149
|
-
return `<section class="rag-status-governance"><h3>${
|
|
21580
|
+
return `<section class="rag-status-governance"><h3>${escapeHtml2(input.title)}</h3>` + renderLabelValueRows(rows) + `<h4>Run history</h4>` + renderLabelValueRows(latestRows) + (recentRuns.length > 0 ? `<ul class="rag-status-capabilities">${recentRuns.slice(0, 3).map((run) => `<li><strong>${escapeHtml2(run.label)}</strong> ${escapeHtml2(run.summary)}</li>`).join("")}</ul>` : `<p class="rag-empty">No persisted benchmark runs yet.</p>`) + `<h4>Snapshot history</h4>` + renderLabelValueRows(snapshotRows) + (snapshots.length > 0 ? `<ul class="rag-status-capabilities">${snapshots.slice(0, 3).map((snapshot) => `<li><strong>${escapeHtml2(snapshot.label)}</strong> ${escapeHtml2(snapshot.summary)}</li>`).join("")}</ul>` : `<p class="rag-empty">No saved suite snapshots yet.</p>`) + `</section>`;
|
|
21150
21581
|
};
|
|
21151
21582
|
var renderBenchmarkSnapshotPanel = (input) => {
|
|
21152
21583
|
const summaryRows = [
|
|
@@ -21161,16 +21592,16 @@ var renderBenchmarkSnapshotPanel = (input) => {
|
|
|
21161
21592
|
].filter((row) => Boolean(row));
|
|
21162
21593
|
const snapshotRows = input.response.snapshotHistoryPresentation?.rows ?? [];
|
|
21163
21594
|
const snapshots = input.response.snapshotHistoryPresentation?.snapshots ?? [];
|
|
21164
|
-
return `<section class="rag-status-governance"><h3>${
|
|
21595
|
+
return `<section class="rag-status-governance"><h3>${escapeHtml2(input.title)}</h3>` + renderLabelValueRows(summaryRows) + renderLabelValueRows(snapshotRows) + (snapshots.length > 0 ? `<ul class="rag-status-capabilities">${snapshots.slice(0, 3).map((snapshot) => `<li><strong>${escapeHtml2(snapshot.label)}</strong> ${escapeHtml2(snapshot.summary)}</li>`).join("")}</ul>` : `<p class="rag-empty">No saved suite snapshots yet.</p>`) + `</section>`;
|
|
21165
21596
|
};
|
|
21166
21597
|
var renderSourceLabels = (input) => {
|
|
21167
21598
|
if (!input) {
|
|
21168
21599
|
return "";
|
|
21169
21600
|
}
|
|
21170
21601
|
const rows = [
|
|
21171
|
-
input.contextLabel ? `<li><strong>Context</strong> ${
|
|
21172
|
-
input.locatorLabel ? `<li><strong>Location</strong> ${
|
|
21173
|
-
input.provenanceLabel ? `<li><strong>Provenance</strong> ${
|
|
21602
|
+
input.contextLabel ? `<li><strong>Context</strong> ${escapeHtml2(input.contextLabel)}</li>` : "",
|
|
21603
|
+
input.locatorLabel ? `<li><strong>Location</strong> ${escapeHtml2(input.locatorLabel)}</li>` : "",
|
|
21604
|
+
input.provenanceLabel ? `<li><strong>Provenance</strong> ${escapeHtml2(input.provenanceLabel)}</li>` : ""
|
|
21174
21605
|
].filter((row) => row.length > 0);
|
|
21175
21606
|
return rows.length > 0 ? `<ul class="rag-source-labels">${rows.join("")}</ul>` : "";
|
|
21176
21607
|
};
|
|
@@ -21199,12 +21630,12 @@ var renderChunkStructure = (structure) => {
|
|
|
21199
21630
|
return "";
|
|
21200
21631
|
}
|
|
21201
21632
|
const rows = [
|
|
21202
|
-
structure.section?.kind ? `<li><strong>Kind</strong> ${
|
|
21203
|
-
structure.section?.title ? `<li><strong>Section</strong> ${
|
|
21204
|
-
structure.section?.path && structure.section.path.length > 1 ? `<li><strong>Section path</strong> ${
|
|
21633
|
+
structure.section?.kind ? `<li><strong>Kind</strong> ${escapeHtml2(formatStructureKindLabel(structure.section.kind) ?? structure.section.kind)}</li>` : "",
|
|
21634
|
+
structure.section?.title ? `<li><strong>Section</strong> ${escapeHtml2(structure.section.title)}</li>` : "",
|
|
21635
|
+
structure.section?.path && structure.section.path.length > 1 ? `<li><strong>Section path</strong> ${escapeHtml2(structure.section.path.join(" > "))}</li>` : "",
|
|
21205
21636
|
typeof structure.sequence?.sectionChunkIndex === "number" && typeof structure.sequence?.sectionChunkCount === "number" ? `<li><strong>Section chunk</strong> ${structure.sequence.sectionChunkIndex + 1} of ${structure.sequence.sectionChunkCount}</li>` : "",
|
|
21206
|
-
structure.sequence?.previousChunkId ? `<li><strong>Previous</strong> ${
|
|
21207
|
-
structure.sequence?.nextChunkId ? `<li><strong>Next</strong> ${
|
|
21637
|
+
structure.sequence?.previousChunkId ? `<li><strong>Previous</strong> ${escapeHtml2(structure.sequence.previousChunkId)}</li>` : "",
|
|
21638
|
+
structure.sequence?.nextChunkId ? `<li><strong>Next</strong> ${escapeHtml2(structure.sequence.nextChunkId)}</li>` : ""
|
|
21208
21639
|
].filter((row) => row.length > 0);
|
|
21209
21640
|
return rows.length > 0 ? `<ul class="rag-chunk-structure">${rows.join("")}</ul>` : "";
|
|
21210
21641
|
};
|
|
@@ -21213,9 +21644,9 @@ var renderChunkExcerpts = (input) => {
|
|
|
21213
21644
|
return "";
|
|
21214
21645
|
}
|
|
21215
21646
|
const rows = [
|
|
21216
|
-
input.chunkExcerpt ? `<li><strong>Chunk excerpt</strong> ${
|
|
21217
|
-
input.windowExcerpt ? `<li><strong>Neighbor window</strong> ${
|
|
21218
|
-
input.sectionExcerpt ? `<li><strong>Section excerpt</strong> ${
|
|
21647
|
+
input.chunkExcerpt ? `<li><strong>Chunk excerpt</strong> ${escapeHtml2(input.chunkExcerpt)}</li>` : "",
|
|
21648
|
+
input.windowExcerpt ? `<li><strong>Neighbor window</strong> ${escapeHtml2(input.windowExcerpt)}</li>` : "",
|
|
21649
|
+
input.sectionExcerpt ? `<li><strong>Section excerpt</strong> ${escapeHtml2(input.sectionExcerpt)}</li>` : ""
|
|
21219
21650
|
].filter((row) => row.length > 0);
|
|
21220
21651
|
return rows.length > 0 ? `<ul class="rag-chunk-structure">${rows.join("")}</ul>` : "";
|
|
21221
21652
|
};
|
|
@@ -21225,17 +21656,17 @@ var renderExcerptSelection = (selection) => {
|
|
|
21225
21656
|
}
|
|
21226
21657
|
const modeLabel = selection.mode === "chunk" ? "Chunk excerpt" : selection.mode === "window" ? "Neighbor window" : "Section excerpt";
|
|
21227
21658
|
const reasonLabel = selection.reason === "single_chunk" ? "single chunk" : selection.reason === "chunk_too_narrow" ? "chunk too narrow" : selection.reason === "section_small_enough" ? "section small enough" : "section too large, used window";
|
|
21228
|
-
return `<ul class="rag-chunk-structure"><li><strong>Preferred excerpt</strong> ${
|
|
21659
|
+
return `<ul class="rag-chunk-structure"><li><strong>Preferred excerpt</strong> ${escapeHtml2(modeLabel)}</li><li><strong>Promotion reason</strong> ${escapeHtml2(reasonLabel)}</li></ul>`;
|
|
21229
21660
|
};
|
|
21230
21661
|
var renderSectionJumpList = (label, items) => {
|
|
21231
|
-
const rows = items.map((item) => item.href ? `<li><strong>${
|
|
21662
|
+
const rows = items.map((item) => item.href ? `<li><strong>${escapeHtml2(label)}</strong> <a href="${escapeHtml2(item.href)}"${item.active ? ' aria-current="true"' : ""}>${escapeHtml2(item.label)}</a></li>` : `<li><strong>${escapeHtml2(label)}</strong> ${escapeHtml2(item.label)}</li>`).join("");
|
|
21232
21663
|
return rows ? `<ul class="rag-chunk-structure">${rows}</ul>` : "";
|
|
21233
21664
|
};
|
|
21234
21665
|
var renderSectionDiagnostics = (diagnostics) => {
|
|
21235
21666
|
if (diagnostics.length === 0) {
|
|
21236
21667
|
return "";
|
|
21237
21668
|
}
|
|
21238
|
-
return `<section class="rag-search-results"><h3>Section diagnostics</h3>` + diagnostics.map((diagnostic) => `<article class="rag-search-result" id="rag-section-diagnostic-${
|
|
21669
|
+
return `<section class="rag-search-results"><h3>Section diagnostics</h3>` + diagnostics.map((diagnostic) => `<article class="rag-search-result" id="rag-section-diagnostic-${escapeHtml2(diagnostic.key)}">` + `<h4>${escapeHtml2(diagnostic.path?.join(" > ") ?? diagnostic.label)}</h4>` + `<p class="rag-search-source">${escapeHtml2(diagnostic.summary)}</p>` + `<ul class="rag-source-labels">` + `<li><strong>Top hit</strong> ${diagnostic.bestScore.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES)}</li>` + `<li><strong>Average</strong> ${diagnostic.averageScore.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES)}</li>` + `<li><strong>Sources</strong> ${diagnostic.sourceCount}</li>` + `<li><strong>Channels</strong> vector ${diagnostic.vectorHits} \xB7 lexical ${diagnostic.lexicalHits} \xB7 hybrid ${diagnostic.hybridHits}</li>` + `${diagnostic.topContextLabel ? `<li><strong>Lead context</strong> ${escapeHtml2(diagnostic.topContextLabel)}</li>` : ""}` + `${diagnostic.topLocatorLabel ? `<li><strong>Lead location</strong> ${escapeHtml2(diagnostic.topLocatorLabel)}</li>` : ""}` + `${diagnostic.sourceAwareChunkReasonLabel ? `<li><strong>Chunk boundary</strong> ${escapeHtml2(diagnostic.sourceAwareChunkReasonLabel)}</li>` : ""}` + `${diagnostic.sourceAwareUnitScopeLabel ? `<li><strong>Source-aware scope</strong> ${escapeHtml2(diagnostic.sourceAwareUnitScopeLabel)}</li>` : ""}` + `${diagnostic.stageCounts.length > 0 ? `<li><strong>Stage flow</strong> ${escapeHtml2(diagnostic.stageCounts.map((entry) => `${entry.stage} ${entry.count}`).join(" \u2192 "))}</li>` : ""}` + `${diagnostic.firstSeenStage ? `<li><strong>First seen</strong> ${escapeHtml2(diagnostic.firstSeenStage)}</li>` : ""}` + `${diagnostic.lastSeenStage ? `<li><strong>Last seen</strong> ${escapeHtml2(diagnostic.lastSeenStage)}</li>` : ""}` + `<li><strong>Query attribution</strong> ${escapeHtml2(`${diagnostic.queryAttribution.mode} \xB7 primary ${diagnostic.queryAttribution.primaryHits} \xB7 transformed ${diagnostic.queryAttribution.transformedHits} \xB7 variant ${diagnostic.queryAttribution.variantHits}`)}</li>` + `${diagnostic.queryAttribution.reasons.length > 0 ? `<li><strong>Query attribution reasons</strong> ${escapeHtml2(diagnostic.queryAttribution.reasons.join(", "))}</li>` : ""}` + `${diagnostic.peakStage ? `<li><strong>Peak stage</strong> ${escapeHtml2(diagnostic.peakStage)} (${diagnostic.peakCount})</li>` : ""}` + `${typeof diagnostic.finalRetentionRate === "number" ? `<li><strong>Final retention</strong> ${(diagnostic.finalRetentionRate * 100).toFixed(0)}%</li>` : ""}` + `${typeof diagnostic.dropFromPeak === "number" ? `<li><strong>Drop from peak</strong> ${diagnostic.dropFromPeak}</li>` : ""}` + `${diagnostic.retrievalMode ? `<li><strong>Trace mode</strong> ${escapeHtml2(diagnostic.retrievalMode)}</li>` : ""}` + `${diagnostic.rerankApplied !== undefined ? `<li><strong>Rerank</strong> ${diagnostic.rerankApplied ? "applied" : "skipped"}</li>` : ""}` + `${diagnostic.sourceBalanceApplied ? `<li><strong>Source balance</strong> applied</li>` : ""}` + `${diagnostic.scoreThresholdApplied ? `<li><strong>Score threshold</strong> applied</li>` : ""}` + `<li><strong>Reasons</strong> ${escapeHtml2(diagnostic.reasons.join(", ") || "none")}</li>` + `${diagnostic.strongestSiblingLabel ? `<li><strong>Strongest sibling</strong> ${escapeHtml2(diagnostic.strongestSiblingLabel)} (${diagnostic.strongestSiblingScore?.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES) ?? "n/a"})</li>` : ""}` + `${typeof diagnostic.parentShareGap === "number" ? `<li><strong>Parent share gap</strong> ${(diagnostic.parentShareGap * 100).toFixed(0)}%</li>` : ""}` + `</ul>` + `${diagnostic.stageWeights.length > 0 ? `<ul class="rag-source-labels">${diagnostic.stageWeights.map((entry) => `<li><strong>${escapeHtml2(entry.stage)}</strong> ${(entry.stageShare * 100).toFixed(0)}% of stage` + `${typeof entry.retentionRate === "number" ? ` \xB7 ${(entry.retentionRate * 100).toFixed(0)}% retained from ${escapeHtml2(entry.previousStage ?? "previous")}` : ""}` + `${typeof entry.countDelta === "number" ? ` \xB7 delta ${entry.countDelta >= 0 ? "+" : ""}${entry.countDelta}` : ""}` + `${typeof entry.stageScoreShare === "number" ? ` \xB7 ${(entry.stageScoreShare * 100).toFixed(0)}% of stage score` : ""}` + `${typeof entry.parentStageScoreShare === "number" ? ` \xB7 ${(entry.parentStageScoreShare * 100).toFixed(0)}% of parent stage score` : ""}` + `${typeof entry.stageScoreShareGap === "number" ? ` \xB7 score gap ${(entry.stageScoreShareGap * 100).toFixed(0)}%` : ""}` + `${typeof entry.parentStageShare === "number" ? ` \xB7 ${(entry.parentStageShare * 100).toFixed(0)}% of parent stage` : ""}` + `${typeof entry.stageShareGap === "number" ? ` \xB7 gap ${(entry.stageShareGap * 100).toFixed(0)}%` : ""}` + `${entry.strongestSiblingLabel ? ` \xB7 runner-up ${escapeHtml2(entry.strongestSiblingLabel)}` : ""}` + `${entry.reasons.length > 0 ? ` \xB7 ${escapeHtml2(entry.reasons.join(", "))}` : ""}</li>`).join("")}</ul>` : ""}` + `${diagnostic.parentDistribution.length > 0 ? `<ul class="rag-source-labels">${diagnostic.parentDistribution.map((entry) => `<li><strong>${entry.isActive ? "Active section" : "Peer section"}</strong> ${escapeHtml2(entry.label)} \xB7 ${(entry.parentShare * 100).toFixed(0)}% \xB7 ${entry.count} hit${entry.count === 1 ? "" : "s"}</li>`).join("")}</ul>` : ""}` + `</article>`).join("") + `</section>`;
|
|
21239
21670
|
};
|
|
21240
21671
|
var renderEmptyState = (kind) => {
|
|
21241
21672
|
switch (kind) {
|
|
@@ -21264,7 +21695,7 @@ var renderCapabilityList = (capabilities) => {
|
|
|
21264
21695
|
`serverSideFiltering=${capabilities.serverSideFiltering ? "true" : "false"}`,
|
|
21265
21696
|
`streamingIngestStatus=${capabilities.streamingIngestStatus ? "true" : "false"}`
|
|
21266
21697
|
];
|
|
21267
|
-
return `<ul class="rag-status-capabilities">${items.map((item) => `<li>${
|
|
21698
|
+
return `<ul class="rag-status-capabilities">${items.map((item) => `<li>${escapeHtml2(item)}</li>`).join("")}</ul>`;
|
|
21268
21699
|
};
|
|
21269
21700
|
var formatByteSize = (value) => {
|
|
21270
21701
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
@@ -21292,7 +21723,7 @@ var renderPostgresNativeStatus = (status) => {
|
|
|
21292
21723
|
status.native.lastReindexError ? `Native index rebuild failed: ${status.native.lastReindexError}` : "",
|
|
21293
21724
|
typeof status.native.indexBytes === "number" && typeof status.native.totalBytes === "number" && status.native.totalBytes > 0 && status.native.indexBytes / status.native.totalBytes >= 0.7 ? "Index-heavy storage footprint" : ""
|
|
21294
21725
|
].filter((entry) => entry.length > 0);
|
|
21295
|
-
return `<dl class="rag-status">` + `<div><dt>Index type</dt><dd>${
|
|
21726
|
+
return `<dl class="rag-status">` + `<div><dt>Index type</dt><dd>${escapeHtml2(status.native.indexType ?? "n/a")}</dd></div>` + `<div><dt>Index name</dt><dd>${escapeHtml2(status.native.indexName ?? "n/a")}</dd></div>` + `<div><dt>Index present</dt><dd>${typeof status.native.indexPresent === "boolean" ? status.native.indexPresent ? "true" : "false" : "n/a"}</dd></div>` + `<div><dt>Estimated rows</dt><dd>${typeof status.native.estimatedRowCount === "number" ? String(status.native.estimatedRowCount) : "n/a"}</dd></div>` + `<div><dt>Table bytes</dt><dd>${formatByteSize(status.native.tableBytes)}</dd></div>` + `<div><dt>Index bytes</dt><dd>${formatByteSize(status.native.indexBytes)}</dd></div>` + `<div><dt>Total bytes</dt><dd>${formatByteSize(status.native.totalBytes)}</dd></div>` + `<div><dt>Health check</dt><dd>${typeof status.native.lastHealthCheckAt === "number" ? escapeHtml2(new Date(status.native.lastHealthCheckAt).toLocaleString("en-US")) : "n/a"}</dd></div>` + `<div><dt>Last analyze</dt><dd>${typeof status.native.lastAnalyzeAt === "number" ? escapeHtml2(new Date(status.native.lastAnalyzeAt).toLocaleString("en-US")) : "n/a"}</dd></div>` + `<div><dt>Last index rebuild</dt><dd>${typeof status.native.lastReindexAt === "number" ? escapeHtml2(new Date(status.native.lastReindexAt).toLocaleString("en-US")) : "n/a"}</dd></div>` + `</dl>` + (warnings.length > 0 ? `<ul class="rag-status-capabilities">${warnings.map((warning) => `<li>${escapeHtml2(warning)}</li>`).join("")}</ul>` : "");
|
|
21296
21727
|
};
|
|
21297
21728
|
var renderSQLiteNativeStatus = (status) => {
|
|
21298
21729
|
if (status?.backend !== "sqlite" || !status.native || !("mode" in status.native) || status.native.mode !== "vec0") {
|
|
@@ -21304,15 +21735,15 @@ var renderSQLiteNativeStatus = (status) => {
|
|
|
21304
21735
|
status.native.lastAnalyzeError ? `Analyze failed: ${status.native.lastAnalyzeError}` : "",
|
|
21305
21736
|
typeof status.native.pageCount === "number" && typeof status.native.freelistCount === "number" && status.native.pageCount > 0 && status.native.freelistCount / status.native.pageCount >= 0.2 ? "SQLite freelist growth suggests running optimize" : ""
|
|
21306
21737
|
].filter((entry) => entry.length > 0);
|
|
21307
|
-
return `<dl class="rag-status">` + `<div><dt>Native table</dt><dd>${
|
|
21738
|
+
return `<dl class="rag-status">` + `<div><dt>Native table</dt><dd>${escapeHtml2(status.native.tableName ?? "n/a")}</dd></div>` + `<div><dt>Distance metric</dt><dd>${escapeHtml2(status.native.distanceMetric ?? "n/a")}</dd></div>` + `<div><dt>Native active</dt><dd>${status.native.active ? "true" : "false"}</dd></div>` + `<div><dt>Row count</dt><dd>${typeof status.native.rowCount === "number" ? String(status.native.rowCount) : "n/a"}</dd></div>` + `<div><dt>Database bytes</dt><dd>${formatByteSize(status.native.databaseBytes)}</dd></div>` + `<div><dt>Page count</dt><dd>${typeof status.native.pageCount === "number" ? String(status.native.pageCount) : "n/a"}</dd></div>` + `<div><dt>Freelist pages</dt><dd>${typeof status.native.freelistCount === "number" ? String(status.native.freelistCount) : "n/a"}</dd></div>` + `<div><dt>Health check</dt><dd>${typeof status.native.lastHealthCheckAt === "number" ? escapeHtml2(new Date(status.native.lastHealthCheckAt).toLocaleString("en-US")) : "n/a"}</dd></div>` + `<div><dt>Last analyze</dt><dd>${typeof status.native.lastAnalyzeAt === "number" ? escapeHtml2(new Date(status.native.lastAnalyzeAt).toLocaleString("en-US")) : "n/a"}</dd></div>` + `</dl>` + (warnings.length > 0 ? `<ul class="rag-status-capabilities">${warnings.map((warning) => `<li>${escapeHtml2(warning)}</li>`).join("")}</ul>` : "");
|
|
21308
21739
|
};
|
|
21309
21740
|
var renderStatusActions = (input) => {
|
|
21310
21741
|
if (!input.path) {
|
|
21311
21742
|
return "";
|
|
21312
21743
|
}
|
|
21313
21744
|
const actions = [
|
|
21314
|
-
input.admin?.canAnalyzeBackend ? `<button type="button" hx-post="${
|
|
21315
|
-
input.status?.backend === "postgres" && input.admin?.canRebuildNativeIndex ? `<button type="button" hx-post="${
|
|
21745
|
+
input.admin?.canAnalyzeBackend ? `<button type="button" hx-post="${escapeHtml2(`${input.path}/backend/analyze`)}" hx-target="#rag-status-feedback" hx-swap="innerHTML">Analyze backend</button>` : "",
|
|
21746
|
+
input.status?.backend === "postgres" && input.admin?.canRebuildNativeIndex ? `<button type="button" hx-post="${escapeHtml2(`${input.path}/backend/reindex-native`)}" hx-target="#rag-status-feedback" hx-swap="innerHTML">Rebuild native index</button>` : ""
|
|
21316
21747
|
].filter((entry) => entry.length > 0);
|
|
21317
21748
|
if (actions.length === 0) {
|
|
21318
21749
|
return "";
|
|
@@ -21339,7 +21770,7 @@ var renderBackendMaintenance = (input) => {
|
|
|
21339
21770
|
if (recommendations.length === 0 && activeJobs.length === 0 && recentActions.length === 0) {
|
|
21340
21771
|
return "";
|
|
21341
21772
|
}
|
|
21342
|
-
return `<section class="rag-status-maintenance">` + `<h3>Backend maintenance</h3>` + (recommendations.length > 0 ? `<ul class="rag-status-capabilities">${recommendations.map((entry) => `<li>${
|
|
21773
|
+
return `<section class="rag-status-maintenance">` + `<h3>Backend maintenance</h3>` + (recommendations.length > 0 ? `<ul class="rag-status-capabilities">${recommendations.map((entry) => `<li>${escapeHtml2(entry)}</li>`).join("")}</ul>` : '<p class="rag-empty">No immediate maintenance recommendations.</p>') + (activeJobs.length > 0 ? `<ul class="rag-status-capabilities">${activeJobs.map((job) => `<li><strong>Running</strong> ${escapeHtml2(job.action)}${job.target ? ` \xB7 ${escapeHtml2(job.target)}` : ""}</li>`).join("")}</ul>` : "") + (recentActions.length > 0 ? `<ul class="rag-status-capabilities">${recentActions.map((action) => `<li><strong>${escapeHtml2(action.action)}</strong> ${escapeHtml2(action.status)}${typeof action.finishedAt === "number" ? ` \xB7 ${escapeHtml2(new Date(action.finishedAt).toLocaleString("en-US"))}` : ""}${action.error ? ` \xB7 ${escapeHtml2(action.error)}` : ""}</li>`).join("")}</ul>` : "") + `</section>`;
|
|
21343
21774
|
};
|
|
21344
21775
|
var renderMaintenancePanel = (input) => {
|
|
21345
21776
|
input.maintenance;
|
|
@@ -21350,7 +21781,7 @@ var renderMaintenancePanel = (input) => {
|
|
|
21350
21781
|
status: input.status
|
|
21351
21782
|
}) || (input.status && input.status.backend !== "in_memory" ? `<section class="rag-status-maintenance"><h3>Backend maintenance</h3><p class="rag-empty">No immediate maintenance recommendations.</p></section>` : renderEmptyState("status"));
|
|
21352
21783
|
const route = input.path ? `${input.path}/status/maintenance` : undefined;
|
|
21353
|
-
return route ? `<div id="rag-status-maintenance-panel" hx-get="${
|
|
21784
|
+
return route ? `<div id="rag-status-maintenance-panel" hx-get="${escapeHtml2(route)}" hx-trigger="load, rag:mutated from:body" hx-swap="outerHTML">${content}</div>` : `<div id="rag-status-maintenance-panel">${content}</div>`;
|
|
21354
21785
|
};
|
|
21355
21786
|
var renderRetrievalGovernancePanel = (retrievalComparisons) => {
|
|
21356
21787
|
if (!retrievalComparisons?.latest && !retrievalComparisons?.alerts?.length) {
|
|
@@ -21360,9 +21791,9 @@ var renderRetrievalGovernancePanel = (retrievalComparisons) => {
|
|
|
21360
21791
|
const alerts = (retrievalComparisons.alerts ?? []).slice(0, 3);
|
|
21361
21792
|
const releaseGroups = (retrievalComparisons.releaseGroups ?? []).slice(0, 2);
|
|
21362
21793
|
const formatClassification = (classification) => classification === "multivector" ? "multivector regression" : classification === "evidence" ? "evidence regression" : classification === "cue" ? "cue regression" : classification === "runtime" ? "runtime regression" : classification === "general" ? "general regression" : undefined;
|
|
21363
|
-
return `<section class="rag-status-governance"><h3>Retrieval governance</h3>` + (latest ? `<dl class="rag-status">` + `<div><dt>Latest comparison</dt><dd>${
|
|
21794
|
+
return `<section class="rag-status-governance"><h3>Retrieval governance</h3>` + (latest ? `<dl class="rag-status">` + `<div><dt>Latest comparison</dt><dd>${escapeHtml2(latest.label)}</dd></div>` + (latest.bestByPassingRate ? `<div><dt>Best passing rate</dt><dd>${escapeHtml2(latest.bestByPassingRate)}</dd></div>` : "") + (latest.bestByAverageF1 ? `<div><dt>Best average F1</dt><dd>${escapeHtml2(latest.bestByAverageF1)}</dd></div>` : "") + (latest.bestByMultivectorCollapsedCases ? `<div><dt>Best multivector collapse</dt><dd>${escapeHtml2(latest.bestByMultivectorCollapsedCases)}</dd></div>` : "") + (latest.bestByMultivectorLexicalHitCases ? `<div><dt>Best multivector lexical hits</dt><dd>${escapeHtml2(latest.bestByMultivectorLexicalHitCases)}</dd></div>` : "") + (latest.bestByMultivectorVectorHitCases ? `<div><dt>Best multivector vector hits</dt><dd>${escapeHtml2(latest.bestByMultivectorVectorHitCases)}</dd></div>` : "") + (latest.decisionSummary?.gate?.status ? `<div><dt>Gate</dt><dd>${escapeHtml2(latest.decisionSummary.gate.status)}</dd></div>` : "") + (latest.releaseVerdict?.status ? `<div><dt>Verdict</dt><dd>${escapeHtml2(latest.releaseVerdict.status)}</dd></div>` : "") + `</dl>` : "") + `<h4>Active alerts</h4>` + (alerts.length > 0 ? `<ul class="rag-status-capabilities">${alerts.map((alert) => `<li><strong>${escapeHtml2(alert.kind)}</strong>${formatClassification(alert.classification) ? ` <span>${escapeHtml2(formatClassification(alert.classification) ?? "")}</span>` : ""} ${escapeHtml2(alert.message)}</li>`).join("")}</ul>` : `<p class="rag-empty">No active retrieval comparison alerts.</p>`) + (releaseGroups.length > 0 ? `<h4>Release groups</h4><ul class="rag-status-capabilities">${releaseGroups.map((group) => {
|
|
21364
21795
|
const reasons = group.recommendedActionReasons?.slice(0, 2).join("; ") ?? "No recommended action.";
|
|
21365
|
-
return `<li><strong>${
|
|
21796
|
+
return `<li><strong>${escapeHtml2(group.groupKey)}</strong>${formatClassification(group.classification) ? ` <span>${escapeHtml2(formatClassification(group.classification) ?? "")}</span>` : ""} ${escapeHtml2(group.recommendedAction ?? "monitor")} \xB7 ${escapeHtml2(reasons)}</li>`;
|
|
21366
21797
|
}).join("")}</ul>` : "") + `</section>`;
|
|
21367
21798
|
};
|
|
21368
21799
|
var defaultStatus = ({
|
|
@@ -21379,7 +21810,7 @@ var defaultStatus = ({
|
|
|
21379
21810
|
if (!status) {
|
|
21380
21811
|
return renderEmptyState("status");
|
|
21381
21812
|
}
|
|
21382
|
-
return `<section class="rag-status-panel">` + `<dl class="rag-status">` + `<div><dt>Backend</dt><dd>${
|
|
21813
|
+
return `<section class="rag-status-panel">` + `<dl class="rag-status">` + `<div><dt>Backend</dt><dd>${escapeHtml2(status.backend)}</dd></div>` + `<div><dt>Vector mode</dt><dd>${escapeHtml2(status.vectorMode)}</dd></div>` + `<div><dt>Embedding dimensions</dt><dd>${status.dimensions ?? "n/a"}</dd></div>` + `<div><dt>Vector acceleration</dt><dd>${status.native?.active ? "active" : "inactive"}</dd></div>` + `<div><dt>Documents</dt><dd>${documents?.total ?? "n/a"}</dd></div>` + `<div><dt>Total chunks</dt><dd>${documents?.chunkCount ?? "n/a"}</dd></div>` + `<div><dt>Seed docs</dt><dd>${documents?.byKind.seed ?? 0}</dd></div>` + `<div><dt>Custom docs</dt><dd>${documents?.byKind.custom ?? 0}</dd></div>` + `</dl>${renderPostgresNativeStatus(status)}${renderSQLiteNativeStatus(status)}${renderRetrievalGovernancePanel(retrievalComparisons)}${renderMaintenancePanel({
|
|
21383
21814
|
admin,
|
|
21384
21815
|
adminActions,
|
|
21385
21816
|
adminJobs,
|
|
@@ -21392,7 +21823,7 @@ var defaultStatus = ({
|
|
|
21392
21823
|
status
|
|
21393
21824
|
})}</section>`;
|
|
21394
21825
|
};
|
|
21395
|
-
var defaultSearchResultItem = (source, index, sectionJumps = "") => `<article class="rag-search-result" id="rag-search-result-${
|
|
21826
|
+
var defaultSearchResultItem = (source, index, sectionJumps = "") => `<article class="rag-search-result" id="rag-search-result-${escapeHtml2(source.chunkId)}">` + `<h3>${escapeHtml2(source.title ?? source.chunkId ?? `Result ${index + 1}`)}</h3>` + `<p class="rag-search-source">${escapeHtml2(source.source ?? "unknown source")}</p>` + renderSourceLabels(source.labels) + renderChunkStructure(source.structure) + sectionJumps + `<p class="rag-search-score">score ${source.score.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES)}</p>` + `<p class="rag-search-text">${escapeHtml2(source.text)}</p>` + "</article>";
|
|
21396
21827
|
var defaultSearchResults = ({
|
|
21397
21828
|
query,
|
|
21398
21829
|
results,
|
|
@@ -21401,7 +21832,7 @@ var defaultSearchResults = ({
|
|
|
21401
21832
|
const graph = buildRAGChunkGraph(results);
|
|
21402
21833
|
const sectionDiagnostics = buildRAGSectionRetrievalDiagnostics(results, trace);
|
|
21403
21834
|
const availableChunkIds = new Set(results.map((result) => result.chunkId));
|
|
21404
|
-
return `<section class="rag-search-results">` + `<p class="rag-search-summary">${results.length} results for ${
|
|
21835
|
+
return `<section class="rag-search-results">` + `<p class="rag-search-summary">${results.length} results for ${escapeHtml2(query)}</p>` + `<p class="rag-search-summary">sections=${sectionDiagnostics.length}</p>` + (trace ? `<p class="rag-search-summary">mode=${escapeHtml2(trace.mode)} \xB7 final=${trace.resultCounts.final} \xB7 vector=${trace.resultCounts.vector} \xB7 lexical=${trace.resultCounts.lexical}</p>` : "") + renderSectionDiagnostics(sectionDiagnostics) + `${results.map((result, index) => {
|
|
21405
21836
|
const navigation = buildRAGChunkGraphNavigation(graph, result.chunkId);
|
|
21406
21837
|
const sectionJumps = [
|
|
21407
21838
|
navigation.parentSection?.leadChunkId ? renderSectionJumpList("Parent section", [
|
|
@@ -21455,7 +21886,7 @@ var defaultSpreadsheetCueBenchmarkSnapshot = (input) => renderBenchmarkSnapshotP
|
|
|
21455
21886
|
response: input,
|
|
21456
21887
|
title: "Spreadsheet cue snapshots"
|
|
21457
21888
|
});
|
|
21458
|
-
var defaultDocumentItem = (document, index) => '<article class="rag-document">' + `<h3>${
|
|
21889
|
+
var defaultDocumentItem = (document, index) => '<article class="rag-document">' + `<h3>${escapeHtml2(document.title || `Document ${index + 1}`)}</h3>` + `<p class="rag-document-id">${escapeHtml2(document.id)}</p>` + `<p class="rag-document-source">${escapeHtml2(document.source)}</p>` + renderSourceLabels(document.labels) + `<p class="rag-document-meta">${escapeHtml2(document.format ?? "text")} \xB7 ${escapeHtml2(document.chunkStrategy ?? "paragraphs")} \xB7 ${document.chunkCount ?? 0} chunks</p>` + "</article>";
|
|
21459
21890
|
var defaultDocuments = ({
|
|
21460
21891
|
documents
|
|
21461
21892
|
}) => documents.length === 0 ? renderEmptyState("documents") : `<section class="rag-documents">${documents.map((document, index) => defaultDocumentItem(document, index)).join("")}</section>`;
|
|
@@ -21481,10 +21912,10 @@ var defaultChunkPreview = (input) => {
|
|
|
21481
21912
|
return acc;
|
|
21482
21913
|
}, []);
|
|
21483
21914
|
const groupHtml = groups.map((group) => {
|
|
21484
|
-
const chunkHtml = group.chunks.map((chunk) => '<article class="rag-chunk">' + `<h5>${
|
|
21485
|
-
return `<section class="rag-chunk-group"><h4>${
|
|
21915
|
+
const chunkHtml = group.chunks.map((chunk) => '<article class="rag-chunk">' + `<h5>${escapeHtml2(chunk.chunkId)}</h5>` + `<p class="rag-chunk-meta">chunk ${typeof chunk.metadata?.chunkIndex === "number" ? chunk.metadata.chunkIndex : 0} of ${typeof chunk.metadata?.chunkCount === "number" ? chunk.metadata.chunkCount : input.chunks.length}</p>` + renderSourceLabels(chunk.labels) + renderChunkStructure(chunk.structure) + renderChunkExcerpts(chunk.excerpts) + renderExcerptSelection(chunk.excerptSelection) + `<pre>${escapeHtml2(chunk.text)}</pre>` + "</article>").join("");
|
|
21916
|
+
return `<section class="rag-chunk-group"><h4>${escapeHtml2(group.title)}</h4>${chunkHtml}</section>`;
|
|
21486
21917
|
}).join("");
|
|
21487
|
-
return `<section class="rag-chunk-preview">` + `<h3>${
|
|
21918
|
+
return `<section class="rag-chunk-preview">` + `<h3>${escapeHtml2(input.document.title)}</h3>` + `<p class="rag-chunk-preview-source">${escapeHtml2(input.document.source)}</p>` + renderSourceLabels(input.document.labels) + (navigation.parentSection ? renderSectionJumpList("Parent section", [
|
|
21488
21919
|
{
|
|
21489
21920
|
label: navigation.parentSection.title ?? navigation.parentSection.path?.join(" > ") ?? navigation.parentSection.id
|
|
21490
21921
|
}
|
|
@@ -21492,11 +21923,11 @@ var defaultChunkPreview = (input) => {
|
|
|
21492
21923
|
label: section.title ?? section.path?.join(" > ") ?? section.id
|
|
21493
21924
|
}))) : "") + (navigation.childSections.length > 0 ? renderSectionJumpList("Child section", navigation.childSections.map((section) => ({
|
|
21494
21925
|
label: section.title ?? section.path?.join(" > ") ?? section.id
|
|
21495
|
-
}))) : "") + `<article class="rag-chunk-normalized">` + `<h4>Normalized text</h4>` + `<pre>${
|
|
21926
|
+
}))) : "") + `<article class="rag-chunk-normalized">` + `<h4>Normalized text</h4>` + `<pre>${escapeHtml2(input.normalizedText)}</pre>` + `</article>${groupHtml}</section>`;
|
|
21496
21927
|
};
|
|
21497
21928
|
var defaultMutationResult = (input) => {
|
|
21498
21929
|
if (!input.ok) {
|
|
21499
|
-
return `<div class="rag-mutation error">${
|
|
21930
|
+
return `<div class="rag-mutation error">${escapeHtml2(input.error ?? "Request failed")}</div>`;
|
|
21500
21931
|
}
|
|
21501
21932
|
const details = [];
|
|
21502
21933
|
if (input.status) {
|
|
@@ -21511,7 +21942,7 @@ var defaultMutationResult = (input) => {
|
|
|
21511
21942
|
if (typeof input.documents === "number") {
|
|
21512
21943
|
details.push(`documents=${input.documents}`);
|
|
21513
21944
|
}
|
|
21514
|
-
return `<div class="rag-mutation ok">${
|
|
21945
|
+
return `<div class="rag-mutation ok">${escapeHtml2(details.join(" \xB7 ") || "ok")}</div>`;
|
|
21515
21946
|
};
|
|
21516
21947
|
var defaultEvaluateResult = ({
|
|
21517
21948
|
cases,
|
|
@@ -21520,11 +21951,11 @@ var defaultEvaluateResult = ({
|
|
|
21520
21951
|
if (cases.length === 0) {
|
|
21521
21952
|
return renderEmptyState("evaluation");
|
|
21522
21953
|
}
|
|
21523
|
-
const caseRows = cases.map((entry) => `<tr class="rag-eval-row rag-eval-${entry.status}">` + `<td>${
|
|
21954
|
+
const caseRows = cases.map((entry) => `<tr class="rag-eval-row rag-eval-${entry.status}">` + `<td>${escapeHtml2(entry.caseId)}</td>` + `<td>${escapeHtml2(entry.mode)}</td>` + `<td>${escapeHtml2(entry.status)}</td>` + `<td>${entry.elapsedMs}</td>` + `<td>${entry.retrievedCount}</td>` + `<td>${entry.expectedCount}</td>` + `<td>${entry.matchedCount}</td>` + `<td>${entry.precision.toFixed(4)}</td>` + `<td>${entry.recall.toFixed(4)}</td>` + `<td>${entry.f1.toFixed(4)}</td>` + `<td>${escapeHtml2(entry.label ?? "n/a")}</td>` + `<td>${escapeHtml2(entry.missingIds.join(", ") || "none")}</td>` + `</tr>`).join("");
|
|
21524
21955
|
const passingRate = summary.totalCases > 0 ? (summary.passedCases / summary.totalCases * 100).toFixed(1) : "0.0";
|
|
21525
21956
|
return `<section class="rag-evaluation">` + `<h3>Evaluation</h3>` + `<p>${summary.totalCases} cases \xB7 ${summary.passedCases} pass \xB7 ${summary.partialCases} partial \xB7 ${summary.failedCases} fail \xB7 passing ${passingRate}%</p>` + `<table class="rag-eval-table"><thead><tr><th>Case</th><th>Mode</th><th>Status</th><th>ms</th><th>Retrieved</th><th>Expected</th><th>Matched</th><th>Precision</th><th>Recall</th><th>F1</th><th>Label</th><th>Missing</th></tr></thead><tbody>${caseRows}</tbody></table>` + `<dl class="rag-eval-summary"><div><dt>Average precision</dt><dd>${summary.averagePrecision.toFixed(4)}</dd></div><div><dt>Average recall</dt><dd>${summary.averageRecall.toFixed(4)}</dd></div><div><dt>Average F1</dt><dd>${summary.averageF1.toFixed(4)}</dd></div><div><dt>Average latency</dt><dd>${summary.averageLatencyMs.toFixed(1)}ms</dd></div></dl>` + `</section>`;
|
|
21526
21957
|
};
|
|
21527
|
-
var defaultError = (message) => `<div class="rag-error">${
|
|
21958
|
+
var defaultError = (message) => `<div class="rag-error">${escapeHtml2(message)}</div>`;
|
|
21528
21959
|
var defaultMaintenance = (input) => renderMaintenancePanel(input);
|
|
21529
21960
|
var resolveRAGWorkflowRenderers = (custom) => ({
|
|
21530
21961
|
adaptiveNativePlannerBenchmark: custom?.adaptiveNativePlannerBenchmark ?? defaultAdaptiveNativePlannerBenchmark,
|
|
@@ -37649,5 +38080,5 @@ export {
|
|
|
37649
38080
|
addRAGEvaluationSuiteCase
|
|
37650
38081
|
};
|
|
37651
38082
|
|
|
37652
|
-
//# debugId=
|
|
38083
|
+
//# debugId=1EFB64CE5660478364756E2164756E21
|
|
37653
38084
|
//# sourceMappingURL=index.js.map
|