Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20250423233959070725.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Fix text chunking logic."
}
4 changes: 4 additions & 0 deletions graphrag/index/text_splitting/text_splitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def split_single_text_on_tokens(text: str, tokenizer: Tokenizer) -> list[str]:
while start_idx < len(input_ids):
chunk_text = tokenizer.decode(list(chunk_ids))
result.append(chunk_text) # Append chunked text as string
if cur_idx == len(input_ids): # prevent single-token chunks
break
start_idx += tokenizer.tokens_per_chunk - tokenizer.chunk_overlap
cur_idx = min(start_idx + tokenizer.tokens_per_chunk, len(input_ids))
chunk_ids = input_ids[start_idx:cur_idx]
Expand Down Expand Up @@ -186,6 +188,8 @@ def split_multiple_texts_on_tokens(
chunk_text = tokenizer.decode([id for _, id in chunk_ids])
doc_indices = list({doc_idx for doc_idx, _ in chunk_ids})
result.append(TextChunk(chunk_text, doc_indices, len(chunk_ids)))
if cur_idx == len(input_ids): # prevent single-token chunks
break
start_idx += tokenizer.tokens_per_chunk - tokenizer.chunk_overlap
cur_idx = min(start_idx + tokenizer.tokens_per_chunk, len(input_ids))
chunk_ids = input_ids[start_idx:cur_idx]
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/indexing/text_splitting/test_text_splitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def test_split_single_text_on_tokens():
" by this t",
"his test o",
"est only.",
"nly.",
]

result = split_single_text_on_tokens(text=text, tokenizer=tokenizer)
Expand Down Expand Up @@ -197,7 +196,6 @@ def decode(tokens: list[int]) -> str:
" this test",
" test only",
" only.",
".",
]

result = split_single_text_on_tokens(text=text, tokenizer=tokenizer)
Expand Down
Loading