Skip to content
VecShield
← RAG Security Notes

Retrieval Security10 min read

Why the Retrieval Layer Should Be a Security Boundary

Why the Retrieval Layer Should Be a Security Boundary

Most AI security controls are placed around the model.

We inspect the user prompt before it reaches the LLM.

We run guard models.

We filter the response afterward.

That makes sense for many threats.

But RAG systems introduce another place where security decisions can happen:

before retrieved information ever reaches the model.

That retrieval layer is becoming one of the most important security boundaries in an AI application.

And today, we probably do not treat it like one.

Consider a normal RAG application

Imagine a company builds an internal assistant over its documents.

An employee asks:

“What was the discount we negotiated with Acme last year?”

The application might work like this:

Employee
   ↓
Question
   ↓
Embedding / Search
   ↓
Vector Store
   ↓
5 relevant chunks
   ↓
LLM
   ↓
Answer

The interesting security decision does not necessarily happen at the LLM.

It happens one step earlier:

Which five chunks is this employee allowed to retrieve?

Suppose the vector store contains:

Chunk A
source: sales/acme_contract.pdf
tenant: company_a
classification: internal
allowed_group: sales

Chunk B
source: hr/salaries.xlsx
tenant: company_a
classification: restricted
allowed_group: hr

Chunk C
source: customer_b/acme_contract.pdf
tenant: company_b
classification: confidential
allowed_group: customer_b

All three chunks might be semantically similar to the employee's query.

The embedding model does not know that Chunk B belongs to HR.

Cosine similarity does not know that Chunk C belongs to another customer.

And the LLM should not be expected to figure this out after receiving them.

The safer architecture is:

Question
   ↓
Who is asking?
   ↓
What are they allowed to access?
   ↓
Vector search + security constraints
   ↓
Only authorized chunks
   ↓
LLM

Not:

Retrieve everything relevant
   ↓
Give it to the LLM
   ↓
Hope the model does not reveal something sensitive

OWASP's current RAG security guidance makes this point explicitly: access controls should travel with chunks and be enforced at retrieval time, before the content reaches the model. It also recommends tenant and classification isolation as foundational RAG controls.

That is the first reason retrieval deserves to be treated as a security boundary.

Once the model sees the data, we are already late

Suppose a user should not have access to an employee's medical record.

There are two possible approaches.

The first is:

Retrieve medical record
        ↓
Put it in LLM context
        ↓
Tell model:
"Do not reveal medical information"

The second is:

User requests information
        ↓
Authorization check
        ↓
Medical record is not retrieved
        ↓
LLM never sees it

The second is much easier to reason about.

This is not unique to AI.

We would not normally build a database application by giving every row to the frontend and asking the frontend to politely hide the rows the user should not see.

Authorization belongs as close as possible to the data access itself.

RAG should be treated similarly.

The LLM may still need its own safeguards. But the model should not become the primary enforcement mechanism for data access.

The retrieval layer knows things the LLM often does not

There is another important reason to place controls here.

A retrieved chunk is not just text.

A well-designed RAG system can know:

source document
document owner
tenant
user permissions
classification
creation time
retention policy
ingestion source
document hash
sensitivity

By the time the LLM sees the chunk, much of that structure may have disappeared.

The model could simply see:

“The employee's compensation package is $180,000…”

It may not know that the text came from:

HR/payroll/2026.xlsx

classification = restricted
allowed_roles = ["HR"]
tenant = company_a

The retrieval layer can.

That gives us something very valuable:

structured security information before the content is flattened into model context.

This is where deterministic rules become possible.

For example:

if chunk.tenant != user.tenant:
    do_not_retrieve()

if "HR" not in user.roles:
    exclude_hr_documents()

if chunk.retention_expired:
    do_not_retrieve()

These rules are boring.

That is a good thing.

Security controls generally become easier to reason about when they do not depend on an LLM interpreting policy correctly.

Vector databases already provide many of the primitives

We do not need to invent this entire architecture from scratch.

