Class: Woods::Evaluation::BaselineRunner
- Inherits:
-
Object
- Object
- Woods::Evaluation::BaselineRunner
- Defined in:
- lib/woods/evaluation/baseline_runner.rb
Overview
Runs simple baseline strategies for comparison against the full retrieval pipeline.
Provides three baseline strategies:
-
‘:grep` — substring match on unit identifiers
-
‘:random` — random selection from available units
-
‘:file_level` — returns identifiers matching file paths
Constant Summary collapse
- VALID_STRATEGIES =
%i[grep random file_level].freeze
Instance Method Summary collapse
-
#initialize(metadata_store:, seed: nil) ⇒ BaselineRunner
constructor
A new instance of BaselineRunner.
-
#run(query, strategy:, limit: 10) ⇒ Array<String>
Run a baseline strategy for a query.
Constructor Details
#initialize(metadata_store:, seed: nil) ⇒ BaselineRunner
Returns a new instance of BaselineRunner.
27 28 29 30 31 32 33 34 35 |
# File 'lib/woods/evaluation/baseline_runner.rb', line 27 def initialize(metadata_store:, seed: nil) @metadata_store = @random = seed.nil? ? Random.new : Random.new(seed) # Ruby's `Random` instance isn't documented thread-safe; multiple # evaluator threads sharing one runner would otherwise interleave # `sample` calls and drift from the seeded sequence. A plain Mutex # around the read path is enough — `sample` is the only caller. @random_mutex = Mutex.new end |
Instance Method Details
#run(query, strategy:, limit: 10) ⇒ Array<String>
Run a baseline strategy for a query.
44 45 46 47 48 49 50 |
# File 'lib/woods/evaluation/baseline_runner.rb', line 44 def run(query, strategy:, limit: 10) unless VALID_STRATEGIES.include?(strategy) raise ArgumentError, "Invalid strategy: #{strategy}. Must be one of #{VALID_STRATEGIES.join(', ')}" end send(:"run_#{strategy}", query, limit) end |