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: 9db1bb96787265658439252f9632523d527f1b34b759769379a62b3577d64db5
4
- data.tar.gz: c072f647cf7b91c55ebf1edb77c1ca2cbe57fde4e00a968f2e7b016502271c9c
3
+ metadata.gz: 29631e6f2778ceedf74b69197379edc4c215d9b7ff4b2e088790dedc227fd90f
4
+ data.tar.gz: d96dd08d5a1450e5e1f3db0936729d3a40c834edc166126d6c9dd73a1839518f
5
5
  SHA512:
6
- metadata.gz: 7058729c26b22b3b85674650e91f1be9ab8869761cfae0ec710d3aafea306daad91e66a14d69fea55349666c135e8a6bd32a97068ac520adc74e34b47b1536b2
7
- data.tar.gz: 78176d44e646f407bd7dfe3852d0249779404df4e690c16a2abd8a391a7f29e580bff4cdcd9cb893a7ee6849dfc1f01bfdfa27f1870a1d0aceb9aaae8f4f0524
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
- Find.find(path) do |entry|
17
- basename = ::File.basename(entry)
18
- Find.prune if basename.start_with?('.')
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
- results
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
- scan_entries = Helpers::Manifest.scan(path: path)
51
- store_path = Helpers::ManifestStore.store_path(corpus_path: path)
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(path, scan_entries, manifest_file, last_ingest),
60
+ local: build_local_stats(resolved, scan_entries, manifest_file, last_ingest),
58
61
  apollo: build_apollo_stats,
59
- sync: build_sync_stats(path, scan_entries)
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
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Knowledge
6
- VERSION = '0.6.6'
6
+ VERSION = '0.6.9'
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.6
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Iverson