class Ragdoll::CLI::Main
Public Class Methods
Source
# File lib/ragdoll/cli.rb, line 23 def initialize(args = [], local_options = {}, config = {}) super load_configuration end
Calls superclass method
Public Instance Methods
Source
# File lib/ragdoll/cli.rb, line 290 def add(*paths) if paths.empty? puts 'Error: No paths provided' puts 'Usage: ragdoll add PATH [PATH2] [PATH3]...' puts 'Examples:' puts ' ragdoll add file.pdf' puts ' ragdoll add ../docs' puts ' ragdoll add ../docs/**/*.md' puts ' ragdoll add file1.txt file2.pdf ../docs' exit 1 end client = StandaloneClient.new all_results = [] # First pass: collect all files to process all_files = [] paths.each do |path| if path.include?('*') || path.include?('?') all_files.concat(collect_files_from_glob(path, options)) elsif File.directory?(path) all_files.concat(collect_files_from_directory(path, options)) elsif File.file?(path) all_files << path else puts "Warning: Path not found or not accessible: #{path}" end end if all_files.empty? puts "No files found to process." return end # Initialize progress bar progressbar = ProgressBar.create( title: "Adding documents", total: all_files.length, format: "%t: |%B| %p%% (%c/%C) %e %f" ) # Second pass: process each file with progress all_files.each do |file_path| progressbar.log "Processing: #{File.basename(file_path)}" result = process_single_file(client, file_path, options) all_results << result progressbar.increment end progressbar.finish # Summary success_count = all_results.count { |r| r && r[:status] == 'success' } error_count = all_results.count { |r| r && r[:status] == 'error' } puts "\nCompleted:" puts " Successfully added: #{success_count} files" puts " Errors: #{error_count} files" if error_count > 0 puts "\nErrors:" all_results.select { |r| r && r[:status] == 'error' }.each do |result| puts " #{result[:file]}: #{result[:error] || result[:message]}" end end return unless success_count > 0 puts "\nSuccessfully added files:" all_results.select { |r| r && r[:status] == 'success' }.each do |result| puts " #{result[:file]} (ID: #{result[:document_id]})" puts " #{result[:message]}" if result[:message] end puts "\nNote: Documents are being processed in the background." puts "Use 'ragdoll status <id>' to check processing status." end
Source
# File lib/ragdoll/cli.rb, line 529 def cleanup_searches analytics = Analytics.new analytics.options = options analytics.cleanup end
Source
# File lib/ragdoll/cli.rb, line 448 def context(query) client = StandaloneClient.new context_options = { limit: options[:limit] } context_options[:threshold] = options[:threshold] if options[:threshold] ctx = client.get_context(query, **context_options) # Check if no context was found and provide enhanced feedback if ctx[:context_chunks].empty? # Get the underlying search response for statistics search_response = client.search(query, **context_options) display_no_results_feedback(query, search_response, 'context') else puts JSON.pretty_generate(ctx) end end
Source
# File lib/ragdoll/cli.rb, line 441 def delete(document_id) Delete.new.call(document_id, options) end
Source
# File lib/ragdoll/cli.rb, line 467 def enhance(prompt) client = StandaloneClient.new enhance_options = { context_limit: options[:limit] } enhance_options[:threshold] = options[:threshold] if options[:threshold] enhanced = client.enhance_prompt(prompt, **enhance_options) # Check if no context was found and provide enhanced feedback if enhanced[:context_count] == 0 # Get the underlying search response for statistics search_response = client.search(prompt, limit: enhance_options[:context_limit], threshold: enhance_options[:threshold]) display_no_results_feedback(prompt, search_response, 'enhance') else puts enhanced[:enhanced_prompt] end end
Source
# File lib/ragdoll/cli.rb, line 198 def health client = StandaloneClient.new if client.healthy? puts '✓ System is healthy' puts '✓ Database connection: OK' puts '✓ Configuration: OK' else puts '✗ System health check failed' exit 1 end end
Source
# File lib/ragdoll/cli.rb, line 220 def list client = StandaloneClient.new # Handle keyword filtering if provided if options[:keywords] keywords_array = options[:keywords].split(',').map(&:strip) search_method = options[:keywords_all] ? :search_by_keywords_all : :search_by_keywords documents = client.public_send(search_method, keywords_array, limit: options[:limit]) puts "Listing documents with keywords: #{keywords_array.join(', ')}" puts "Mode: #{options[:keywords_all] ? 'ALL keywords (AND)' : 'ANY keywords (OR)'}" puts else documents = client.list_documents(limit: options[:limit]) end # Get accurate embeddings count for all documents documents.each do |doc| begin status_info = client.document_status(doc[:id] || doc['id']) doc[:embeddings_count] = status_info[:embeddings_count] rescue # Keep original count if status fails end end case options[:format] when 'json' puts JSON.pretty_generate(documents) when 'plain' documents.each do |doc| puts "#{doc[:id]}: #{doc[:title] || 'Untitled'}" end else # Table format - show keywords if keyword filtering is being used if options[:keywords] puts 'ID'.ljust(10) + 'Title'.ljust(30) + 'Keywords'.ljust(35) + 'Status'.ljust(10) + 'Emb' puts '-' * 90 documents.each do |doc| id = (doc[:id] || doc['id'] || '')[0..9].ljust(10) title = (doc[:title] || doc['title'] || 'Untitled')[0..29].ljust(30) keywords = (doc[:keywords] || doc['keywords'] || []).join(', ')[0..34].ljust(35) status = (doc[:status] || doc['status'] || 'unknown')[0..9].ljust(10) embeddings = (doc[:embeddings_count] || doc['embeddings_count'] || 0).to_s puts "#{id}#{title}#{keywords}#{status}#{embeddings}" end else puts 'ID'.ljust(10) + 'Title'.ljust(40) + 'Status'.ljust(12) + 'Embeddings' puts '-' * 80 documents.each do |doc| id = (doc[:id] || doc['id'] || '')[0..9].ljust(10) title = (doc[:title] || doc['title'] || 'Untitled')[0..39].ljust(40) status = (doc[:status] || doc['status'] || 'unknown')[0..11].ljust(12) embeddings = (doc[:embeddings_count] || doc['embeddings_count'] || 0).to_s puts "#{id}#{title}#{status}#{embeddings}" end end end end
Source
# File lib/ragdoll/cli.rb, line 68 def search(query) Search.new.call(query, options) end
Source
# File lib/ragdoll/cli.rb, line 492 def search_history analytics = Analytics.new analytics.options = options analytics.history end
Source
# File lib/ragdoll/cli.rb, line 503 def search_stats analytics = Analytics.new analytics.options = options analytics.overview end
Source
# File lib/ragdoll/cli.rb, line 157 def show(document_id) client = StandaloneClient.new begin document = client.get_document(document_id) case options[:format] when 'json' puts JSON.pretty_generate(document) else puts "Document Details for ID: #{document_id}" puts " Title: #{document[:title]}" puts " Status: #{document[:status]}" puts " Embeddings Count: #{document[:embeddings_count]}" puts " Content Length: #{document[:content_length]} characters" # Show keywords prominently keywords = document[:keywords] || document['keywords'] || [] if keywords.any? puts " Keywords: #{keywords.join(', ')}" else puts " Keywords: (none)" end puts " Created: #{document[:created_at]}" puts " Updated: #{document[:updated_at]}" if document[:metadata] && document[:metadata].any? puts "\nMetadata:" document[:metadata].each do |key, value| next if key == 'keywords' # Already displayed above puts " #{key}: #{value}" end end end rescue StandardError => e puts "Error getting document: #{e.message}" end end
Source
# File lib/ragdoll/cli.rb, line 82 def stats client = StandaloneClient.new stats = client.stats puts 'System Statistics:' puts " Total documents: #{stats[:total_documents]}" puts " Total embeddings: #{stats[:total_embeddings]}" puts " Storage type: #{stats[:storage_type] || 'unknown'}" if stats[:by_status] puts " Documents by status:" stats[:by_status].each do |status, count| puts " #{status}: #{count}" end end if stats[:by_type] puts " Documents by type:" stats[:by_type].each do |type, count| puts " #{type}: #{count}" end end if stats[:content_types] puts "\nContent Types:" stats[:content_types].each do |type, count| puts " #{type}: #{count}" end end # Add search analytics if available begin search_analytics = client.search_analytics(days: 30) if search_analytics && !search_analytics.empty? puts "\nSearch Analytics (last 30 days):" puts " Total searches: #{search_analytics[:total_searches] || 0}" puts " Unique queries: #{search_analytics[:unique_queries] || 0}" puts " Avg results per search: #{search_analytics[:avg_results_per_search] || 0}" puts " Avg execution time: #{search_analytics[:avg_execution_time] || 0}ms" if search_analytics[:search_types] puts " Search types:" search_analytics[:search_types].each do |type, count| puts " #{type}: #{count}" end end puts " Searches with results: #{search_analytics[:searches_with_results] || 0}" puts " Avg click-through rate: #{search_analytics[:avg_click_through_rate] || 0}%" end rescue StandardError => e # Search analytics not available - silently continue puts "\nSearch analytics: Not available (#{e.message})" end end
Source
# File lib/ragdoll/cli.rb, line 139 def status(document_id) client = StandaloneClient.new begin status = client.document_status(document_id) puts "Document Status for ID: #{document_id}" puts " Status: #{status[:status]}" puts " Embeddings Count: #{status[:embeddings_count]}" puts " Embeddings Ready: #{status[:embeddings_ready] ? 'Yes' : 'No'}" puts " Message: #{status[:message]}" rescue StandardError => e puts "Error getting document status: #{e.message}" end end
Source
# File lib/ragdoll/cli.rb, line 516 def trending analytics = Analytics.new analytics.options = options analytics.trending end
Source
# File lib/ragdoll/cli.rb, line 435 def update(document_id) Update.new.call(document_id, options) end
Source
# File lib/ragdoll/cli.rb, line 29 def version puts Ragdoll.version.join("\n") end