Class: Langchain::Chunker::Text
- Defined in:
- lib/langchain/chunker/text.rb
Overview
Instance Attribute Summary collapse
-
#chunk_overlap ⇒ Object
readonly
Returns the value of attribute chunk_overlap.
-
#chunk_size ⇒ Object
readonly
Returns the value of attribute chunk_size.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #chunks ⇒ Array<Langchain::Chunk>
-
#initialize(text, chunk_size: 1000, chunk_overlap: 200, separator: "\n\n") ⇒ Text
constructor
A new instance of Text.
Constructor Details
#initialize(text, chunk_size: 1000, chunk_overlap: 200, separator: "\n\n") ⇒ Text
Returns a new instance of Text.
18 19 20 21 22 23 |
# File 'lib/langchain/chunker/text.rb', line 18 def initialize(text, chunk_size: 1000, chunk_overlap: 200, separator: "\n\n") @text = text @chunk_size = chunk_size @chunk_overlap = chunk_overlap @separator = separator end |
Instance Attribute Details
#chunk_overlap ⇒ Object (readonly)
Returns the value of attribute chunk_overlap.
12 13 14 |
# File 'lib/langchain/chunker/text.rb', line 12 def chunk_overlap @chunk_overlap end |
#chunk_size ⇒ Object (readonly)
Returns the value of attribute chunk_size.
12 13 14 |
# File 'lib/langchain/chunker/text.rb', line 12 def chunk_size @chunk_size end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
12 13 14 |
# File 'lib/langchain/chunker/text.rb', line 12 def separator @separator end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
12 13 14 |
# File 'lib/langchain/chunker/text.rb', line 12 def text @text end |
Instance Method Details
#chunks ⇒ Array<Langchain::Chunk>
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/langchain/chunker/text.rb', line 26 def chunks splitter = Baran::CharacterTextSplitter.new( chunk_size: chunk_size, chunk_overlap: chunk_overlap, separator: separator ) splitter.chunks(text).map do |chunk| Langchain::Chunk.new(text: chunk[:text]) end end |