Vector Database Security for LLM Applications
Vector database security for LLM apps — tenant isolation, authorization, sensitive embeddings, poisoned sources, and retention at the application layer.
Vector databases power semantic retrieval in LLM applications — but security does not live inside the embedding index alone. Vector database security for LLM apps is primarily application-layer: tenant isolation, authorization filters, sensitive data handling, poisoned source detection, and access logging around every query and upsert.
Treating the vector store as a passive cache invites cross-tenant leakage, unauthorized retrieval, and persistent injection payloads that similarity search returns for benign queries.
What the vector DB actually stores
A typical RAG record:
| Field | Security relevance |
|---|---|
embedding | Not human-readable; still derived from sensitive text |
chunk_text or object storage pointer | May contain PII, secrets, injection payloads |
metadata | Tenant ID, ACL, doc_id, trust tier, sensitivity |
source_uri | Provenance for incident response |
Embeddings are not encryption. Anyone with database access can often reconstruct approximate content or join back to stored text. Protect the store like any datastore holding customer documents.
Hub context: RAG Security.
Threat model for vector stores in LLM apps
| Threat | Example | Mitigation |
|---|---|---|
| Cross-tenant retrieval | Shared index, missing filter | Per-tenant collection or strict metadata filters |
| Broken object-level ACL | User retrieves manager-only doc | Enforce ACL in query filter, verify post-fetch |
| Sensitive data in embeddings | SSN in chunk text | PII scan at ingest; minimize stored text |
| Poisoned documents | Malicious upload indexed | Ingest validation, quarantine, monitoring (poisoning) |
| Injection via stored chunks | Instructions in chunk_text | Retrieve-time scanning (secure retrieved docs) |
| Credential exposure | DB connection string leaked | Secrets management, network isolation, IAM |
| Stale revoked content | Deleted doc still embedded | TTL, delete propagation, re-index jobs |
Tenant isolation patterns
Choose one primary strategy (can combine):
1. Separate collections per tenant
- Strongest isolation boundary
- Higher operational overhead at scale
- Natural fit for enterprise "dedicated index" tiers
2. Shared collection + mandatory metadata filter
{
"filter": {
"tenant_id": { "$eq": "tenant_abc" },
"visibility": { "$in": ["public", "authenticated"] }
}
}
- Every query must include tenant filter — enforce in code, test for bypass
- Single missing filter in one code path = critical vulnerability
3. Sensitivity-tiered indexes
public_kb,internal_kb,restricted_kbper tenant- Query router selects index based on user clearance
Multi-tenant SaaS: AI SaaS guardrails.
Authorization is not similarity
Vector search returns semantically similar chunks, not permitted chunks.
Required pattern:
- Resolve user/tenant/session server-side
- Build authorization filter from your identity system
- Execute similarity search with filter
- Optionally re-verify each
doc_idagainst source-of-truth ACL service - Scan surviving chunks before LLM (prevent RAG injection)
Never accept tenant_id or user_id from client JSON without authentication.
Securing upsert and ingest paths
Attackers target write paths:
- Authenticate all ingest APIs
- Rate limit uploads per tenant
- Scan full document before embedding (
POST /api/v1/security/prompt-injection,POST /api/v1/security/pii-secrets) - Reject or quarantine
unsafefindings - Store provenance:
uploader,content_hash,ingested_at - Validate
metadataschema — prevent privilege escalation via craftedtenant_idin metadata
Ingest compromise is data poisoning — see RAG Data Poisoning Explained.
Sensitive embeddings and text retention
Options to reduce exposure:
| Approach | Trade-off |
|---|---|
| Store only embedding + pointer to encrypted object storage | Extra fetch latency |
| Store redacted chunk text at index time | May lose retrieval quality |
| Omit full text from vector DB; fetch from doc store after ID match | Two-step retrieve |
| Encrypt chunks at rest (KMS) | Platform feature; key rotation discipline |
Run PII/secrets detection before persistence (PII leakage checklist).
Network and credential security
Infrastructure practices (cloud-specific details vary):
- Private networking between app and vector service
- IAM roles with least privilege — separate read vs write credentials
- No vector admin keys in application containers or LLM prompts
- Audit admin console access
- Backup encryption and restore testing
These do not replace application authorization but limit blast radius of infra compromise.
Poisoned and compromised sources
Defensive controls:
- Monitor new
unsafefindings persource_uri - Alert when one
doc_iddominates retrieval for diverse queries - Ability to delete embeddings by
doc_idwithout full reindex downtime - Version corpus snapshots for rollback
Do not rely on "our documents are internal" — document injection and supply-chain PDFs happen.
Query logging and privacy
Log:
- Query id, tenant, user (hashed if required), filter applied
- Retrieved
doc_ids and scores - Guardrail
request_idif chunks scanned post-fetch
Avoid logging full query text in production if queries contain PII. Balance forensics with minimization (LLM data leakage).
Retention and deletion
When users delete documents or leave a tenant:
- Delete vectors by
doc_idortenant_id - Delete object storage blobs
- Propagate deletion to backups per policy
- Document lag if async deletion
Stale vectors are both a privacy issue and an injection reservoir.
Security checks around retrieval
Vector DB security complements content scanning:
POST /api/v1/guard
{
"text": "<concatenated retrieved chunks>",
"checks": ["prompt_injection", "pii_secrets"]
}
Run after authorized fetch, before LLM. Unified Guard orchestrates multi-check paths; Prompt Injection Shield for injection-only.
Testing vector security
- Tenant A cannot retrieve Tenant B's planted chunk (automated test)
- Missing filter in test harness fails CI
- Revoked document not returned after deletion job
- Ingest with
unsafeinjection rejected - Admin credentials not in repo or prompts (prevent API key leak)
Checklist summary
- Tenant isolation strategy documented and enforced in code
- Authorization filter on every query
- Ingest authentication and scanning
- Retrieve-time chunk screening
- Provenance and deletion workflows
- Poisoning monitoring
- Infrastructure least privilege
- Privacy-safe logging
Full RAG guardrails: LLM Guardrails Checklist. Vector-adjacent injection: Indirect Prompt Injection in RAG.
Summary
Vector database security for LLM applications means enforcing tenant and document ACLs on every query, securing ingest paths against poisoned content, minimizing sensitive text retention, and pairing storage controls with retrieve-time guardrails — not assuming embeddings are safe because they are numerical.
Lock down isolation and authorization first, then layer Unified Guard checks on chunks before they reach the model.
Frequently asked questions
Is vector database security only about encryption?
Encryption at rest and network isolation matter, but LLM app security depends heavily on application-layer tenant filters, document ACLs, ingest authentication, and retrieve-time content scanning.
How do I prevent cross-tenant retrieval in RAG?
Use separate collections per tenant or mandatory metadata filters on every query. Test that a missing filter fails CI. Never trust client-supplied tenant identifiers without server authentication.
Do embeddings hide sensitive text?
No. Embeddings are derived from chunk text and the store often retains text or pointers to it. Treat vector records like any datastore holding customer documents.
How does data poisoning affect vector stores?
Malicious documents indexed like any other content can dominate similarity search. Defensive ingest scanning, provenance metadata, monitoring by doc_id, and fast embedding deletion contain impact.
Where do guardrail APIs fit relative to the vector DB?
After authorized retrieval and before LLM prompt assembly — scan chunks with POST /api/v1/security/prompt-injection or POST /api/v1/guard. The vector DB should not be the only security control.
Related reading
- RAG Security: Risks Every Developer Should Know
RAG security risks — untrusted documents, indirect prompt injection, data poisoning, access control, sensitive retrieval…
- RAG Data Poisoning Explained
RAG data poisoning — how compromised knowledge sources influence retrieval, validation strategies, trusted ingestion, pr…
- Securing Retrieved Documents Before They Reach an LLM
Secure RAG retrieved documents with trust boundaries, source validation, content scanning, authorization, and instructio…