@mastra/rag 2.6.4 → 2.6.5-alpha.1

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.
@@ -3,7 +3,7 @@ name: mastra-rag
3
3
  description: Documentation for @mastra/rag. Use when working with @mastra/rag APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/rag"
6
- version: "2.6.4"
6
+ version: "2.6.5-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.6.4",
2
+ "version": "2.6.5-alpha.1",
3
3
  "package": "@mastra/rag",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/html.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAWjD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,iBAAiB,CAAU;IAEnC,YAAY,OAAO,EAAE,gBAAgB,GAAG;QAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAAE,EAGtE;IAED,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,EAAE,CAsDhD;IAED,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,yBAAyB;IAyBjC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAAQ,EAAE,CA4B9E;IAED,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAUpD;CACF;AAED,qBAAa,s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sBAAsB;IAmC9B,OAAO,CAAC,2BAA2B;IAsBnC,OAAO,CAAC,wBAAwB;IA4BhC,OAAO,CAAC,kBAAkB;IAqB1B,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE,CAQ9C;CACF"}
package/dist/index.cjs CHANGED
@@ -4549,6 +4549,61 @@ var RecursiveCharacterTransformer = class RecursiveCharacterTransformer extends
4549
4549
  };
4550
4550
  //#endregion
4551
4551
  //#region src/document/transformers/html.ts
