Class: Kreuzberg::Config::TokenReduction

Inherits:
Object
  • Object
show all
Defined in:
lib/kreuzberg/config.rb

Overview

Token reduction configuration

Examples:

Disable token reduction

token = TokenReduction.new(mode: "off")

Light reduction

token = TokenReduction.new(mode: "light", preserve_important_words: true)

Aggressive reduction

token = TokenReduction.new(mode: "aggressive", preserve_important_words: false)

Constant Summary collapse

VALID_MODES =
%w[off light moderate aggressive maximum].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode: 'off', preserve_important_words: true) ⇒ TokenReduction

Returns a new instance of TokenReduction.

Raises:

  • (ArgumentError)


585
586
587
588
589
590
591
592
593
# File 'lib/kreuzberg/config.rb', line 585

def initialize(mode: 'off', preserve_important_words: true)
  @mode = mode.to_s
  @preserve_important_words = preserve_important_words ? true : false

  # Validate mode against known valid modes
  return if VALID_MODES.include?(@mode)

  raise ArgumentError, "Invalid token reduction mode: #{@mode}. Valid modes are: #{VALID_MODES.join(', ')}"
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



581
582
583
# File 'lib/kreuzberg/config.rb', line 581

def mode
  @mode
end

#preserve_important_wordsObject (readonly)

Returns the value of attribute preserve_important_words.



581
582
583
# File 'lib/kreuzberg/config.rb', line 581

def preserve_important_words
  @preserve_important_words
end

Instance Method Details

#to_hObject



595
596
597
598
599
600
# File 'lib/kreuzberg/config.rb', line 595

def to_h
  {
    mode: @mode,
    preserve_important_words: @preserve_important_words
  }
end