@customize-agent/knowledge 4.0.20 → 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.
|
@@ -295,7 +295,7 @@ 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 (
|
|
298
|
+
if (this.hasLongUnbrokenSegment(text) && text.length > Math.max(2000, maxTokens * 3)) {
|
|
299
299
|
const maxChars = Math.max(1, maxTokens);
|
|
300
300
|
const overlapChars = Math.max(0, Math.min(Math.floor(maxChars / 2), overlapTokens));
|
|
301
301
|
const step = Math.max(1, maxChars - overlapChars);
|
|
@@ -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 (
|
|
486
|
-
return
|
|
488
|
+
if (this.hasLongUnbrokenSegment(text))
|
|
489
|
+
return text.length;
|
|
487
490
|
return Math.max(1, this.tokenizer.countTokens(text));
|
|
488
491
|
}
|
|
489
492
|
}
|