← Back to Pull requests

fix(retrieval): embed queries and documents with the right cohere input types #17

Open
unknown opened this pull request with 264 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 22, 2026 03:30 UTC
Author

Summary

Questions were embedded as if they were documents. This PR gives each side its own Cohere input_type, adds retries, and adds a local embedding provider so the engine runs without API keys.

Closes #3

Stacked on #14. Merge in order: #13 → #14 → this one.

Changes

  • The bug. embedding_provider.embed() sent COHERE_EMBEDDING_INPUT_TYPE (default search_document) for both passages and questions. Cohere v3 is trained asymmetrically, so retrieval quality dropped with no error anywhere. The setting is removed.

  • EmbeddingProvider protocol (app/providers/embeddings.py): embed_documents() for ingestion, embed_query() for questions, plus name and dim.

  • CohereEmbeddings: search_document / search_query, batches of 96 (API limit), truncate=END instead of NONE (a long chunk no longer fails the whole document).

  • post_with_retries (app/providers/http.py): honors Retry-After, exponential backoff on 429/5xx and network errors, at most 4 attempts, fails fast on other 4xx. The provider response is logged and never returned.

  • LocalEmbeddings: fastembed (ONNX on the CPU) with paraphrase-multilingual-MiniLM-L12-v2, 384 dims, selected with EMBEDDING_PROVIDER=local. Optional extra: uv sync --extra local.

  • CI caches the ONNX model between runs.
  • How to test

    uv sync --all-extras
    uv run pytest tests/unit/test_embeddings.py -v
    

    test_local_model_is_multilingual downloads the model once (about 220 MB) and checks that a Spanish question is closer to the English passage that answers it than to an unrelated one.

    Results

    Quality numbers for both providers come with the benchmark (#10); this PR fixes the input type and makes that benchmark possible without keys.

    Checklist

  • Branch follows <type>/<issue>-<short-description> and the PR title is a Conventional Commit

  • New or changed behavior is covered by tests (9 new, 36 total)

  • ruff check, ruff format --check, mypy and pytest pass locally

  • No secrets committed
  • 🤖 Generated with Claude Code

    Diff: 264 lines (+198 / -66) across 3 files Reviewer: copilot-pull-request-reviewer[bot] Review duration: 0m
    All Vouch review confidence checks passed
    Residual risk 0.34 = Change Risk (0.39) × (1 − Review Confidence (0.13)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 264 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 13% · Reviewer familiarity: 35%
    12%
    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.344
    Diff Size diff_size
    0.334
    Real PR Conversation Timeline
    1 comments
    "Review active on #17"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 12.7% 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: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    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: 12.7% · Lower = rushed or shallow review
    12.7%
    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: 34.3% · Safe to merge
    34.3%