Class: Aidp::PromptOptimization::RelevanceScorer
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::RelevanceScorer
- Defined in:
- lib/aidp/prompt_optimization/relevance_scorer.rb
Overview
Scores fragments based on relevance to current task context
Calculates relevance scores (0.0-1.0) for fragments based on:
-
Task type (feature, bugfix, refactor, test)
-
Affected files and code locations
-
Work loop step (planning vs implementation)
-
Keywords and semantic similarity
Constant Summary collapse
- DEFAULT_WEIGHTS =
Default scoring weights
{ task_type_match: 0.3, tag_match: 0.25, file_location_match: 0.25, step_match: 0.2 }.freeze
Instance Method Summary collapse
-
#initialize(weights: DEFAULT_WEIGHTS) ⇒ RelevanceScorer
constructor
A new instance of RelevanceScorer.
-
#score_fragment(fragment, context) ⇒ Float
Score a single fragment.
-
#score_fragments(fragments, context) ⇒ Array<Hash>
Score multiple fragments.
Constructor Details
#initialize(weights: DEFAULT_WEIGHTS) ⇒ RelevanceScorer
Returns a new instance of RelevanceScorer.
26 27 28 |
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 26 def initialize(weights: DEFAULT_WEIGHTS) @weights = weights end |
Instance Method Details
#score_fragment(fragment, context) ⇒ Float
Score a single fragment
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 35 def score_fragment(fragment, context) scores = {} scores[:task_type] = score_task_type_match(fragment, context) * @weights[:task_type_match] scores[:tags] = score_tag_match(fragment, context) * @weights[:tag_match] scores[:location] = score_file_location_match(fragment, context) * @weights[:file_location_match] scores[:step] = score_step_match(fragment, context) * @weights[:step_match] total_score = scores.values.sum normalize_score(total_score) end |
#score_fragments(fragments, context) ⇒ Array<Hash>
Score multiple fragments
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aidp/prompt_optimization/relevance_scorer.rb', line 52 def score_fragments(fragments, context) fragments.map do |fragment| score = score_fragment(fragment, context) { fragment: fragment, score: score, breakdown: score_breakdown(fragment, context) } end.sort_by { |result| -result[:score] } end |