Module: Legion::LLM::Inference::Steps::KnowledgeCapture

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

Constant Summary collapse

EMBED_MAX_CHARS =
2000

Instance Method Summary collapse

Instance Method Details

#step_knowledge_captureObject



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
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/llm/inference/steps/knowledge_capture.rb', line 14

def step_knowledge_capture
  response = current_response
  request = @request
  enrichments = @enrichments
  local_enabled = local_capture_enabled?
  content_chars = response&.message&.dig(:content).to_s.length
  log_step_info(
    :knowledge_capture,
    :dispatch_async,
    local_enabled:       local_enabled,
    writeback_available: defined?(Legion::Extensions::Apollo::Helpers::Writeback),
    response_chars:      content_chars
  )

  Executor::ASYNC_THREAD_POOL.post do
    if defined?(Legion::Extensions::Apollo::Helpers::Writeback)
      log_step_debug(:knowledge_capture, :writeback_route)
      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