When Local RAG Is Worth Calling, and When Reading the Source Is Faster
Am I missing a fact, or an entry point? That one question decides whether to retrieve at all.
On this page · 10 sections
RAG has two "should I fetch?" decisions that are often conflated. The data side decides whether to re-fetch a source body; the development side decides whether to invoke retrieval for the question at hand. The first is the raw data control plane; the second is query routing. Both follow one principle: identify the gap first, then perform the action that has a cost, needs permission, or may introduce staleness risk.
The Short Version
- The data side and the query side follow one principle: identify the gap first, then perform the action that has a cost, needs permission, or may introduce staleness risk.
- Confluence pulls lightweight metadata first; a full fetch is skipped only when five conditions all hold (including unchanged and
score < 0.1), while a new page, a change, or an abnormal timestamp is still fetched. - Freshness applies only to Confluence; code uses currentness, which depends on the repo, branch, pinned commit, and sync status.
- With a precise entry point already in hand, read the current source directly; Local RAG finds the entry point, and the current source and the provider's original text complete the proof.
Knowledge Map for This Article
The topics to master are:
- metadata-first ingestion;
- the difference between freshness and currentness;
- change override;
- source event identity;
- permission and cost gates;
- the direct search fallback on the query side.
The Control Plane Does Not Process Bodies; It Decides Whether a Body Is Worth Processing
If every scheduled run re-downloaded all Confluence pages, attachments, and code, then re-parsed, re-chunked, and re-embedded everything, the system would waste a great deal of resources on data that has not changed. If it looked only at the update time and skipped outright, a wrong timestamp or an update to an old page would be missed permanently.
The current Confluence policy pulls lightweight metadata first, then computes:
age_days = max(0, as_of - effective_updated_at)
freshness_score = exp(-ln(10) * age_days / 1096)
At 1096 days the score is 0.1. A full fetch is skipped only when all of the following hold:
- It is not force mode;
- A previous snapshot already exists;
- The revision, effective updated-at, and metadata fingerprint are all unchanged;
- The timestamp can be scored normally;
score < 0.1; note that this is strictly less than.
A new page, a revision change, or a metadata fingerprint change each triggers change_override. When a timestamp is missing, invalid, or beyond the future tolerance, the fetch is not skipped to save traffic; these cases preserve the content with a fail-open fetch and record the abnormal state with a fail-closed claim.
Inside the metadata-first freshness control plane, the persister is called only after an individual full fetch has succeeded completely. A skip does not overwrite existing raw data, and a half-failed single page is not published by this control plane as a complete snapshot.
The project still retains the legacy full refresh, however: it deletes the old Jira/Confluence raw data first and then re-fetches. If the network fails midway, the entire mutable raw mirror can still be left partially complete. The more robust target is to write a staging snapshot first and then switch the pointer as a whole. Describing per-page atomic overwrite as "the whole full refresh is atomic" would overstate the current guarantee.
Freshness Cannot Be Applied to Code
Confluence's time decay expresses "an older design may deserve more caution." The validity of code, by contrast, is not determined by age: a core function untouched for years may still be the current implementation, and a recent feature branch may never have been deployed at all.
So source_temporal_policy returns freshness for Confluence and currentness for code. Code currentness depends on the repo, branch, pinned commit, and sync status; the query payload sets currentness_valid=true only when the source sync is fresh. Applying exponential decay to code by updated_at would wrongly suppress stable implementations and promote new code that has not been released.
Source Event: The Goal Is That a Change Enters Downstream Only After It Is Accepted
The output of the raw control plane is not "a directory changed"; it is a structured SourceChangeEvent:
source_type / entity_type / entity_id
operation = upsert | delete
revision / content_hash / payload_hash
occurred_at / detected_at / authoritative
run_id / job_id
source_entity_state uses the revision, content hash, payload hash, and deleted flag to suppress unchanged entities across runs. The event ID retains run/source-revision semantics, so a legitimate A → B → A change is not wrongly swallowed just because the content returned to an old value.
For an incremental source, "not seen" is not a delete. Incremental queries against Jira/Confluence are not an authoritative full inventory; only a successfully completed reconciliation sweep can emit an authoritative tombstone, that is, an authoritative deletion marker. Otherwise a single pagination failure could be misread as hundreds or thousands of deletions.
The current scheduled Jira path also has an explicit gap: the schedule first runs a full collect without --fast-metadata, and the subsequent enrich picks only placeholder/incomplete issues. After a full collect, enrich may have no candidates, so the Jira issue source event handoff may be empty; attachment events cannot substitute for issue events either.
A successful raw mirror update and the V3 journal having received the event must be accepted separately.
Scheduling Pulls Only Sources by Default
The current Docker schedule splits sources into independent jobs: Atlassian and code are both scheduled daily but at different frequencies, and the DDB weekly job is off by default. Default jobs update sources only; they do not automatically run embedding or store writes.
Beyond that, three control paths coexist in the middle of a migration:
- the legacy monolithic refresh;
- the V3 SQLite journal;
- the System RAG immutable Manifest Generation.
They cannot be described as one unified runtime.
Enabling DDB requires three values to hold at once: the weekly flag, the read-only confirmation, and the current ISO week. The week-scoped confirmation expires automatically, because "reading was allowed last week" does not imply "reading is still allowed this week." Even though the command pins --read-only, it may still read production data and incur AWS cost, so a code switch cannot replace human safety confirmation.
The Query Side: Am I Missing a Fact, or an Entry Point?
Once the data side is done, a development task should not call Local RAG unconditionally either.
If the user has given me a file, a stack trace, a class, a GraphQL field, or a specific diff, I already have a precise entry point. At that point rg, type definitions, tests, and current callers are more direct than vector retrieval, because they read the current working tree and require no further judgment about which commit the index reflects.
Local RAG is better suited to four kinds of gap:
- Business language and code naming do not match;
- The question spans Jira, Confluence, and multiple repositories;
- I know only the domain concept, not the module or symbol;
- I need to find the original page for a historical decision, then go back to the current code to verify it.
So "when is it worth calling" is not decided by whether the task looks complex; it is decided by whether retrieval can significantly narrow an undirected search. Local RAG finds the entry point; the current source and the provider's original text complete the proof.
Failure Modes and Trade-offs
Each row below is one failure: the middle column is the current handling, and the last column is what that handling costs.
| Failure mode | Current handling | Trade-off |
|---|---|---|
| A Confluence timestamp is missing or invalid | Fetch full, and record the state | One extra fetch, in exchange for never permanently missing a page |
| An old page's metadata changes | Change override; the low freshness is ignored | Parsing cost goes up, but a change is never masked by age |
| A scheduled run finds no source change | No derived work is generated | The journal/state adds implementation complexity |
| An incremental result is missing an object | No delete is emitted | Deletions converge more slowly, but the whole projection is not deleted by mistake |
| A legacy full refresh is interrupted mid-fetch | Mutable raw may be left with only part of the new snapshot | Staging + pointer is required to get a batch-level atomic switch |
| Jira raw is updated but the issue event is not handed off | V3 downstream may not see that change | Check raw, the journal, and the consumer cursor separately |
| Local RAG/Qdrant is unavailable | Fall back to a bounded direct search | Cross-source discovery degrades, but development is not blocked by a hidden runtime |
| The exact symbol is known and retrieval still runs first | Treated as an unnecessary path | A uniform flow is simpler, but latency and staleness risk are higher, so it is not adopted |
Verifiable Project Evidence
src/mt_rag/freshness/policy.py: the 1096-day exponential score and the source temporal policy;src/mt_rag/freshness/confluence.py: the metadata fingerprint, strict threshold, change override, and decision reason;src/mt_rag/freshness/control_plane.py: the metadata-first sweep, persistence after a complete fetch, and source events;src/mt_rag/refresh/contracts.py: the source/vector/graph event contract;src/mt_rag/refresh/journal.py: unchanged suppression, entity state, and the consumer cursor;src/mt_rag/service/service_refresh.py: the source-aware schedule and the default source-only behavior;docs/03-reference/incremental-refresh-v3-event-design.md: source jobs, confirmation gates, and deletion semantics.
References
- Atlassian Confluence Content API documentation;
- Bitbucket Cloud Webhooks documentation;
- AWS DynamoDB security best practices;
- Debezium Architecture documentation;
- Git
rev-parsedocumentation.
A reliable control plane does not aim to "do more every time." It lets fetching, retrieval, and degradation all be triggered by an observable gap, and it records the reason something was not executed as evidence too.
Related notes
Local RAG Design: Store the Evidence First, Then Retrieve
How mt_rag separates replayable evidence, rebuildable query views, verified graph paths, and bounded generation—and why current source still wins.
Why a Code Hit Is Not Yet an Answer
Engineering retrieval has to bind results to a repository, a commit, and a symbol; a hit that is missing, stale, or from the wrong repository is only a locating lead.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]