Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Store Bot Comment Embeddings from Closed PRs #2100

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

RulaKhaled
Copy link

@RulaKhaled RulaKhaled commented Mar 6, 2025

  • Add tests

This PR adds functionality to collect and store bot comment patterns when PRs are closed. We analyze user reactions to identify good/bad patterns and store them with embeddings for future similarity matching.

Implementation Details

  1. PR Closed Handler
class PrClosedStep(CodegenStep):
    """Processes closed PRs to collect comment patterns"""
  • Triggers when a PR is closed
  • Fetches all review comments from the PR
  • Filters for bot comments only (codecov-ai-reviewer[bot])
  1. Comment Analysis
  • Counts 👍 and 👎 reactions on each comment
  • Determines if it's a good pattern (more 👍) or bad pattern (more 👎)
  1. Embedding Generation
# Generate embeddings for similarity matching
model = GoogleProviderEmbeddings.model(
    "text-embedding-005", 
    task_type="CODE_RETRIEVAL_QUERY"
)
embedding = model.encode(comment.body)[0]  # 768-dimensional vector
  1. Database Storage
class DbReviewCommentEmbedding(Base):
    """Store PR review comments with their embeddings for pattern matching per organization"""
    __tablename__ = "review_comments_embedding"
  • Stores comment text, metadata, and embeddings
  • Uses pgvector for efficient similarity search
  • Handles duplicates with on_conflict_do_nothing

Example Flow

  1. PR Beta readiness #123 is closed
  2. System finds bot comment
  3. Comment has 3 👍 and 1 👎 → marked as good pattern
  4. Generates embedding for similarity matching
  5. Stores in DB with metadata (PR link, file location, etc.)

@RulaKhaled RulaKhaled requested a review from a team as a code owner March 6, 2025 14:09
@RulaKhaled RulaKhaled marked this pull request as draft March 6, 2025 14:09
@RulaKhaled RulaKhaled force-pushed the rola/ai-comments-improvements branch from c6f9352 to bf6e99a Compare March 6, 2025 14:41
@RulaKhaled RulaKhaled force-pushed the rola/ai-comments-improvements branch from 3c862a0 to 10caf77 Compare March 6, 2025 14:49
@RulaKhaled RulaKhaled changed the title feat: Store Bot Comment Patterns from Closed PRs feat: Store Bot Comment Embeddings from Closed PRs Mar 6, 2025
@RulaKhaled RulaKhaled marked this pull request as ready for review March 18, 2025 10:44
@@ -122,11 +122,31 @@ def get_codecov_pr_review_app_credentials(
return app_id, private_key


@inject
def get_codecov_pr_closed_app_credentials(

Choose a reason for hiding this comment

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

I think we can just use PR review credentials. That way we don't have to add additional env values

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.

2 participants