@@ -121,12 +121,18 @@ def chunk_ranges(
121121 while start < text_len :
122122 end = min (start + chunk_size , text_len )
123123 if end < text_len :
124- end = _find_split_point (content , start , end )
124+ split_end = _find_split_point (content , start , end )
125+ # Guard: if split point barely advances (e.g. a single newline
126+ # near `start` followed by a very long line), fall back to the
127+ # hard cut so we always make forward progress.
128+ if split_end - start < max (1 , chunk_size // 4 ):
129+ split_end = end
130+ end = split_end
125131 if content [start :end ].strip ():
126132 ranges .append ((start , end ))
127133 if end >= text_len :
128134 break
129- start = max (0 , end - overlap )
135+ start = max (start + 1 , end - overlap )
130136 return ranges
131137
132138
@@ -327,7 +333,17 @@ def _subprocess_encode_worker(
327333 results : List [Tuple [Dict , "np.ndarray" ]] = []
328334
329335 for doc_idx , doc in enumerate (batch_docs ):
330- content = str (doc .get ("content" , "" ))
336+ # Read file content from disk (not passed in doc to keep IPC small)
337+ abs_path = doc .get ("abs_path" , "" )
338+ if not abs_path :
339+ continue
340+ try :
341+ content = Path (abs_path ).read_text (encoding = "utf-8" , errors = "ignore" )
342+ except Exception as e :
343+ print (f" [child] Error reading { abs_path } : { e } " , flush = True )
344+ continue
345+ if not content .strip ():
346+ continue
331347 ranges = chunk_ranges (content )
332348 if not ranges :
333349 continue
@@ -372,9 +388,13 @@ def _subprocess_encode_worker(
372388
373389 file_embedding = (file_sum / file_chunk_count ).astype ("float32" )
374390 doc ["embedding_chunk_count" ] = file_chunk_count
375- # Strip content before returning to parent — keeps IPC small
376- doc .pop ("content" , None )
377- doc .pop ("context" , None )
391+ doc ["start_char" ] = 0
392+ doc ["end_char" ] = len (content )
393+ doc ["start_line" ] = 1
394+ doc ["end_line" ] = content .count ("\n " ) + 1
395+ doc ["char_range" ] = f"0-{ len (content )} "
396+ # Strip fields that shouldn't go in metadata
397+ doc .pop ("abs_path" , None )
378398 results .append ((doc , file_embedding ))
379399 del file_sum , content
380400
0 commit comments