@absolutejs/absolute 0.19.0-beta.603 → 0.19.0-beta.605

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.
Files changed (39) hide show
  1. package/dist/ai/client/index.js +244 -10
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +248 -10
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +1003 -110
  6. package/dist/ai/index.js.map +8 -8
  7. package/dist/ai/rag/quality.js +27 -6
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +248 -10
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +243 -9
  12. package/dist/ai-client/react/ai/index.js +258 -10
  13. package/dist/ai-client/vue/ai/index.js +347 -101
  14. package/dist/angular/ai/index.js +244 -10
  15. package/dist/angular/ai/index.js.map +4 -4
  16. package/dist/react/ai/index.js +259 -11
  17. package/dist/react/ai/index.js.map +6 -6
  18. package/dist/src/ai/client/ui.d.ts +1 -1
  19. package/dist/src/ai/rag/index.d.ts +1 -1
  20. package/dist/src/ai/rag/presentation.d.ts +12 -1
  21. package/dist/src/ai/rag/ui.d.ts +1 -1
  22. package/dist/src/react/ai/useRAG.d.ts +5 -0
  23. package/dist/src/react/ai/useRAGChunkPreview.d.ts +4 -0
  24. package/dist/src/react/ai/useRAGSources.d.ts +1 -0
  25. package/dist/src/svelte/ai/createRAG.d.ts +5 -0
  26. package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +4 -0
  27. package/dist/src/svelte/ai/createRAGSources.d.ts +1 -0
  28. package/dist/src/vue/ai/useRAG.d.ts +125 -0
  29. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +54 -0
  30. package/dist/src/vue/ai/useRAGDocuments.d.ts +20 -0
  31. package/dist/src/vue/ai/useRAGIndexAdmin.d.ts +10 -0
  32. package/dist/src/vue/ai/useRAGSearch.d.ts +40 -0
  33. package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
  34. package/dist/svelte/ai/index.js +305 -57
  35. package/dist/svelte/ai/index.js.map +6 -6
  36. package/dist/types/ai.d.ts +102 -1
  37. package/dist/vue/ai/index.js +311 -63
  38. package/dist/vue/ai/index.js.map +6 -6
  39. package/package.json +1 -1
@@ -738,6 +738,10 @@ var buildContextLabel = (metadata) => {
738
738
  return from ? `Message from ${from}` : "Message evidence";
739
739
  }
740
740
  const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
741
+ const region = getContextNumber(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
742
+ if (page && region) {
743
+ return `Page ${page} region ${region}`;
744
+ }
741
745
  if (page) {
742
746
  return `Page ${page}`;
743
747
  }
@@ -761,6 +765,11 @@ var buildContextLabel = (metadata) => {
761
765
  if (speaker) {
762
766
  return `Speaker ${speaker}`;
763
767
  }
768
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
769
+ const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
770
+ if (sectionTitle) {
771
+ return `Section ${sectionTitle}`;
772
+ }
764
773
  return;
765
774
  };
766
775
  var formatMediaTimestamp = (value) => {
@@ -778,6 +787,10 @@ var buildLocatorLabel = (metadata, source, title) => {
778
787
  return;
779
788
  }
780
789
  const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
790
+ const region = getContextNumber(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
791
+ if (page && region) {
792
+ return `Page ${page} · Region ${region}`;
793
+ }
781
794
  if (page) {
782
795
  return `Page ${page}`;
783
796
  }
@@ -806,6 +819,10 @@ var buildLocatorLabel = (metadata, source, title) => {
806
819
  if (mediaStart) {
807
820
  return `Timestamp ${mediaStart}`;
808
821
  }
822
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
823
+ if (sectionPath.length > 0) {
824
+ return `Section ${sectionPath.join(" > ")}`;
825
+ }
809
826
  return;
810
827
  };
811
828
  var formatTimestampLabel = (value) => {
@@ -830,9 +847,11 @@ var buildProvenanceLabel = (metadata) => {
830
847
  const transcriptSource = getContextString(metadata.transcriptSource);
831
848
  const pdfTextMode = getContextString(metadata.pdfTextMode);
832
849
  const ocrEngine = getContextString(metadata.ocrEngine);
850
+ const ocrConfidence = getContextNumber(metadata.ocrRegionConfidence) ?? getContextNumber(metadata.ocrConfidence);
833
851
  const labels = [
834
852
  pdfTextMode ? `PDF ${pdfTextMode}` : "",
835
853
  ocrEngine ? `OCR ${ocrEngine}` : "",
854
+ typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
836
855
  mediaKind ? `Media ${mediaKind}` : "",
837
856
  transcriptSource ? `Transcript ${transcriptSource}` : "",
838
857
  threadTopic ? `Thread ${threadTopic}` : "",
@@ -853,8 +872,10 @@ var buildExcerpt = (text, maxLength = 160) => {
853
872
  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(" · ");
854
873
  var buildGroundingReferenceEvidenceSummary = (reference) => [
855
874
  reference.source ?? reference.title ?? reference.chunkId,
875
+ reference.locatorLabel,
876
+ reference.contextLabel,
856
877
  reference.provenanceLabel
857
- ].filter((value) => Boolean(value && value.length > 0)).join(" · ");
878
+ ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
858
879
  var buildGroundedAnswerCitationDetail = (reference) => ({
859
880
  contextLabel: reference.contextLabel,
860
881
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
@@ -878,12 +899,12 @@ var buildRAGCitations = (sources) => {
878
899
  continue;
879
900
  unique.set(key, {
880
901
  chunkId: source.chunkId,
881
- contextLabel: buildContextLabel(source.metadata),
902
+ contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
882
903
  key,
883
904
  label: buildSourceLabel(source),
884
- locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
905
+ locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
885
906
  metadata: source.metadata,
886
- provenanceLabel: buildProvenanceLabel(source.metadata),
907
+ provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
887
908
  score: source.score,
888
909
  source: source.source,
889
910
  text: source.text,
@@ -953,7 +974,7 @@ var buildRAGGroundingReferences = (sources) => {
953
974
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
954
975
  return citations.map((citation) => ({
955
976
  chunkId: citation.chunkId,
956
- contextLabel: buildContextLabel(citation.metadata),
977
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
957
978
  excerpt: buildExcerpt(citation.text),
958
979
  label: citation.label,
959
980
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
@@ -1023,6 +1044,10 @@ var buildContextLabel2 = (metadata) => {
1023
1044
  return from ? `Message from ${from}` : "Message evidence";
1024
1045
  }
1025
1046
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1047
+ const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
1048
+ if (page && region) {
1049
+ return `Page ${page} region ${region}`;
1050
+ }
1026
1051
  if (page) {
1027
1052
  return `Page ${page}`;
1028
1053
  }
@@ -1046,6 +1071,11 @@ var buildContextLabel2 = (metadata) => {
1046
1071
  if (speaker) {
1047
1072
  return `Speaker ${speaker}`;
1048
1073
  }
1074
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1075
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1076
+ if (sectionTitle) {
1077
+ return `Section ${sectionTitle}`;
1078
+ }
1049
1079
  return;
1050
1080
  };
1051
1081
  var buildLocatorLabel2 = (metadata, source, title) => {
@@ -1053,6 +1083,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1053
1083
  return;
1054
1084
  }
1055
1085
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1086
+ const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
1087
+ if (page && region) {
1088
+ return `Page ${page} · Region ${region}`;
1089
+ }
1056
1090
  if (page) {
1057
1091
  return `Page ${page}`;
1058
1092
  }
@@ -1081,6 +1115,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1081
1115
  if (mediaStart) {
1082
1116
  return `Timestamp ${mediaStart}`;
1083
1117
  }
1118
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1119
+ if (sectionPath.length > 0) {
1120
+ return `Section ${sectionPath.join(" > ")}`;
1121
+ }
1084
1122
  return;
1085
1123
  };
1086
1124
  var buildProvenanceLabel2 = (metadata) => {
@@ -1095,9 +1133,11 @@ var buildProvenanceLabel2 = (metadata) => {
1095
1133
  const transcriptSource = getContextString2(metadata.transcriptSource);
1096
1134
  const pdfTextMode = getContextString2(metadata.pdfTextMode);
1097
1135
  const ocrEngine = getContextString2(metadata.ocrEngine);
1136
+ const ocrConfidence = getContextNumber2(metadata.ocrRegionConfidence) ?? getContextNumber2(metadata.ocrConfidence);
1098
1137
  const labels = [
1099
1138
  pdfTextMode ? `PDF ${pdfTextMode}` : "",
1100
1139
  ocrEngine ? `OCR ${ocrEngine}` : "",
1140
+ typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
1101
1141
  mediaKind ? `Media ${mediaKind}` : "",
1102
1142
  transcriptSource ? `Transcript ${transcriptSource}` : "",
1103
1143
  threadTopic ? `Thread ${threadTopic}` : "",
@@ -1107,6 +1147,50 @@ var buildProvenanceLabel2 = (metadata) => {
1107
1147
  ].filter((value) => value.length > 0);
1108
1148
  return labels.length > 0 ? labels.join(" · ") : undefined;
1109
1149
  };
1150
+ var buildRAGSourceLabels = ({
1151
+ metadata,
1152
+ source,
1153
+ title
1154
+ }) => {
1155
+ const contextLabel = buildContextLabel2(metadata);
1156
+ const locatorLabel = buildLocatorLabel2(metadata, source, title);
1157
+ const provenanceLabel = buildProvenanceLabel2(metadata);
1158
+ if (!contextLabel && !locatorLabel && !provenanceLabel) {
1159
+ return;
1160
+ }
1161
+ return {
1162
+ contextLabel,
1163
+ locatorLabel,
1164
+ provenanceLabel
1165
+ };
1166
+ };
1167
+ var buildRAGChunkStructure = (metadata) => {
1168
+ if (!metadata) {
1169
+ return;
1170
+ }
1171
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
1172
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
1173
+ const section = {
1174
+ depth: getContextNumber2(metadata.sectionDepth),
1175
+ kind: sectionKind,
1176
+ path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
1177
+ title: getContextString2(metadata.sectionTitle)
1178
+ };
1179
+ const sequence = {
1180
+ nextChunkId: getContextString2(metadata.nextChunkId),
1181
+ previousChunkId: getContextString2(metadata.previousChunkId),
1182
+ sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
1183
+ sectionChunkId: getContextString2(metadata.sectionChunkId),
1184
+ sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
1185
+ };
1186
+ if (!section.title && (!section.path || section.path.length === 0) && typeof section.depth !== "number" && !section.kind && !sequence.nextChunkId && !sequence.previousChunkId && typeof sequence.sectionChunkCount !== "number" && !sequence.sectionChunkId && typeof sequence.sectionChunkIndex !== "number") {
1187
+ return;
1188
+ }
1189
+ return {
1190
+ section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
1191
+ sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
1192
+ };
1193
+ };
1110
1194
  var buildExcerpt2 = (text, maxLength = 160) => {
1111
1195
  const normalized = text.replaceAll(/\s+/g, " ").trim();
1112
1196
  if (normalized.length <= maxLength) {
@@ -1114,6 +1198,136 @@ var buildExcerpt2 = (text, maxLength = 160) => {
1114
1198
  }
1115
1199
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}…`;
1116
1200
  };
1201
+ var buildRAGChunkGraph = (chunks) => {
1202
+ const nodes = [];
1203
+ const edges = [];
1204
+ const edgeKeys = new Set;
1205
+ const sections = new Map;
1206
+ for (const chunk of chunks) {
1207
+ const labels = chunk.labels ?? buildRAGSourceLabels({
1208
+ metadata: chunk.metadata,
1209
+ source: chunk.source,
1210
+ title: chunk.title
1211
+ });
1212
+ const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
1213
+ nodes.push({
1214
+ chunkId: chunk.chunkId,
1215
+ contextLabel: labels?.contextLabel,
1216
+ label: chunk.source ?? chunk.title ?? chunk.chunkId,
1217
+ locatorLabel: labels?.locatorLabel,
1218
+ provenanceLabel: labels?.provenanceLabel,
1219
+ score: chunk.score,
1220
+ source: chunk.source,
1221
+ structure,
1222
+ title: chunk.title
1223
+ });
1224
+ const previousChunkId = structure?.sequence?.previousChunkId;
1225
+ if (previousChunkId) {
1226
+ const key = `previous:${previousChunkId}:${chunk.chunkId}`;
1227
+ if (!edgeKeys.has(key)) {
1228
+ edgeKeys.add(key);
1229
+ edges.push({
1230
+ fromChunkId: previousChunkId,
1231
+ relation: "previous",
1232
+ toChunkId: chunk.chunkId
1233
+ });
1234
+ }
1235
+ }
1236
+ const nextChunkId = structure?.sequence?.nextChunkId;
1237
+ if (nextChunkId) {
1238
+ const key = `next:${chunk.chunkId}:${nextChunkId}`;
1239
+ if (!edgeKeys.has(key)) {
1240
+ edgeKeys.add(key);
1241
+ edges.push({
1242
+ fromChunkId: chunk.chunkId,
1243
+ relation: "next",
1244
+ toChunkId: nextChunkId
1245
+ });
1246
+ }
1247
+ }
1248
+ const sectionId = structure?.sequence?.sectionChunkId;
1249
+ if (sectionId) {
1250
+ const existing = sections.get(sectionId);
1251
+ if (!existing) {
1252
+ sections.set(sectionId, {
1253
+ chunkCount: structure.sequence?.sectionChunkCount ?? 1,
1254
+ chunkIds: [chunk.chunkId],
1255
+ depth: structure.section?.depth,
1256
+ id: sectionId,
1257
+ kind: structure.section?.kind,
1258
+ path: structure.section?.path,
1259
+ title: structure.section?.title
1260
+ });
1261
+ continue;
1262
+ }
1263
+ if (!existing.chunkIds.includes(chunk.chunkId)) {
1264
+ existing.chunkIds.push(chunk.chunkId);
1265
+ }
1266
+ existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
1267
+ }
1268
+ }
1269
+ for (const section of sections.values()) {
1270
+ section.chunkIds.sort((left, right) => {
1271
+ const leftNode = nodes.find((node) => node.chunkId === left);
1272
+ const rightNode = nodes.find((node) => node.chunkId === right);
1273
+ const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1274
+ const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1275
+ if (leftIndex !== rightIndex) {
1276
+ return leftIndex - rightIndex;
1277
+ }
1278
+ return left.localeCompare(right);
1279
+ });
1280
+ }
1281
+ nodes.sort((left, right) => {
1282
+ const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1283
+ const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1284
+ if (leftSection !== rightSection) {
1285
+ return leftSection - rightSection;
1286
+ }
1287
+ const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
1288
+ const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
1289
+ if (leftScore !== rightScore) {
1290
+ return rightScore - leftScore;
1291
+ }
1292
+ return left.label.localeCompare(right.label);
1293
+ });
1294
+ return {
1295
+ edges,
1296
+ nodes,
1297
+ sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
1298
+ };
1299
+ };
1300
+ var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
1301
+ chunkId: chunk.chunkId,
1302
+ labels: chunk.labels,
1303
+ metadata: chunk.metadata,
1304
+ source: chunk.source ?? preview.document.source,
1305
+ structure: chunk.structure,
1306
+ title: chunk.title ?? preview.document.title
1307
+ })));
1308
+ var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
1309
+ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
1310
+ if (graph.nodes.length === 0) {
1311
+ return {
1312
+ activeChunkId,
1313
+ sectionNodes: []
1314
+ };
1315
+ }
1316
+ const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
1317
+ const resolvedActiveChunkId = activeNode?.chunkId;
1318
+ const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
1319
+ const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
1320
+ const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
1321
+ const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
1322
+ return {
1323
+ activeChunkId: resolvedActiveChunkId,
1324
+ activeNode,
1325
+ nextNode,
1326
+ previousNode,
1327
+ section,
1328
+ sectionNodes
1329
+ };
1330
+ };
1117
1331
  var buildRAGRetrievedState = (messages) => {
1118
1332
  const message = getLatestRetrievedMessage(messages);
1119
1333
  if (!message) {
@@ -1148,13 +1362,14 @@ var buildRAGSourceSummaries = (sources) => {
1148
1362
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
1149
1363
  citations: groupCitations,
1150
1364
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
1151
- contextLabel: buildContextLabel2(leadChunk?.metadata),
1365
+ contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
1152
1366
  count: group.count,
1153
1367
  excerpt: buildExcerpt2(leadChunk?.text ?? ""),
1154
1368
  key: group.key,
1155
1369
  label: group.label,
1156
- locatorLabel: buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
1157
- provenanceLabel: buildProvenanceLabel2(leadChunk?.metadata),
1370
+ locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
1371
+ provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
1372
+ structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
1158
1373
  source: group.source,
1159
1374
  title: group.title
1160
1375
  };
@@ -1278,6 +1493,12 @@ var buildSourceGroup = (source, key) => ({
1278
1493
  count: 1,
1279
1494
  key,
1280
1495
  label: buildSourceLabel2(source),
1496
+ labels: source.labels ?? buildRAGSourceLabels({
1497
+ metadata: source.metadata,
1498
+ source: source.source,
1499
+ title: source.title
1500
+ }),
1501
+ structure: source.structure ?? buildRAGChunkStructure(source.metadata),
1281
1502
  source: source.source,
1282
1503
  title: source.title
1283
1504
  });
@@ -1288,7 +1509,20 @@ var updateSourceGroup = (groups, source) => {
1288
1509
  groups.set(key, buildSourceGroup(source, key));
1289
1510
  return;
1290
1511
  }
1291
- existing.bestScore = Math.max(existing.bestScore, source.score);
1512
+ if (source.score > existing.bestScore) {
1513
+ existing.bestScore = source.score;
1514
+ existing.label = buildSourceLabel2(source);
1515
+ existing.labels = source.labels ?? buildRAGSourceLabels({
1516
+ metadata: source.metadata,
1517
+ source: source.source,
1518
+ title: source.title
1519
+ });
1520
+ existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
1521
+ existing.source = source.source;
1522
+ existing.title = source.title;
1523
+ } else {
1524
+ existing.bestScore = Math.max(existing.bestScore, source.score);
1525
+ }
1292
1526
  existing.count += 1;
1293
1527
  existing.chunks.push(source);
1294
1528
  };