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)


589
590
591
592
593
594
595
596
597
# File 'lib/kreuzberg/config.rb', line 589

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.



585
586
587
# File 'lib/kreuzberg/config.rb', line 585

def mode
  @mode
end

#preserve_important_wordsObject (readonly)

Returns the value of attribute preserve_important_words.



585
586
587
# File 'lib/kreuzberg/config.rb', line 585

def preserve_important_words
  @preserve_important_words
end

Instance Method Details

#to_hObject



599
600
601
602
603
604
# File 'lib/kreuzberg/config.rb', line 599

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