← Back to Pull requests

fix(rag): preserve text document content and source #9293

Open
unknown opened this pull request with 313 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 09, 2026 12:17 UTC
Author

Related issue

Fixes #9292

Summary

When a text document dictionary supplies both source and content, the adapter previously used the source label as the text to index. Use the provided body for chunking and keep the source as metadata. Scope the resulting IDs to the source so identical text from different sources produces distinct records.

Verification

The regression exercises RagTool.add() with the vector database client mocked. It checks the indexed body, source metadata, caller metadata, and distinct IDs for equal text from two sources. On the unmodified adapter, the new regression was the only failure (59 passed, 1 failed). With this change, all 60 tests across the four RagTool test files passed. The tests used Python 3.12.16, CrewAI and CrewAI Tools 1.15.39, and pytest 9.0.3. The adapter baseline came from upstream commit 83d7407aa50b94d5b9f110c10ca295d3e0f360ee.

Ruff 0.15.1 formatting and git diff --check passed. Lint had one identical import-order diagnostic on both versions with the isolated workspace config. The full monorepo test suite and GitHub CI were not run.

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally
  • Additional context

    Prepared and locally verified with Codex assistance. I do not have upstream label permissions. Maintainers, please apply the required llm-generated label during triage.

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Low Risk

    Targeted RAG ingest fix for text dict inputs plus a regression test; no auth or broad API changes.

    > Overview

    Fixes a regression where text document dicts that include both source and content were passed to the loader as the source label, so the wrong text was chunked and indexed.

    > The adapter now loads from content when data_type is text and a dict carries source, while still recording source (and caller metadata) on chunks. Doc/chunk IDs incorporate source_ref with the loader doc_id, so the same body from two sources indexes as separate records instead of colliding.

    > A regression test asserts indexed bodies, metadata sources, custom metadata, and distinct doc_ids for duplicate content under different sources.

    > <sup>Reviewed by Cursor Bugbot for commit 9a6919177957d3006d828874680d0d9994ca36c2. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 313 lines (+234 / -79) across 3 files Reviewer: chrikrah Review duration: 6496m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 313 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Diff Size diff_size
    0.344
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9293"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.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: 40.3% (MEDIUM) · Higher = larger blast radius
    40.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: 46.7% · Lower = rushed or shallow review
    46.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: 21.5% · Safe to merge
    21.5%