Skip to content

Commit

Permalink
compact chunks on text splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 23, 2023
1 parent bdf9f25 commit feb2fd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/baran/text_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def chunks(text)
cursor = 0
chunks = []

splitted(text).each do |chunk|
splitted(text).compact.each do |chunk|
chunks << { text: chunk, cursor: cursor }
cursor += chunk.length
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_recursive_character_text_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ def test_chunks

assert_equal(chunks.length, 6)
end


def test_empty_chunks
chunks = @splitter.chunks("\n\nHello, world!\n\nHello, world!\n\nHello, world!")

assert_equal(chunks.length, 6)
end
end

0 comments on commit feb2fd8

Please sign in to comment.