Module: Legion::LLM::Pipeline::Steps::KnowledgeCapture

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

Instance Method Summary collapse

Instance Method Details

#step_knowledge_captureObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/legion/llm/pipeline/steps/knowledge_capture.rb', line 12

def step_knowledge_capture
  response = current_response
  request = @request
  enrichments = @enrichments
  local_enabled = local_capture_enabled?

  Thread.new do
    if defined?(Legion::Extensions::Apollo::Helpers::Writeback)
      Legion::Extensions::Apollo::Helpers::Writeback.evaluate_and_route(
        request:     request,
        response:    response,
        enrichments: enrichments
      )
    end

    ingest_to_local(response: response) if local_enabled
  rescue StandardError => e
    handle_exception(e, level: :warn, operation: 'llm.pipeline.steps.knowledge_capture.async')
  end

  @timeline.record(
    category: :knowledge, key: 'knowledge:capture',
    direction: :outbound, detail: 'knowledge capture dispatched async',
    from: 'pipeline', to: 'apollo'
  )
rescue StandardError => e
  @warnings << "knowledge_capture error: #{e.message}"
  handle_exception(e, level: :warn, operation: 'llm.pipeline.steps.knowledge_capture')
end