4552
+ const BLOCK_TAGS = /* @__PURE__ */ new Set([
4553
+ "address",
4554
+ "article",
4555
+ "aside",
4556
+ "blockquote",
4557
+ "br",
4558
+ "caption",
4559
+ "center",
4560
+ "dd",
4561
+ "details",
4562
+ "dialog",
4563
+ "div",
4564
+ "dl",
4565
+ "dt",
4566
+ "fieldset",
4567
+ "figcaption",
4568
+ "figure",
4569
+ "footer",
4570
+ "form",
4571
+ "h1",
4572
+ "h2",
4573
+ "h3",
4574
+ "h4",
4575
+ "h5",
4576
+ "h6",
4577
+ "header",
4578
+ "hgroup",
4579
+ "hr",
4580
+ "legend",
4581
+ "li",
4582
+ "main",
4583
+ "menu",
4584
+ "nav",
4585
+ "ol",
4586
+ "p",
4587
+ "pre",
4588
+ "search",
4589
+ "section",
4590
+ "summary",
4591
+ "table",
4592
+ "tbody",
4593
+ "td",
4594
+ "tfoot",
4595
+ "th",
4596
+ "thead",
4597
+ "tr",
4598
+ "ul"
4599
+ ]);
4600
+ function extractText(node) {
4601
+ if (!node) return "";
4602
+ if (!node.tagName) return node.text || "";
4603
+ let content = "";
4604
+ for (const child of node.childNodes ?? []) content += extractText(child);
4605
+ return BLOCK_TAGS.has(node.tagName.toLowerCase()) ? " " + content + " " : content;
4606
+ }
4552
4607
  var HTMLHeaderTransformer = class {
4553
4608
  headersToSplitOn;
4554
4609
  returnEachElement;
@@ -4607,14 +4662,7 @@ var HTMLHeaderTransformer = class {
4607
4662
  return "/" + parts.join("/");
4608
4663
  }
4609
4664
  getTextContent(element) {
4610
- if (!element) return "";
4611
- if (!element.tagName) return element.text || "";
4612
- let content = element.text || "";
4613
- if (element.childNodes) for (const child of element.childNodes) {
4614
- const childText = this.getTextContent(child);
4615
- if (childText) content += " " + childText;
4616
- }
4617
- return content.trim();
4665
+ return extractText(element).replace(/\s+/g, " ").trim();
4618
4666
  }
4619
4667
  aggregateElementsToChunks(elements) {
4620
4668
  const aggregatedChunks = [];
@@ -4692,14 +4740,7 @@ var HTMLSectionTransformer = class {
4692
4740
  return "/" + parts.join("/");
4693
4741
  }
4694
4742
  getTextContent(element) {
4695
- if (!element) return "";
4696
- if (!element.tagName) return element.text || "";
4697
- let content = element.text || "";
4698
- if (element.childNodes) for (const child of element.childNodes) {
4699
- const childText = this.getTextContent(child);
4700
- if (childText) content += " " + childText;
4701
- }
4702
- return content.trim();
4743
+ return extractText(element).replace(/\s+/g, " ").trim();
4703
4744
  }
4704
4745
  splitHtmlByHeaders(htmlDoc) {
4705
4746
  const sections = [];
@@ -5503,35 +5544,44 @@ var SentenceTransformer = class extends TextTransformer {
5503
5544
  const chunks = [];
5504
5545
  let currentChunk = [];
5505
5546
  let currentSize = 0;
5547
+ let carriedCount = 0;
5506
5548
  const separator = " ";
5549
+ const sepLength = this.lengthFunction(separator);
5507
5550
  for (const sentence of sentences) {
5508
5551
  const sentenceLength = this.lengthFunction(sentence);
5509
- const separatorLength = currentChunk.length > 0 ? this.lengthFunction(separator) : 0;
5510
- const totalLength = currentSize + sentenceLength + separatorLength;
5511
5552
  if (sentenceLength > this.maxSize) {
5512
- if (currentChunk.length > 0) {
5513
- chunks.push(currentChunk.join(separator));
5514
- currentChunk = [];
5515
- currentSize = 0;
5516
- }
5553
+ if (currentChunk.length > carriedCount) chunks.push(currentChunk.join(separator));
5554
+ currentChunk = [];
5555
+ currentSize = 0;
5556
+ carriedCount = 0;
5517
5557
  const fallbackChunks = this.handleOversizedSentence(sentence);
5518
5558
  chunks.push(...fallbackChunks);
5519
5559
  continue;
5520
5560
  }
5521
- if (currentChunk.length > 0 && totalLength > this.maxSize) {
5522
- chunks.push(currentChunk.join(separator));
5523
- currentChunk = this.calculateSentenceOverlap(currentChunk);
5524
- currentSize = this.calculateChunkSize(currentChunk);
5561
+ if (currentChunk.length > 0 && currentSize + sepLength + sentenceLength > this.maxSize) {
5562
+ if (currentChunk.length > carriedCount) chunks.push(currentChunk.join(separator));
5563
+ const overlapSentences = this.calculateSentenceOverlap(currentChunk);
5564
+ let overlapSize = this.calculateChunkSize(overlapSentences);
5565
+ let start = 0;
5566
+ while (start < overlapSentences.length && overlapSize + sepLength + sentenceLength > this.maxSize) {
5567
+ overlapSize -= this.lengthFunction(overlapSentences[start]);
5568
+ if (start < overlapSentences.length - 1) overlapSize -= sepLength;
5569
+ start++;
5570
+ }
5571
+ currentChunk = overlapSentences.slice(start);
5572
+ carriedCount = currentChunk.length;
5573
+ currentSize = currentChunk.length > 0 ? overlapSize : 0;
5525
5574
  }
5575
+ currentSize += sentenceLength + (currentChunk.length > 0 ? sepLength : 0);
5526
5576
  currentChunk.push(sentence);
5527
- currentSize += sentenceLength + separatorLength;
5528
5577
  if (currentSize >= this.targetSize) {
5529
5578
  chunks.push(currentChunk.join(separator));
5530
5579
  currentChunk = this.calculateSentenceOverlap(currentChunk);
5580
+ carriedCount = currentChunk.length;
5531
5581
  currentSize = this.calculateChunkSize(currentChunk);
5532
5582
  }
5533
5583
  }
5534
- if (currentChunk.length > 0) chunks.push(currentChunk.join(separator));
5584
+ if (currentChunk.length > carriedCount) chunks.push(currentChunk.join(separator));
5535
5585
  return chunks;
5536
5586
  }
5537
5587
  /**