Your local agent remembers too much: how to run AutoRAG on work files without data leaks or access chaos
I’m Denis Shokhirev, an Agentic AI Systems Architect in Freiburg im Breisgau, Germany, and at DennisCraft AI Studio I ship production AI systems for DACH B2B clients on Claude, Supabase, n8n, Doppler, and self-hosted Postgres. The ugliest local AutoRAG failure I see is not a dramatic breach; it’s an agent calmly answering from the wrong folder, pulling an expired policy, an HR draft, and a finance note because the index remembers more than the current user should ever see. Teams often say, “It’
I’m Denis Shokhirev, an Agentic AI Systems Architect in Freiburg im Breisgau, Germany, and at DennisCraft AI Studio I ship production AI systems for DACH B2B clients on Claude, Supabase, n8n, Doppler, and self-hosted Postgres. The ugliest local AutoRAG failure I see is not a dramatic breach; it’s an agent calmly answering from the wrong folder, pulling an expired policy, an HR draft, and a finance note because the index remembers more than the current user should ever see.
Teams often say, “It’s local, so it’s safe.” That assumption causes most of the access chaos. Running RAG on work files is not one problem but three: file ingestion, indexing and chunking, and authorization at retrieval time. When those are blended into one pipeline, the agent starts treating relevance as permission. In production, that is how you get silent data exposure, stale answers, and no clean way to revoke knowledge after a document should be gone.
Where local AutoRAG actually breaks
The weak point is usually not generation. It’s the habit of building a global index “for convenience.” I keep seeing the same pattern in internal document assistants: a developer parses a shared drive, stores embeddings in one table, adds a user interface on top, and assumes application-level filters will handle access later. They won’t. Vector search returns semantic similarity, not entitlement.
Three failure modes that show up fast
| Failure mode | What happens | Production impact |
|---|---|---|
| Global index | All teams search the same vector space | Agents mix unrelated or restricted files into answers |
| No TTL or revocation | Deleted or expired files remain embedded | Users get answers from invalid policy or contract versions |
| ACL after retrieval | Filtering happens after candidate selection | Leaks into logs, traces, rerankers, or intermediate tools |
OWASP’s GenAI project lists Sensitive Information Disclosure and insecure vector or embedding handling as real risk categories, not edge cases. See the OWASP Top 10 for LLM Applications and GenAI guidance: https://genai.owasp.org/ and https://owasp.org/www-project-top-10-for-large-language-model-applications/. That matters here because “local” lowers one external transfer risk, but it does nothing for internal overexposure. If an agent can see data it should not use for a given person or role, the problem already exists before anything leaves your network.
Design the index as an access projection
The simplest stable rule I use is this: a document enters retrieval only together with its minimum access metadata. Not later. Not as a cleanup job. If a file arrives without tenant, owner or access group, classification, source path, checksum, and expiration policy, ingestion should fail. An index is not a memory dump. It is a searchable projection of what specific actors may retrieve under specific conditions.
Minimum metadata that should exist before embedding
| Field | Why it matters | Example |
|---|---|---|
| tenant_id | Separates customers or business units | dach_fintech_02 |
| access_group | Maps retrieval to role or team | risk_ops |
| classification | Marks sensitivity | internal / confidential |
| source_path | Supports traceability and review | /policies/kyt/2026-11.pdf |
| checksum | Enables deduplication and revocation | sha256... |
| expires_at | Supports TTL and stale-content control | 2026-12-31 |
The important implementation detail: the retrieval query must enforce those constraints inside the database query before candidates are returned. Not in the prompt. Not in frontend logic. Not in a “please ignore unauthorized files” instruction to the model.
from anthropic import Anthropic
import psycopg
def search_chunks(tenant_id, access_group, embedding):
sql = """
select id, content, source_path
from rag_chunks
where tenant_id = %s
and access_group = %s
and expires_at > now()
order by embedding <=> %s::vector
limit 8
"""
with psycopg.connect() as conn:
with conn.cursor() as cur:
cur.execute(sql, (tenant_id, access_group, embedding))
return cur.fetchall()
client = Anthropic()
rows = search_chunks("dach_fintech_02", "risk_ops", "[0.1,0.2]")
print(rows)Ingestion is where most “memory leaks” begin
Many teams focus on the chat experience and ignore the ingestion path. Then a file watcher on a shared folder starts indexing everything that lands there: approved policy PDFs, but also exports, payroll sheets, debug CSVs, or a temporary archive from ERP. If the folder is broad, the agent’s memory will be broad. That is not intelligence. It is unbounded intake.
Practical ingestion controls
My default posture is deny by default. Only allowlisted directories get indexed. Filenames and paths that include payroll, backup, secret, key, or export are blocked before chunking. Every file gets a checksum. Revocation has its own queue instead of waiting for the next full reindex. And I avoid logging full retrieved context for regulated work files.
#!/usr/bin/env bash
set -euo pipefail
FILE="$1"
echo "$FILE" | grep -E '/approved/(policies|contracts|runbooks)/' > /dev/null
echo "$FILE" | grep -Ei '(payroll|backup|secret|key|export)' && exit 1 || true
gitleaks detect --no-git --source "$FILE" > /dev/null
sha256sum "$FILE" | awk '{print $1}'
python ingest_file.py "$FILE"I usually add gitleaks and semgrep in the ingestion and CI path. Gitleaks helps keep obvious secrets out of the agent’s memory. Semgrep helps catch dangerous patterns in retrieval code and file handling before they become production incidents. If there is Python around custom ingestion utilities, Bandit is also worth running for a quick static pass.
“Local” is not the same as controlled
Anthropic’s documentation on tool use and context management consistently pushes developers toward minimizing the data the model receives and structuring tool access carefully: https://docs.anthropic.com/. OpenAI’s RAG examples in the Cookbook also reflect a basic truth: retrieval is a systems problem, not just a prompt problem. See the OpenAI Cookbook at https://cookbook.openai.com/ for reference implementations and patterns.
In practice I separate three layers: source storage, searchable index, and runtime context. Source storage holds the original files. The index stores chunks and metadata with strict access attributes. Runtime builds prompts from the already filtered result set. If you log all three into one tracing bucket, you erase the boundary you just tried to create.
| Layer | Purpose | Common mistake |
|---|---|---|
| Storage | Original file retention | Granting broad service-account access |
| Index | Searchable chunk metadata and vectors | Ignoring ACL and expiration in queries |
| Runtime | Prompt assembly, tools, traces | Logging full retrieved content by default |
steps:
- name: classify_file
run: python classify.py ${FILE}
- name: secret_scan
run: gitleaks detect --no-git --source ${FILE}
- name: metadata_check
run: python validate_metadata.py ${FILE}
- name: index_file
run: python ingest_file.py ${FILE}The other recurring mistake is the all-powerful service account. If the agent indexes or searches as a technical identity that sees everything, then answers a real employee, your retrieval layer no longer reflects actual authorization. The agent should search for what this actor may access now, not what the platform can technically read somewhere in the background.
What production-ready AutoRAG looks like on work files
For me, production-ready means predictable behavior. If a file is deleted, it stops appearing in results. If a user loses access, retrieval respects that immediately rather than after a nightly rebuild. If a generated answer cites a document, I can show the source path, checksum, and indexing timestamp. And if something goes wrong, I can revoke one document cleanly instead of rebuilding the entire memory layer.
That is why I like self-hosted Postgres as the control plane, Supabase as a convenient application layer, n8n for ingest and revoke automation, and Claude for reasoning on already filtered context. The useful mindset shift is this: stop asking how smart the model is before you ask which document, under which rights, at which time, the model is even allowed to see.
FAQ
Can I use one shared vector index for the whole company?
You can, but I would not recommend it for work files unless your authorization model is extremely explicit and enforced in-query. Separate tenants and access groups reduce the blast radius when retrieval logic is wrong.
Is keeping everything on-prem enough?
No. On-prem or local storage reduces one category of transfer risk, but it does not solve stale context, over-indexing, or role-based retrieval mistakes. Most real issues I see are internal access mistakes, not cloud transport problems.
Should I log retrieved chunks for debugging?
Log identifiers and decision traces first: chunk IDs, source paths, checksums, and policy decisions. Full text logging should be the exception for sensitive work files, not the default.
How do I revoke a document quickly?
Use checksum and source path as first-class controls. A revoke workflow should delete or disable all related chunks and invalidate any cache immediately.
Is n8n suitable for this workflow?
Yes, as an orchestration layer. I would still keep access rules, retrieval filters, and critical policy checks in code and in the database rather than inside low-code nodes.
Which part of your LLM pipeline catches the most production issues right now: ingestion, retrieval, runtime sandboxing, or human review after the answer is generated? I’d genuinely like to compare that with what I see in regulated DACH environments.
I run a free 30-min stack audit for DACH founders building AI in regulated markets. DM me on LinkedIn or write to @ger_dennis_ai.
I build agents like this for businesses in Germany and the EU.
Tell me in two sentences what eats your team’s time – reply within 24 hours.
Turn your process into an AI system
Production quality. DACH B2B focus.