ActiveContext: Add preprocessing for references
What does this MR do and why?
Add a way to preprocess references in a generic way. Examples of preprocessing are:
- Preloading database records to prevent N+1
- Bulk generating embeddings
- Doing anything that should be done in bulk
We can now add a preprocessor by adding the following to the Reference subclass:
# frozen_string_literal: true
module Ai
module Context
module References
class MergeRequest < ::ActiveContext::Reference
add_preprocessor :preload do |refs|
# ... do something
refs
end
add_preprocessor :bulk_generate_embeddings do |refs|
# ... do something
refs
end
...
Ai::Context::References::MergeRequest.new(MergeRequest.first.id).class.preprocessors
=> [{:name=>:preload, :block=>#<Proc:0x000000030e659bc0 /Users/madelein/dev/gitlab-development-kit/gitlab-development-kit/gitlab/ee/lib/ai/context/references/merge_request.rb:7>},
{:name=>:bulk_generate_embeddings, :block=>#<Proc:0x000000030e659b98 /Users/madelein/dev/gitlab-development-kit/gitlab-development-kit/gitlab/ee/lib/ai/context/references/merge_request.rb:12>}]
By default we don't do any preprocessing.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #519536 (closed)