Modern vector databases already provide mechanisms that can help enforce isolation.

Qdrant, for example, supports tenant-specific filtering and dedicated tenant shards. A shared collection can attach a tenant identifier to each point and constrain searches using that field.

Weaviate supports multi-tenancy by storing tenants on separate shards so that one tenant's objects are isolated from another tenant's objects.

Other systems use namespaces, metadata filters, SQL row-level security, collections, roles, API keys, or similar mechanisms.

So one important problem is not:

“Can vector databases support security?”

They often can.

The harder question is:

Is the application actually using those controls correctly, consistently, and on every retrieval?

A single missing tenant filter can change:

search all vectors belonging to customer A

into:

search all vectors

The query may still succeed.

The model may still produce an excellent answer.

Nothing necessarily crashes.

The only difference is that the answer may contain another customer's information.

That is exactly the kind of failure traditional application security teaches us to look for.

Retrieval is also where data security and AI security meet

There is something else unusual about vector stores.

They sit between two worlds.

On one side, we have traditional data-security problems:

PII
PHI
credentials
API keys
tenant isolation
RBAC
retention
deletion
encryption

On the other, we have newer AI-specific problems:

RAG poisoning
stored prompt injection
retrieval manipulation
embedding anomalies
semantic enumeration
malicious retrieved context

The vector and retrieval layer contains both.

Imagine VecShield finds a chunk containing medical information.

That is already interesting from a privacy perspective.

Now imagine runtime monitoring also shows that the chunk is being repeatedly retrieved by an account belonging to another tenant.

The combination is much more meaningful:

Sensitive data
      +
unexpected retrieval
      +
wrong tenant

      ↓

high-priority security event

This is harder to see if the data scanner and the AI guardrail live completely separate lives.

The retrieval layer gives us a place to connect:

what is stored

with:

who is retrieving it

and:

why it is reaching the model.

It is largely independent of which LLM you use

RAG applications change models frequently.

An organization might start with one model and later move to another.

GPT
 ↓
Claude
 ↓
Gemini
 ↓
open-source model

A prompt-level defense may behave differently each time.

But this rule:

authenticated_tenant == chunk.tenant

does not care which model comes afterward.

Neither does:

user must have permission to source_document

or:

do not retrieve expired records

That makes retrieval-layer controls useful as a relatively model-independent security layer.

The LLM can change.

The security property remains:

Customer A should not retrieve Customer B's data.

That is much easier to test objectively than:

The model should probably realize that this information looks like it belongs to another customer and avoid mentioning it.

The vector store is persistent

Prompts disappear.

Vector stores do not.

That makes this layer useful for another reason: investigation.

Suppose a suspicious answer was generated yesterday.

A security team may want to know:

Which chunks were retrieved?

Which documents created those chunks?

Who ingested them?

When were they added?

Were they modified?

Were they retrieved by anyone else?

Did they belong to the correct tenant?

Did they contain sensitive information?

Were they later deleted?

If provenance is maintained properly, these questions become answerable.

OWASP's RAG guidance recommends tracking document provenance, ownership, source, hashes and retrieval activity precisely because compromised RAG systems otherwise become difficult to investigate.

This also matters for poisoning.

A malicious instruction may enter through a document today but only be retrieved weeks later.

The attack and the effect can happen at completely different times.

Without provenance, the security team may see a bad model response but have little idea which piece of stored context caused it.

Privacy controls fit naturally here too

Consider what happens when a document enters a RAG system:

Customer record
      ↓
chunking
      ↓
chunk 1
chunk 2
chunk 3
      ↓
embedding
      ↓
vector 1
vector 2
vector 3

Now the customer asks for their data to be deleted.

Deleting the original file does not necessarily prove that everything derived from it disappeared.

The organization may still have:

chunks
embeddings
metadata
cached retrievals
replicas
indexes

This is another reason provenance matters.

If every vector can be traced back to its source, deletion becomes something that can at least partly be verified:

Source document deleted
        ↓
