Skip to content

Conversation

@NehharShah
Copy link

@NehharShah NehharShah commented Nov 8, 2025

  • Created a calculateRecencyWeight function inside buildCandidatePairs that uses Date.now() and the intent's createdAt timestamp
  • The weight decays exponentially: 100 for today, ~50 after 30 days, ~25 after 90 days
  • Formula: 100 * Math.exp(-ageInDays / 30)

Summary by CodeRabbit

  • New Features

    • Semantic ranking now incorporates recency-based weighting in candidate evaluation.
  • Refactor

    • Optimized asynchronous processing in semantic relevancy evaluation pipeline.
    • Enhanced ranking logic to balance relevance scores with recency factors.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

The SemanticRelevancyBroker introduces recency-based scoring to candidate pair evaluation. The buildCandidatePairs method becomes asynchronous and now enriches candidate pair objects with a recencyWeight field. Downstream methods (rankIntentPairs, updateStakes) and user-facing output are updated to propagate and display this recency dimension.

Changes

Cohort / File(s) Summary
Recency-weighted semantic relevancy
protocol/src/agents/context_brokers/semantic_relevancy/index.ts
buildCandidatePairs converted to async; introduces calculateRecencyWeight helper based on intent creation time; candidate pair objects enriched with recencyWeight: number field; rankIntentPairs and updateStakes signatures updated to accept and propagate recencyWeight; ranking logic adjusted; user-facing output strings updated to reflect recency and revised ranking guidance

Sequence Diagram

sequenceDiagram
    participant Main as Stage 2 Evaluation
    participant BuildCP as buildCandidatePairs()
    participant CalcRW as calculateRecencyWeight()
    participant Rank as rankIntentPairs()
    participant Output as User Output

    Main->>+BuildCP: (awaited)
    
    loop For each candidate pair
        BuildCP->>+CalcRW: Get recencyWeight for intent(s)
        CalcRW-->>-BuildCP: Promise<number>
        BuildCP->>BuildCP: Attach recencyWeight to pair
    end
    
    BuildCP-->>-Main: Promise<CandidatePair[]> with recencyWeight
    
    Main->>+Rank: candidatePairs (with recencyWeight)
    Rank->>Rank: Account for recencyWeight in ranking
    Rank-->>-Main: Ranked pairs
    
    Main->>+Output: Top 3 pairs + Recency Weight
    Output->>Output: Display recency-aware guidance
    Output-->>-Main: User-facing results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Pay close attention to the calculateRecencyWeight async logic and its correctness in computing intent creation time-based scoring
  • Verify that recencyWeight propagation is consistent across all candidate pair construction paths (new-target pairs and existing-stake-derived pairs)
  • Check that the max recencyWeight derivation logic when constructing pairs from existing stakes is intentional
  • Ensure all downstream consumers of candidatePairs (logging, display, ranking calculations) correctly handle the new recencyWeight field

Poem

🐰 Hark! The broker now sees through time's gentle veil,
Each candidate pair blessed with recency's pale glow—
No longer just relevant, but fresh and quite hale,
Async flows upstream, where wise rabbits now go! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat/adding recency score' directly describes the main feature addition—introducing recency-based scoring to the semantic relevancy broker, which aligns with the changeset's core objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@serefyarar serefyarar self-requested a review November 8, 2025 19:16
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Caution

Docstrings generation - FAILED

No docstrings were generated.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
protocol/src/agents/context_brokers/semantic_relevancy/index.ts (1)

197-228: Cache intent recency lookups to avoid N+1 queries.

Each call to calculateRecencyWeight performs its own getIntent fetch, so building candidates can issue two fresh DB reads per existing stake and one per mutual result. In dense matches this becomes an avoidable N+1 pattern (the same intent ID can be looked up repeatedly across stakes), adding latency before we even reach the LLM. Please memoize/batch the recency lookups (e.g., keep a Map keyed by intentId or prefetch the unique IDs up front) so every intent row is retrieved at most once during this pass.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 050250f and 370bb25.

📒 Files selected for processing (1)
  • protocol/src/agents/context_brokers/semantic_relevancy/index.ts (6 hunks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant