@absolutejs/absolute 0.19.0-beta.617 → 0.19.0-beta.619

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.
@@ -1787,6 +1787,25 @@ var buildContextLabel2 = (metadata) => {
1787
1787
  if (!metadata) {
1788
1788
  return;
1789
1789
  }
1790
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
1791
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
1792
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1793
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1794
+ if (pdfTextKind === "table_like" && sectionTitle) {
1795
+ return `PDF table block ${sectionTitle}`;
1796
+ }
1797
+ if (pdfTextKind === "paragraph" && sectionTitle) {
1798
+ return `PDF text block ${sectionTitle}`;
1799
+ }
1800
+ if (officeBlockKind === "table" && sectionTitle) {
1801
+ return `Office table block ${sectionTitle}`;
1802
+ }
1803
+ if (officeBlockKind === "list" && sectionTitle) {
1804
+ return `Office list block ${sectionTitle}`;
1805
+ }
1806
+ if (officeBlockKind === "paragraph" && sectionTitle) {
1807
+ return `Office paragraph block ${sectionTitle}`;
1808
+ }
1790
1809
  const emailKind = getContextString2(metadata.emailKind);
1791
1810
  if (emailKind === "attachment") {
1792
1811
  return "Attachment evidence";
@@ -1823,8 +1842,6 @@ var buildContextLabel2 = (metadata) => {
1823
1842
  if (speaker) {
1824
1843
  return `Speaker ${speaker}`;
1825
1844
  }
1826
- const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1827
- const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1828
1845
  if (sectionTitle) {
1829
1846
  return `Section ${sectionTitle}`;
1830
1847
  }
@@ -1834,11 +1851,21 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1834
1851
  if (!metadata) {
1835
1852
  return;
1836
1853
  }
1854
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
1855
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
1856
+ const pdfBlockNumber = getContextNumber2(metadata.pdfBlockNumber);
1857
+ const officeBlockNumber = getContextNumber2(metadata.officeBlockNumber);
1837
1858
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1838
1859
  const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
1839
1860
  if (page && region) {
1840
1861
  return `Page ${page} \xB7 Region ${region}`;
1841
1862
  }
1863
+ if (page && pdfBlockNumber && pdfTextKind === "table_like") {
1864
+ return `Page ${page} \xB7 Table Block ${pdfBlockNumber}`;
1865
+ }
1866
+ if (page && pdfBlockNumber) {
1867
+ return `Page ${page} \xB7 Text Block ${pdfBlockNumber}`;
1868
+ }
1842
1869
  if (page) {
1843
1870
  return `Page ${page}`;
1844
1871
  }
@@ -1867,6 +1894,15 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1867
1894
  if (mediaStart) {
1868
1895
  return `Timestamp ${mediaStart}`;
1869
1896
  }
1897
+ if (officeBlockNumber && officeBlockKind === "table") {
1898
+ return `Office table block ${officeBlockNumber}`;
1899
+ }
1900
+ if (officeBlockNumber && officeBlockKind === "list") {
1901
+ return `Office list block ${officeBlockNumber}`;
1902
+ }
1903
+ if (officeBlockNumber && officeBlockKind === "paragraph") {
1904
+ return `Office paragraph block ${officeBlockNumber}`;
1905
+ }
1870
1906
  const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1871
1907
  if (sectionPath.length > 0) {
1872
1908
  return `Section ${sectionPath.join(" > ")}`;
@@ -1884,12 +1920,16 @@ var buildProvenanceLabel2 = (metadata) => {
1884
1920
  const mediaKind = getContextString2(metadata.mediaKind);
1885
1921
  const transcriptSource = getContextString2(metadata.transcriptSource);
1886
1922
  const pdfTextMode = getContextString2(metadata.pdfTextMode);
1923
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
1924
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
1887
1925
  const ocrEngine = getContextString2(metadata.ocrEngine);
1888
1926
  const extractorRegistryMatch = getContextString2(metadata.extractorRegistryMatch);
1889
1927
  const chunkingProfile = getContextString2(metadata.chunkingProfile);
1890
1928
  const ocrConfidence = getContextNumber2(metadata.ocrRegionConfidence) ?? getContextNumber2(metadata.ocrConfidence);
1891
1929
  const labels = [
1892
1930
  pdfTextMode ? `PDF ${pdfTextMode}` : "",
1931
+ pdfTextKind === "table_like" ? "PDF table block" : pdfTextKind === "paragraph" ? "PDF text block" : "",
1932
+ officeBlockKind ? `Office ${officeBlockKind}` : "",
1893
1933
  ocrEngine ? `OCR ${ocrEngine}` : "",
1894
1934
  extractorRegistryMatch ? `Extractor ${extractorRegistryMatch}` : "",
1895
1935
  chunkingProfile ? `Chunking ${chunkingProfile}` : "",
@@ -1925,7 +1965,7 @@ var buildRAGChunkStructure = (metadata) => {
1925
1965
  return;
1926
1966
  }
1927
1967
  const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
1928
- const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" || metadata.sectionKind === "office_heading" || metadata.sectionKind === "spreadsheet_rows" || metadata.sectionKind === "presentation_slide" ? metadata.sectionKind : undefined;
1968
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" || metadata.sectionKind === "office_heading" || metadata.sectionKind === "office_block" || metadata.sectionKind === "pdf_block" || metadata.sectionKind === "spreadsheet_rows" || metadata.sectionKind === "presentation_slide" ? metadata.sectionKind : undefined;
1929
1969
  const section = {
1930
1970
  depth: getContextNumber2(metadata.sectionDepth),
1931
1971
  kind: sectionKind,
@@ -2245,7 +2285,7 @@ var buildRAGSourceSummaries = (sources) => {
2245
2285
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
2246
2286
  return sourceGroups.map((group) => {
2247
2287
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
2248
- const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
2288
+ const leadChunk = getPreferredSourceLeadChunk(group.chunks);
2249
2289
  const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
2250
2290
  const structure = leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata);
2251
2291
  const excerptSelection = buildRAGExcerptSelection(excerpts, structure);
@@ -2273,13 +2313,45 @@ var getSectionPathFromSource = (source) => {
2273
2313
  const path = source.structure?.section?.path ?? (Array.isArray(source.metadata?.sectionPath) ? source.metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : []);
2274
2314
  return path.length > 0 ? path : undefined;
2275
2315
  };
2316
+ var isBlockAwareContextLabel = (value) => typeof value === "string" && (value.startsWith("PDF ") || value.startsWith("Office "));
2317
+ var getStructuredSectionScoreWeight = (metadata) => {
2318
+ if (!metadata) {
2319
+ return 1;
2320
+ }
2321
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
2322
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
2323
+ const sectionKind = getContextString2(metadata.sectionKind);
2324
+ if (pdfTextKind === "table_like") {
2325
+ return 1.28;
2326
+ }
2327
+ if (officeBlockKind === "table" || officeBlockKind === "list") {
2328
+ return 1.24;
2329
+ }
2330
+ if (sectionKind === "pdf_block" || sectionKind === "office_block" || officeBlockKind === "paragraph" || pdfTextKind === "paragraph") {
2331
+ return 1.12;
2332
+ }
2333
+ return 1;
2334
+ };
2335
+ var getStructuredSourceLeadScore = (source) => source.score * getStructuredSectionScoreWeight(source.metadata);
2336
+ var getPreferredSourceLeadChunk = (chunks) => chunks.slice().sort((left, right) => {
2337
+ const leftWeightedScore = getStructuredSourceLeadScore(left);
2338
+ const rightWeightedScore = getStructuredSourceLeadScore(right);
2339
+ if (rightWeightedScore !== leftWeightedScore) {
2340
+ return rightWeightedScore - leftWeightedScore;
2341
+ }
2342
+ if (right.score !== left.score) {
2343
+ return right.score - left.score;
2344
+ }
2345
+ return left.chunkId.localeCompare(right.chunkId);
2346
+ })[0];
2276
2347
  var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2277
- const totalScore = sources.reduce((sum, source) => sum + source.score, 0);
2348
+ const totalScore = sources.reduce((sum, source) => sum + source.score * getStructuredSectionScoreWeight(source.metadata), 0);
2278
2349
  if (sources.length === 0 || totalScore <= 0) {
2279
2350
  return [];
2280
2351
  }
2281
2352
  const sections = new Map;
2282
2353
  for (const source of sources) {
2354
+ const structuredScore = source.score * getStructuredSectionScoreWeight(source.metadata);
2283
2355
  const path = getSectionPathFromSource(source);
2284
2356
  if (!path) {
2285
2357
  continue;
@@ -2311,7 +2383,7 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2311
2383
  sourceSet: new Set(source.source ? [source.source] : []),
2312
2384
  topChunkId: source.chunkId,
2313
2385
  topSource: source.source,
2314
- totalScore: source.score,
2386
+ totalScore: structuredScore,
2315
2387
  transformedHits,
2316
2388
  variantHits,
2317
2389
  vectorHits
@@ -2319,7 +2391,7 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2319
2391
  continue;
2320
2392
  }
2321
2393
  existing.count += 1;
2322
- existing.totalScore += source.score;
2394
+ existing.totalScore += structuredScore;
2323
2395
  if (source.source) {
2324
2396
  existing.sourceSet.add(source.source);
2325
2397
  }
@@ -2347,6 +2419,8 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2347
2419
  const parentTotal = siblingPool.reduce((sum, entry) => sum + entry.totalScore, 0);
2348
2420
  const scoreShare = section.totalScore / totalScore;
2349
2421
  const parentShare = parentTotal > 0 ? section.totalScore / parentTotal : undefined;
2422
+ const topChunk = sources.find((source) => source.chunkId === section.topChunkId);
2423
+ const topContextLabel = topChunk?.labels?.contextLabel ?? buildContextLabel2(topChunk?.metadata);
2350
2424
  const parentDistribution = parentTotal > 0 ? siblingPool.map((entry) => ({
2351
2425
  count: entry.count,
2352
2426
  isActive: entry.key === section.key,
@@ -2472,6 +2546,7 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2472
2546
  reasons.push("concentrated_evidence");
2473
2547
  }
2474
2548
  const summaryParts = [
2549
+ isBlockAwareContextLabel(topContextLabel) ? topContextLabel : "",
2475
2550
  `${section.count} hit${section.count === 1 ? "" : "s"}`,
2476
2551
  `${(scoreShare * 100).toFixed(0)}% score share`,
2477
2552
  `vector ${section.vectorHits} \xB7 lexical ${section.lexicalHits} \xB7 hybrid ${section.hybridHits}`,
@@ -2683,22 +2758,21 @@ var updateSourceGroup = (groups, source) => {
2683
2758
  groups.set(key, buildSourceGroup(source, key));
2684
2759
  return;
2685
2760
  }
2686
- if (source.score > existing.bestScore) {
2687
- existing.bestScore = source.score;
2688
- existing.label = buildSourceLabel2(source);
2689
- existing.labels = source.labels ?? buildRAGSourceLabels({
2690
- metadata: source.metadata,
2691
- source: source.source,
2692
- title: source.title
2693
- });
2694
- existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
2695
- existing.source = source.source;
2696
- existing.title = source.title;
2697
- } else {
2698
- existing.bestScore = Math.max(existing.bestScore, source.score);
2699
- }
2761
+ existing.bestScore = Math.max(existing.bestScore, source.score);
2700
2762
  existing.count += 1;
2701
2763
  existing.chunks.push(source);
2764
+ const leadChunk = getPreferredSourceLeadChunk(existing.chunks);
2765
+ if (leadChunk) {
2766
+ existing.label = buildSourceLabel2(leadChunk);
2767
+ existing.labels = leadChunk.labels ?? buildRAGSourceLabels({
2768
+ metadata: leadChunk.metadata,
2769
+ source: leadChunk.source,
2770
+ title: leadChunk.title
2771
+ });
2772
+ existing.structure = leadChunk.structure ?? buildRAGChunkStructure(leadChunk.metadata);
2773
+ existing.source = leadChunk.source;
2774
+ existing.title = leadChunk.title;
2775
+ }
2702
2776
  };
2703
2777
  var getLatestAssistantMessage = (messages) => {
2704
2778
  for (let index = messages.length - 1;index >= 0; index -= 1) {
@@ -4706,5 +4780,5 @@ export {
4706
4780
  AIStreamService
4707
4781
  };
4708
4782
 
4709
- //# debugId=91EA691E1A0F94C964756E2164756E21
4783
+ //# debugId=367F6BF9D108824C64756E2164756E21
4710
4784
  //# sourceMappingURL=index.js.map