Find all derived chunks
        ↓
Find associated vectors
        ↓
Remove them
        ↓
Verify they are no longer retrievable

OWASP's current RAG guidance explicitly recommends cascading deletion of derived chunks, embeddings and relevant caches when their source data is deleted or loses permission.

This is not only an AI security problem.

It is a data-governance problem created by AI infrastructure.

Retrieval behavior itself can become a security signal

There is also a runtime side.

Consider an attacker trying to learn what is inside a private RAG knowledge base.

They might not issue one obviously malicious request.

Instead:

query 1
query 2
query 3
query 4
...
query 500

Each query is slightly different.

Over time, the attacker attempts to cover more and more of the semantic space and reconstruct information from the retrieved results.

The individual query may look harmless.

The pattern does not.

At the retrieval layer we can potentially observe:

query frequency
documents retrieved
unique chunk coverage
tenant boundaries
repeated near-neighbor exploration
bulk reads
unusual top-k values
retrieval distribution

This begins to look less like prompt moderation and more like traditional intrusion or database activity monitoring.

OWASP similarly recommends monitoring for systematic probing, retrieval abuse and unusual access patterns rather than treating each query independently.

That is another reason retrieval deserves its own security telemetry.

Why haven't we treated it this way already?

Probably because RAG did not begin as a security architecture.

Its original motivation was straightforward:

The model does not know enough. Retrieve relevant information and give it better context.

Most of the engineering attention therefore went toward improving retrieval.

Better embeddings.

Better chunk sizes.

Better reranking.

Better top-k selection.

Better answer quality.

Security attention, meanwhile, naturally focused on the most visible part of an AI application:

User → LLM → Response

So we built prompt filters, jailbreak detectors, guard models, moderation systems and output filters.

But a RAG application actually has another major input:

User input
     ↓
    LLM
     ↑
Retrieved input

The retrieved context may contain thousands of words the user never typed and may never even see.

That makes retrieval almost a second input channel into the model.

And historically, we have put much less security around it.

There is also an organizational reason.

Traditional security tools understand:

PII
credentials
IAM
database permissions
network exposure

AI guardrails understand:

prompts
outputs
jailbreaks
toxicity
model behavior

But RAG sits awkwardly between them.

Traditional security

        ↓

   [ RAG / RETRIEVAL ]

        ↑

      AI safety

A traditional DLP scanner may not understand poisoning, embeddings or semantic retrieval.

An LLM guardrail may not understand vector-store RBAC, tenant boundaries, stale chunks or deletion propagation.

That gap is increasingly important.

This does not mean the vector store solves AI security

The argument should not be taken too far.

The vector store is a security boundary, not the only one.

A complete AI application may still need controls at:

ingestion
retrieval
LLM input
LLM output
agent tools
external APIs
identity
application layer

A retrieval-layer control will not stop every jailbreak.

It cannot authorize a dangerous tool call by itself.

It cannot guarantee that the model will never generate harmful content.

And not every RAG architecture uses a vector database at all.

Some use keyword search, SQL, knowledge graphs, web search or hybrid retrieval.

So the broader principle is:

The retrieval data plane should be treated as a security boundary.

Vector stores are currently one of the most common places where that boundary exists.

RAG security should start before the prompt reaches the model

The useful property of the retrieval layer is that several things still exist there at once:

identity
permissions
tenant
provenance
classification
stored content
retrieval history

After retrieval, much of that becomes:

tokens in a context window

That is why this layer is so interesting.

It gives us one of the last opportunities to make deterministic decisions about which information should reach the model at all.

That suggests a different way of thinking about RAG security.

Instead of asking only:

“How do we stop the LLM from doing something unsafe with this context?”

we should also ask:

“Why was this context allowed to reach the LLM in the first place?”

That is the layer VecShield is focused on: treating vector stores and retrieval infrastructure not simply as search infrastructure, but as part of the security, privacy and accountability boundary of an AI system.

Discussion

  • No comments yet. Start the discussion.