Class: Kreuzberg::Config::Chunking
- Inherits:
-
Object
- Object
- Kreuzberg::Config::Chunking
- Defined in:
- lib/kreuzberg/config.rb
Overview
Chunking configuration
Instance Attribute Summary collapse
-
#embedding ⇒ Object
readonly
Returns the value of attribute embedding.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#max_chars ⇒ Object
readonly
Returns the value of attribute max_chars.
-
#max_overlap ⇒ Object
readonly
Returns the value of attribute max_overlap.
-
#preset ⇒ Object
readonly
Returns the value of attribute preset.
Instance Method Summary collapse
-
#initialize(max_chars: nil, max_overlap: nil, preset: nil, embedding: nil, chunk_size: nil, chunk_overlap: nil, enabled: true) ⇒ Chunking
constructor
A new instance of Chunking.
- #to_h ⇒ Object
Constructor Details
#initialize(max_chars: nil, max_overlap: nil, preset: nil, embedding: nil, chunk_size: nil, chunk_overlap: nil, enabled: true) ⇒ Chunking
Returns a new instance of Chunking.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/kreuzberg/config.rb', line 198 def initialize( max_chars: nil, max_overlap: nil, preset: nil, embedding: nil, chunk_size: nil, chunk_overlap: nil, enabled: true ) resolved_size = chunk_size || max_chars || 1000 resolved_overlap = chunk_overlap || max_overlap || 200 @max_chars = resolved_size.to_i @max_overlap = resolved_overlap.to_i # Validate positive values raise ArgumentError, "max_chars must be a positive integer, got #{@max_chars}" if @max_chars.negative? raise ArgumentError, "max_overlap must be a positive integer, got #{@max_overlap}" if @max_overlap.negative? @preset = preset&.to_s @embedding = () @enabled = boolean_or_nil(enabled) end |
Instance Attribute Details
#embedding ⇒ Object (readonly)
Returns the value of attribute embedding.
196 197 198 |
# File 'lib/kreuzberg/config.rb', line 196 def @embedding end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
196 197 198 |
# File 'lib/kreuzberg/config.rb', line 196 def enabled @enabled end |
#max_chars ⇒ Object (readonly)
Returns the value of attribute max_chars.
196 197 198 |
# File 'lib/kreuzberg/config.rb', line 196 def max_chars @max_chars end |
#max_overlap ⇒ Object (readonly)
Returns the value of attribute max_overlap.
196 197 198 |
# File 'lib/kreuzberg/config.rb', line 196 def max_overlap @max_overlap end |
#preset ⇒ Object (readonly)
Returns the value of attribute preset.
196 197 198 |
# File 'lib/kreuzberg/config.rb', line 196 def preset @preset end |
Instance Method Details
#to_h ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/kreuzberg/config.rb', line 222 def to_h config = { max_chars: @max_chars, max_overlap: @max_overlap, preset: @preset, embedding: @embedding&.to_h }.compact # @type var config: Hash[Symbol, untyped] config[:enabled] = @enabled unless @enabled.nil? config end |