doc2vec 2.9.1 → 2.9.2

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.
@@ -1760,9 +1760,9 @@ class ContentProcessor {
1760
1760
  }
1761
1761
  async chunkMarkdown(markdown, sourceConfig, url) {
1762
1762
  const logger = this.logger.child('chunker');
1763
- // --- Configuration ---
1764
- const MAX_TOKENS = 1000;
1765
- const MIN_TOKENS = 150; // 💡 Merges "OpenAI-compatible" sentence into the next block
1763
+ // --- Configuration (character-based, ~4 chars ≈ 1 token) ---
1764
+ const MAX_CHARS = 4000;
1765
+ const MIN_CHARS = 600; // 💡 Merges short sections into the next block
1766
1766
  const OVERLAP_PERCENT = 0.1; // 10% overlap for large splits
1767
1767
  const chunks = [];
1768
1768
  const lines = markdown.split("\n");
@@ -1824,29 +1824,27 @@ class ContentProcessor {
1824
1824
  };
1825
1825
  /**
1826
1826
  * Flushes the current buffer into the chunks array.
1827
- * Uses sub-splitting logic if the buffer exceeds MAX_TOKENS.
1827
+ * Uses sub-splitting logic if the buffer exceeds MAX_CHARS.
1828
1828
  */
1829
1829
  const flushBuffer = (force = false) => {
1830
1830
  const trimmedBuffer = buffer.trim();
1831
1831
  if (!trimmedBuffer)
1832
1832
  return;
1833
- const tokenCount = utils_1.Utils.tokenize(trimmedBuffer).length;
1833
+ const charCount = trimmedBuffer.length;
1834
1834
  // 💡 SEMANTIC MERGING
1835
1835
  // If the current section is too short (like just a title or a one-liner),
1836
1836
  // we don't flush yet unless it's the end of the file (force=true).
1837
- if (tokenCount < MIN_TOKENS && !force) {
1837
+ if (charCount < MIN_CHARS && !force) {
1838
1838
  return;
1839
1839
  }
1840
1840
  // Compute the appropriate topic hierarchy for merged content
1841
1841
  const topicHierarchy = computeTopicHierarchy();
1842
- if (tokenCount > MAX_TOKENS) {
1843
- // 💡 RECURSIVE OVERLAP SPLITTING
1842
+ if (charCount > MAX_CHARS) {
1843
+ // 💡 OVERLAP SPLITTING
1844
1844
  // If the section is a massive guide, split it but keep headers on every sub-piece.
1845
- const tokens = utils_1.Utils.tokenize(trimmedBuffer);
1846
- const overlapSize = Math.floor(MAX_TOKENS * OVERLAP_PERCENT);
1847
- for (let i = 0; i < tokens.length; i += (MAX_TOKENS - overlapSize)) {
1848
- const subTokens = tokens.slice(i, i + MAX_TOKENS);
1849
- const subContent = subTokens.join("");
1845
+ const overlapSize = Math.floor(MAX_CHARS * OVERLAP_PERCENT);
1846
+ for (let i = 0; i < trimmedBuffer.length; i += (MAX_CHARS - overlapSize)) {
1847
+ const subContent = trimmedBuffer.slice(i, i + MAX_CHARS);
1850
1848
  chunks.push(createDocumentChunk(subContent, topicHierarchy));
1851
1849
  }
1852
1850
  }
@@ -1870,9 +1868,9 @@ class ContentProcessor {
1870
1868
  .replace(/\[\]\(#[^)]*\)/g, "") // Remove [](#anchor) patterns
1871
1869
  .trim();
1872
1870
  // Check if we should merge with previous content
1873
- const currentTokenCount = utils_1.Utils.tokenize(buffer.trim()).length;
1874
- const hasBufferContent = currentTokenCount > 0;
1875
- const bufferIsSmall = currentTokenCount < MIN_TOKENS;
1871
+ const currentCharCount = buffer.trim().length;
1872
+ const hasBufferContent = currentCharCount > 0;
1873
+ const bufferIsSmall = currentCharCount < MIN_CHARS;
1876
1874
  // Only merge if:
1877
1875
  // 1. Buffer has content and is small
1878
1876
  // 2. Buffer has tracked headings (we're merging sections, not just content)
@@ -1898,7 +1896,7 @@ class ContentProcessor {
1898
1896
  else {
1899
1897
  buffer += `${line}\n`;
1900
1898
  // Safety valve: if a single section is huge, flush it periodically
1901
- if (utils_1.Utils.tokenize(buffer).length >= MAX_TOKENS) {
1899
+ if (buffer.length >= MAX_CHARS) {
1902
1900
  flushBuffer();
1903
1901
  }
1904
1902
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc2vec",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "type": "commonjs",
5
5
  "description": "",
6
6
  "main": "dist/doc2vec.js",