Class: Legion::CLI::Knowledge
- Inherits:
-
Thor
- Object
- Thor
- Legion::CLI::Knowledge
- Defined in:
- lib/legion/cli/knowledge_command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #health ⇒ Object
- #ingest(path) ⇒ Object
- #maintain ⇒ Object
- #quality ⇒ Object
- #query(question) ⇒ Object
- #retrieve(question) ⇒ Object
- #status ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
273 274 275 |
# File 'lib/legion/cli/knowledge_command.rb', line 273 def self.exit_on_failure? true end |
Instance Method Details
#health ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/legion/cli/knowledge_command.rb', line 354 def health result = api_post('/api/knowledge/health', path: [:corpus_path]) out = formatter if [:json] out.json(result) elsif result[:success] out.header('Knowledge Health') out.spacer out.header('Local') out.detail(result[:local]) out.spacer out.header('Apollo') out.detail(result[:apollo]) out.spacer out.header('Sync') out.detail(result[:sync]) else out.warn("Health check failed: #{result[:error]}") end end |
#ingest(path) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/legion/cli/knowledge_command.rb', line 322 def ingest(path) result = api_post('/api/knowledge/ingest', path: ::File.(path), force: [:force], dry_run: [:dry_run]) out = formatter if [:json] out.json(result) elsif result[:success] out.success('Ingest complete') out.detail(result.except(:success)) else out.warn("Ingest failed: #{result[:error]}") end end |
#maintain ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/legion/cli/knowledge_command.rb', line 378 def maintain result = api_post('/api/knowledge/maintain', path: [:corpus_path], dry_run: [:dry_run]) out = formatter if [:json] out.json(result) elsif result[:success] out.header("Knowledge Maintain#{' (dry run)' if [:dry_run]}") out.detail({ 'Orphan files' => (result[:orphan_files] || []).join(', '), 'Archived' => result[:archived].to_s, 'Files cleaned' => result[:files_cleaned].to_s, 'Dry run' => result[:dry_run].to_s }) else out.warn("Maintenance failed: #{result[:error]}") end end |
#quality ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/legion/cli/knowledge_command.rb', line 399 def quality result = api_post('/api/knowledge/quality', limit: [:limit]) out = formatter if [:json] out.json(result) elsif result[:success] out.header('Knowledge Quality Report') out.spacer print_chunk_section('Hot Chunks (most accessed)', result[:hot_chunks], out) print_chunk_section('Cold Chunks (never accessed)', result[:cold_chunks], out) print_chunk_section('Low Confidence', result[:low_confidence], out) out.spacer out.header('Summary') out.detail(result[:summary]) else out.warn("Quality report failed: #{result[:error]}") end end |
#query(question) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/legion/cli/knowledge_command.rb', line 284 def query(question) result = api_post('/api/knowledge/query', question: question, top_k: [:top_k], synthesize: [:synthesize]) out = formatter if [:json] out.json(result) elsif result[:success] out.header('Knowledge Query') if result[:answer] out.spacer puts result[:answer] out.spacer end print_sources(result[:sources] || [], out, verbose: [:verbose]) else out.warn("Query failed: #{result[:error]}") end end |
#retrieve(question) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/legion/cli/knowledge_command.rb', line 306 def retrieve(question) result = api_post('/api/knowledge/retrieve', question: question, top_k: [:top_k]) out = formatter if [:json] out.json(result) elsif result[:success] out.header("Knowledge Retrieve (#{(result[:sources] || []).size} chunks)") print_sources(result[:sources] || [], out, verbose: true) else out.warn("Retrieve failed: #{result[:error]}") end end |
#status ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/legion/cli/knowledge_command.rb', line 337 def status result = api_post('/api/knowledge/status', path: ::Dir.pwd) out = formatter if [:json] out.json(result) else out.header('Knowledge Status') out.detail({ 'Path' => result[:path].to_s, 'Files' => result[:file_count].to_s, 'Total size' => "#{result[:total_bytes]} bytes" }) end end |