lex-knowledge 0.6.14 → 0.6.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21c773508b11dfb12b4d07bf2e37705483b82f4100382c29d84d883f3790ce5c
4
- data.tar.gz: 96c6e3da83bb20eabb5db9f55b8ef4b7715ac08d3110ec4c6680ccf6b62210e4
3
+ metadata.gz: 28e36fec6a26f06e680ef33e0cbf8bf52d49762c1996d9257883b8b26524fab8
4
+ data.tar.gz: 2097de8337c7b06c8ac4a4bc1ebca123e642900991a2219e4e9adb31eca0d601
5
5
  SHA512:
6
- metadata.gz: 5e2a5993ca4b4213c1dfb25eff797aaf7b89af3b5bc4c37072683d564bc49db49aad6f30702f47c19bd66c008bcdcc9b9a29b075920b66c03ab237dd4e9070e0
7
- data.tar.gz: 04f3d33195e5c81c4b48c361170909b6f8a53e28660a0d30370584453a847f8d787443261ffa1b47a383c58aa387281616a29f1a2366c6c46e43308d82284808
6
+ metadata.gz: 5ed0345d3cb7c5cd8f52c0f2fa5fb3782f2d251a4a522709a7e5a0576ca5de4ca6b8d15897a49167caa6fe6629c81751ffaf84122a3534374edc99ab7a4b71ea
7
+ data.tar.gz: c684f6f7842c465b7e9c3879a6c6ba8b545ec4dc8787a87945098f7df0e9eb50fa8fc0ced89b706080a4cab64c0b23483ebc8369d13d1887ab0a75312ec91409
@@ -21,16 +21,20 @@ module Legion
21
21
  end
22
22
 
23
23
  def enabled? # rubocop:disable Legion/Extension/ActorEnabledSideEffects
24
- return false unless corpus_path && !corpus_path.empty?
24
+ return true if corpus_path && !corpus_path.empty?
25
25
 
26
- true
26
+ Runners::Monitor.resolve_monitors.any?
27
27
  rescue StandardError => e
28
28
  handle_exception(e, level: :warn, operation: 'knowledge.maintenance_runner.enabled')
29
29
  false
30
30
  end
31
31
 
32
32
  def args
33
- { path: corpus_path }
33
+ path = corpus_path
34
+ return { path: path } if path && !path.empty?
35
+
36
+ monitors = Runners::Monitor.resolve_monitors
37
+ monitors.any? ? { path: monitors.first[:path] } : { path: nil }
34
38
  end
35
39
 
36
40
  private
@@ -240,7 +240,7 @@ module Legion
240
240
  private_class_method :build_exists_map
241
241
 
242
242
  def llm_embed_available?
243
- defined?(Legion::LLM) && Legion::LLM.respond_to?(:embed_batch)
243
+ defined?(Legion::LLM) && (Legion::LLM.respond_to?(:embed_batch) || Legion::LLM.respond_to?(:embed))
244
244
  end
245
245
  private_class_method :llm_embed_available?
246
246
 
@@ -250,9 +250,19 @@ module Legion
250
250
  private_class_method :paired_without_embed
251
251
 
252
252
  def build_embed_map(needs_embed)
253
- results = Legion::LLM.embed_batch(needs_embed.map { |c| c[:content] }) # rubocop:disable Legion/HelperMigration/DirectLlm
254
- results.each_with_object({}) do |r, h|
255
- h[needs_embed[r[:index]][:content_hash]] = r[:vector] unless r[:error]
253
+ if Legion::LLM.respond_to?(:embed_batch)
254
+ results = Legion::LLM.embed_batch(needs_embed.map { |c| c[:content] }) # rubocop:disable Legion/HelperMigration/DirectLlm
255
+ results.each_with_object({}) do |r, h|
256
+ h[needs_embed[r[:index]][:content_hash]] = r[:vector] unless r[:error]
257
+ end
258
+ else
259
+ needs_embed.each_with_object({}) do |chunk, h|
260
+ result = Legion::LLM.embed(chunk[:content]) # rubocop:disable Legion/HelperMigration/DirectLlm
261
+ vector = result.is_a?(Hash) ? result[:vector] : result
262
+ h[chunk[:content_hash]] = vector if vector.is_a?(Array) && vector.any?
263
+ rescue StandardError => e
264
+ log.warn(e.message)
265
+ end
256
266
  end
257
267
  rescue StandardError => e
258
268
  handle_exception(e, level: :warn, operation: 'knowledge.ingest.build_embed_map')
@@ -328,10 +338,10 @@ module Legion
328
338
  return unless Legion::Apollo.respond_to?(:ingest) && Legion::Apollo.started?
329
339
 
330
340
  Legion::Apollo.ingest( # rubocop:disable Legion/HelperMigration/DirectKnowledge
331
- content: file_path,
332
- content_type: 'document_retired',
341
+ content: "Retired document: #{file_path}",
342
+ content_type: 'observation',
333
343
  tags: [file_path, 'retired', 'document_chunk'].uniq,
334
- metadata: { source_file: file_path, retired: true }
344
+ context: { source_file: file_path, retired: true }
335
345
  )
336
346
  rescue StandardError => e
337
347
  handle_exception(e, level: :warn, operation: 'knowledge.ingest.retire_file', file_path: file_path)
@@ -296,7 +296,7 @@ module Legion
296
296
  def query_count
297
297
  return 0 unless Helpers::ApolloModels.access_log_available?
298
298
 
299
- Helpers::ApolloModels.access_log.where(action: 'knowledge_query').count
299
+ Helpers::ApolloModels.access_log.where(action: 'query').count
300
300
  rescue StandardError => e
301
301
  handle_exception(e, level: :warn, operation: 'knowledge.maintenance.query_count')
302
302
  0
@@ -181,11 +181,14 @@ module Legion
181
181
  "Context:\n#{context_text}\n\nQuestion: #{question}\n\nAnswer:"
182
182
  end
183
183
 
184
- result = llm_chat(message: prompt, caller: { extension: 'lex-knowledge' })
185
- result.is_a?(Hash) ? result[:content] : result
184
+ result = Legion::LLM.chat( # rubocop:disable Legion/HelperMigration/DirectLlm
185
+ message: prompt,
186
+ caller: { extension: 'lex-knowledge' }
187
+ )
188
+ result.is_a?(Hash) ? result[:content] : result.content
186
189
  rescue StandardError => e
187
190
  handle_exception(e, level: :warn, operation: 'knowledge.query.synthesize_answer')
188
- "Error generating answer: #{e.message}"
191
+ nil
189
192
  end
190
193
  private_class_method :synthesize_answer
191
194
 
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Knowledge
6
- VERSION = '0.6.14'
6
+ VERSION = '0.6.15'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-knowledge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.14
4
+ version: 0.6.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Iverson