Module: Legion::LLM::Pipeline::Steps::RagContext

Includes:
Legion::Logging::Helper
Included in:
Executor
Defined in:
lib/legion/llm/pipeline/steps/rag_context.rb

Instance Method Summary collapse

Instance Method Details

#step_rag_contextObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/legion/llm/pipeline/steps/rag_context.rb', line 12

def step_rag_context
  return unless rag_enabled?
  return unless substantive_query?
  return unless apollo_available_or_warn?

  strategy = select_context_strategy(utilization: estimate_utilization)
  return if strategy == :none

  query = extract_query
  start_time = Time.now
  result = apollo_retrieve(query: query, strategy: strategy)
  record_rag_enrichment(result, strategy)
  record_rag_timeline(result, strategy, start_time)
rescue StandardError => e
  @warnings << "RAG context error: #{e.message}"
  handle_exception(e, level: :warn, operation: 'llm.pipeline.steps.rag_context')
end