Skip to content

Commit 6b97ec4

Browse files
committed
feat: add soft max for code segment length
1 parent ee8ec12 commit 6b97ec4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/services/code-index/processors/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { scannerExtensions } from "../shared/supported-extensions"
99
const MAX_BLOCK_CHARS = 1000
1010
const MIN_BLOCK_CHARS = 100
1111
const MIN_CHUNK_REMAINDER_CHARS = 200 // Minimum characters for the *next* chunk after a split
12+
const MAX_CHARS_TOLERANCE_FACTOR = 1.15 // 15% tolerance for max chars
1213

1314
/**
1415
* Implementation of the code parser interface
@@ -150,7 +151,7 @@ export class CodeParser implements ICodeParser {
150151
// Check if the node meets the minimum character requirement
151152
if (currentNode.text.length >= MIN_BLOCK_CHARS) {
152153
// If it also exceeds the maximum character limit, try to break it down
153-
if (currentNode.text.length > MAX_BLOCK_CHARS) {
154+
if (currentNode.text.length > MAX_BLOCK_CHARS * MAX_CHARS_TOLERANCE_FACTOR) {
154155
if (currentNode.children.length > 0) {
155156
// If it has children, process them instead
156157
queue.push(...currentNode.children)

0 commit comments

Comments
 (0)