lex-knowledge 0.6.6 → 0.6.9
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29631e6f2778ceedf74b69197379edc4c215d9b7ff4b2e088790dedc227fd90f
|
|
4
|
+
data.tar.gz: d96dd08d5a1450e5e1f3db0936729d3a40c834edc166126d6c9dd73a1839518f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 971edc3c4347a949a89b690cccda16150e5644be27eb201d22daeaab0e293cc03ebf530e509712a514eb2f40e3e86c201ce96475c2cbf398252fcae73bc0af64
|
|
7
|
+
data.tar.gz: 980eb54c45d386db31c1ed817f41f2f12d6a7993e07db910c016398ddb5229274622c720e78eb1aabcb0920d01772de63627ecbff6653bb051b893b7e230d766
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'digest'
|
|
4
|
-
require 'find'
|
|
5
4
|
|
|
6
5
|
module Legion
|
|
7
6
|
module Extensions
|
|
@@ -12,19 +11,28 @@ module Legion
|
|
|
12
11
|
|
|
13
12
|
def scan(path:, extensions: %w[.md .txt .docx .pdf])
|
|
14
13
|
results = []
|
|
14
|
+
walk(path, extensions, results)
|
|
15
|
+
results
|
|
16
|
+
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
next unless ::File.file?(entry)
|
|
21
|
-
next unless extensions.include?(::File.extname(entry).downcase)
|
|
18
|
+
def walk(entry, extensions, results)
|
|
19
|
+
basename = ::File.basename(entry)
|
|
20
|
+
return if basename.start_with?('.')
|
|
22
21
|
|
|
22
|
+
if ::File.directory?(entry)
|
|
23
|
+
::Dir.children(entry).each { |c| walk(::File.join(entry, c), extensions, results) }
|
|
24
|
+
elsif ::File.file?(entry) && extensions.include?(::File.extname(entry).downcase)
|
|
23
25
|
results << build_entry(entry)
|
|
24
26
|
end
|
|
27
|
+
rescue Errno::EPERM, Errno::EACCES, Errno::ELOOP, Errno::ENOENT => e
|
|
28
|
+
log.debug("[manifest] skipping unreadable #{entry}: #{e.class}: #{e.message}")
|
|
29
|
+
end
|
|
30
|
+
private_class_method :walk
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
def log
|
|
33
|
+
Legion::Logging
|
|
27
34
|
end
|
|
35
|
+
private_class_method :log
|
|
28
36
|
|
|
29
37
|
def diff(current:, previous:)
|
|
30
38
|
current_map = current.to_h { |e| [e[:path], e[:sha256]] }
|
|
@@ -47,16 +47,19 @@ module Legion
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def health(path:)
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
resolved = path || (Legion::Settings.dig(:knowledge, :corpus_path) if defined?(Legion::Settings))
|
|
51
|
+
return { success: false, error: 'corpus_path is required' } if resolved.nil? || resolved.to_s.empty?
|
|
52
|
+
|
|
53
|
+
scan_entries = Helpers::Manifest.scan(path: resolved)
|
|
54
|
+
store_path = Helpers::ManifestStore.store_path(corpus_path: resolved)
|
|
52
55
|
manifest_file = ::File.exist?(store_path)
|
|
53
56
|
last_ingest = manifest_file ? ::File.mtime(store_path).iso8601 : nil
|
|
54
57
|
|
|
55
58
|
{
|
|
56
59
|
success: true,
|
|
57
|
-
local: build_local_stats(
|
|
60
|
+
local: build_local_stats(resolved, scan_entries, manifest_file, last_ingest),
|
|
58
61
|
apollo: build_apollo_stats,
|
|
59
|
-
sync: build_sync_stats(
|
|
62
|
+
sync: build_sync_stats(resolved, scan_entries)
|
|
60
63
|
}
|
|
61
64
|
rescue StandardError => e
|
|
62
65
|
{ success: false, error: e.message }
|
|
@@ -69,11 +69,12 @@ module Legion
|
|
|
69
69
|
def retrieve_chunks(question, top_k)
|
|
70
70
|
return [] unless defined?(Legion::Extensions::Apollo)
|
|
71
71
|
|
|
72
|
-
Legion::Extensions::Apollo::Runners::Knowledge.retrieve_relevant(
|
|
72
|
+
result = Legion::Extensions::Apollo::Runners::Knowledge.retrieve_relevant(
|
|
73
73
|
query: question,
|
|
74
74
|
limit: top_k,
|
|
75
75
|
tags: ['document_chunk']
|
|
76
76
|
)
|
|
77
|
+
result.is_a?(Hash) && result[:success] ? Array(result[:entries]) : []
|
|
77
78
|
rescue StandardError => _e
|
|
78
79
|
[]
|
|
79
80
|
end
|