Spaces:
Paused

nexus / core /search.py
dushyantsingh0
Beta 1.0: Pure Backend Release (Excluding Frontend)
5eb4857
Raw History Blame Contribute Delete
732 Bytes
from typing import List
def chunk_text(text: str, chunk_size: int = 600, chunk_overlap: int = 100) -> List[str]:
"""
Simple recursive-style character splitter for text chunking.
Ensures chunks have the specified overlap for context preservation.
"""
if not text:
return []
chunks = []
start = 0
while start < len(text):
end = start + chunk_size
chunk = text[start:end]
chunks.append(chunk)
# Move start forward by chunk_size minus overlap
start += (chunk_size - chunk_overlap)
# Prevent infinite loop if overlap >= size
if chunk_overlap >= chunk_size:
start = end
return chunks