Module: Legion::Extensions::Knowledge::Runners::Maintenance
- Extended by:
- Logging::Helper, Settings::Helper
- Included in:
- Client
- Defined in:
- lib/legion/extensions/knowledge/runners/maintenance.rb
Overview
rubocop:disable Legion/Extension/RunnerIncludeHelpers
Class Method Summary collapse
- .cleanup_orphans(path:, dry_run: true) ⇒ Object
- .detect_orphans(path:) ⇒ Object
- .health(path:) ⇒ Object
- .quality_report(limit: nil) ⇒ Object
- .reindex(path:) ⇒ Object
Class Method Details
.cleanup_orphans(path:, dry_run: true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/knowledge/runners/maintenance.rb', line 33 def cleanup_orphans(path:, dry_run: true) detection = detect_orphans(path: path) return detection unless detection[:success] return detection.merge(archived: 0, files_cleaned: 0, dry_run: dry_run) if detection[:orphan_count].zero? return detection.merge(archived: detection[:orphan_count], files_cleaned: detection[:orphan_files].size, dry_run: true) if dry_run archived = archive_orphan_entries(detection[:orphan_files]) { success: true, archived: archived, files_cleaned: detection[:orphan_files].size, dry_run: false } rescue StandardError => e handle_exception(e, level: :warn, operation: 'knowledge.maintenance.cleanup_orphans', path: path) { success: false, error: e. } end |
.detect_orphans(path:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/knowledge/runners/maintenance.rb', line 15 def detect_orphans(path:) manifest_files = load_manifest_files(path) apollo_files = load_apollo_source_files orphan_files = apollo_files - manifest_files { success: true, orphan_count: orphan_files.size, orphan_files: orphan_files, total_apollo_chunks: count_apollo_chunks, total_manifest_files: manifest_files.size } rescue StandardError => e handle_exception(e, level: :warn, operation: 'knowledge.maintenance.detect_orphans', path: path) { success: false, error: e. } end |
.health(path:) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/knowledge/runners/maintenance.rb', line 57 def health(path:) resolved = path || settings[:corpus_path] return { success: false, error: 'corpus_path is required' } if resolved.nil? || resolved.to_s.empty? scan_entries = Helpers::Manifest.scan(path: resolved) store_path = Helpers::ManifestStore.store_path(corpus_path: resolved) manifest_file = ::File.exist?(store_path) last_ingest = manifest_file ? ::File.mtime(store_path).iso8601 : nil { success: true, local: build_local_stats(resolved, scan_entries, manifest_file, last_ingest), apollo: build_apollo_stats, sync: build_sync_stats(resolved, scan_entries) } rescue StandardError => e handle_exception(e, level: :warn, operation: 'knowledge.maintenance.health', path: path) { success: false, error: e. } end |
.quality_report(limit: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/legion/extensions/knowledge/runners/maintenance.rb', line 77 def quality_report(limit: nil) resolved_limit = limit || settings[:maintenance][:quality_report_limit] { success: true, hot_chunks: hot_chunks(resolved_limit), cold_chunks: cold_chunks(resolved_limit), low_confidence: low_confidence_chunks(resolved_limit), poor_retrieval: [], summary: quality_summary } rescue StandardError => e handle_exception(e, level: :warn, operation: 'knowledge.maintenance.quality_report') { success: false, error: e. } end |
.reindex(path:) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/legion/extensions/knowledge/runners/maintenance.rb', line 47 def reindex(path:) store_path = Helpers::ManifestStore.store_path(corpus_path: path) ::FileUtils.rm_f(store_path) Runners::Ingest.ingest_corpus(path: path, force: true) rescue StandardError => e handle_exception(e, level: :warn, operation: 'knowledge.maintenance.reindex', path: path) { success: false, error: e. } end |