@customize-agent/knowledge 4.0.19 → 4.0.21

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.
@@ -54,5 +54,6 @@ export declare class TextChunker {
54
54
  private kindForCategory;
55
55
  private extractSectionTitle;
56
56
  private takeOverlap;
57
+ private hasLongUnbrokenSegment;
57
58
  private estimateTokens;
58
59
  }
@@ -295,9 +295,9 @@ export class TextChunker {
295
295
  return chunks.flatMap(chunk => this.estimateTokens(chunk) > maxTokens ? this.splitByWindow(chunk, maxTokens, overlapTokens) : [chunk]);
296
296
  }
297
297
  splitByWindow(text, maxTokens, overlapTokens = 0) {
298
- if (!/[\s\n\r\t。?!;;.!?,、]/u.test(text) && text.length > maxTokens * 3) {
299
- const maxChars = Math.max(1, maxTokens * 3);
300
- const overlapChars = Math.max(0, Math.min(Math.floor(maxChars / 2), overlapTokens * 3));
298
+ if (this.hasLongUnbrokenSegment(text) && text.length > Math.max(2000, maxTokens * 3)) {
299
+ const maxChars = Math.max(1, maxTokens);
300
+ const overlapChars = Math.max(0, Math.min(Math.floor(maxChars / 2), overlapTokens));
301
301
  const step = Math.max(1, maxChars - overlapChars);
302
302
  const chunks = [];
303
303
  for (let start = 0; start < text.length; start += step) {
@@ -452,7 +452,7 @@ export class TextChunker {
452
452
  startChar: candidate.startChar,
453
453
  endChar: candidate.endChar,
454
454
  splitStrategy: 'recursive_parent_child_v2',
455
- parentText: candidate.parentText, // <=== 原始父块内容
455
+ parentText: candidate.childIndex === 0 ? candidate.parentText : undefined,
456
456
  },
457
457
  };
458
458
  }
@@ -481,9 +481,12 @@ export class TextChunker {
481
481
  const chars = overlapTokens * 4;
482
482
  return text.slice(Math.max(0, text.length - chars));
483
483
  }
484
+ hasLongUnbrokenSegment(text) {
485
+ return /[^\s\n\r\t。?!;;.!?,、]{2001,}/u.test(text);
486
+ }
484
487
  estimateTokens(text) {
485
- if (!/[\s\n\r\t。?!;;.!?,、]/u.test(text) && text.length > 2000)
486
- return Math.max(1, Math.ceil(text.length / 3));
488
+ if (this.hasLongUnbrokenSegment(text))
489
+ return text.length;
487
490
  return Math.max(1, this.tokenizer.countTokens(text));
488
491
  }
489
492
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customize-agent/knowledge",
3
- "version": "4.0.19",
3
+ "version": "4.0.21",
4
4
  "description": "Local knowledge base infrastructure for customize-agent",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",