← Back to Pull requests

[ENH] Add pretrained embedding basline #45

Closed
unknown closed this pull request without merging on Nov 28, 2026 15:59 UTC
View on GitHub
unknown unknown commented on Nov 28, 2026 15:58 UTC
Author

Related issue


Closes #23

Summary


Add src/crosstrace/baselines/embedding.py.
  • SentenceTransformerEncoder loads a pretrained model on first use.

  • Default: BAAI/bge-small-en-v1.5. Token limit: 256.
  • EmbeddingCache saves vectors on disk. One file for each model name and

  • token limit. The file is replaced in one step after each encoding run.
  • EmbeddingIndex ranks candidates by cosine similarity. The time rule is

  • applied at query time with eligible(). The query's own repository is not
    used by default.
  • Every eligible candidate gets a score. Ties are sorted by ID.

  • rank_queries() returns the run format that metrics.evaluate() uses.

  • The system is added to the evaluation runner as embedding.
  • How I tested it


  • uv run pytest

  • uv run ruff check .

  • Tests use a fake encoder. No model is downloaded in the tests.

  • A test checks that a second run makes no new encoder calls.

  • I ran the real model once by hand and got the shape (2, 384).
  • Diff: 122 lines (+91 / -31) across 1 files Reviewer: aashoday Review duration: 0m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.32) × (1 − Review Confidence (0.32)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.32 · 122 lines diff across 1 files
    0.32
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 21% · Reviewer familiarity: 35%
    32%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.289
    Diff Size diff_size
    0.288
    Real PR Conversation Timeline
    1 comments
    "Review active on #45"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 32.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.8% (LOW) · Higher = larger blast radius
    31.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 32.1% · Lower = rushed or shallow review
    32.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.6% · Safe to merge
    21.6%