Class: RailsAiBridge::RubydexAdapter::IncrementalIndexer
- Defined in:
- lib/rails_ai_bridge/rubydex_adapter/incremental_indexer.rb
Overview
Incremental indexer service for rubydex graphs.
On +:build+ performs a full index and records file mtimes. On +:reindex+ detects changed files and either patches the graph incrementally (when changes are below the threshold) or falls back to a full rebuild.
Optionally persists file mtimes to disk so change detection works across process restarts.
Constant Summary collapse
- MTIMES_FILENAME =
Filename used to persist the integer-second mtime snapshot on disk.
'mtimes.json'
Class Method Summary collapse
-
.call(operation) ⇒ Service::Result
Entry point that creates an instance and dispatches the operation.
Instance Method Summary collapse
-
#call(operation, root:, graph: nil, file_mtimes: {}, **options) ⇒ Service::Result
Dispatches the indexing operation.
Methods inherited from Service
Constructor Details
This class inherits a constructor from RailsAiBridge::Service
Class Method Details
.call(operation) ⇒ Service::Result
Entry point that creates an instance and dispatches the operation.
28 29 30 |
# File 'lib/rails_ai_bridge/rubydex_adapter/incremental_indexer.rb', line 28 def self.call(operation, **) new.call(operation, **) end |
Instance Method Details
#call(operation, root:, graph: nil, file_mtimes: {}, **options) ⇒ Service::Result
Dispatches the indexing operation.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rails_ai_bridge/rubydex_adapter/incremental_indexer.rb', line 43 def call(operation, root:, graph: nil, file_mtimes: {}, **) threshold = .fetch(:threshold, 0.3) persist = .fetch(:persist, false) index_path = .fetch(:index_path, nil) case operation.to_sym when :build build(root, threshold, persist, index_path) when :reindex reindex(root, graph, file_mtimes, threshold, persist, index_path) else Service::Result.new(false, errors: ["Unsupported operation: #{operation}"]) end rescue StandardError => error log_error(operation, error) logger = defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : nil logger&.debug error.backtrace Service::Result.new(false, errors: ["#{self.class} #{operation} failed: #{error.}"]) end |