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 +4 -4
- data/lib/legion/extensions/knowledge/actors/maintenance_runner.rb +7 -3
- data/lib/legion/extensions/knowledge/runners/ingest.rb +17 -7
- data/lib/legion/extensions/knowledge/runners/maintenance.rb +1 -1
- data/lib/legion/extensions/knowledge/runners/query.rb +6 -3
- data/lib/legion/extensions/knowledge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28e36fec6a26f06e680ef33e0cbf8bf52d49762c1996d9257883b8b26524fab8
|
|
4
|
+
data.tar.gz: 2097de8337c7b06c8ac4a4bc1ebca123e642900991a2219e4e9adb31eca0d601
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
24
|
+
return true if corpus_path && !corpus_path.empty?
|
|
25
25
|
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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: '
|
|
341
|
+
content: "Retired document: #{file_path}",
|
|
342
|
+
content_type: 'observation',
|
|
333
343
|
tags: [file_path, 'retired', 'document_chunk'].uniq,
|
|
334
|
-
|
|
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: '
|
|
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 =
|
|
185
|
-
|
|
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
|
-
|
|
191
|
+
nil
|
|
189
192
|
end
|
|
190
193
|
private_class_method :synthesize_answer
|
|
191
194
|
|