Class: Aoororachain::RecursiveTextSplitter
- Inherits:
-
Object
- Object
- Aoororachain::RecursiveTextSplitter
- Defined in:
- lib/aoororachain/recursive_text_splitter.rb
Instance Method Summary collapse
-
#initialize(size: 1024, overlap: 200) ⇒ RecursiveTextSplitter
constructor
A new instance of RecursiveTextSplitter.
- #split_documents(documents) ⇒ Object
- #split_text(text) ⇒ Object
Constructor Details
#initialize(size: 1024, overlap: 200) ⇒ RecursiveTextSplitter
Returns a new instance of RecursiveTextSplitter.
5 6 7 8 |
# File 'lib/aoororachain/recursive_text_splitter.rb', line 5 def initialize(size: 1024, overlap: 200) @size = size @overlap = overlap end |
Instance Method Details
#split_documents(documents) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aoororachain/recursive_text_splitter.rb', line 10 def split_documents(documents) original_documents = Array(documents) new_documents = [] original_documents.each do |document| texts = split_text(document.content) texts.each do |text| new_documents << Document.new(text, document.) end end new_documents end |
#split_text(text) ⇒ Object
24 25 26 |
# File 'lib/aoororachain/recursive_text_splitter.rb', line 24 def split_text(text) split_recursive(text, 0, []) end |