Retrieval-Augmented Generation (RAG) Security
RAG security is protecting AI systems that answer questions by searching a company's own documents and data. The main risks are leaking information to the wrong users, poisoned documents and hidden instructions in retrieved content.
Also called: RAG security, vector database security, embedding security, AI knowledge base security
What is RAG?
Retrieval-augmented generation (RAG) is the most common way businesses connect AI to their own information. When someone asks a question, the system first retrieves relevant passages from a knowledge base, such as policies, manuals, contracts, tickets, emails or a website, then gives them to the AI model to generate an answer. Documents are usually stored as "embeddings" in a vector database so they can be searched by meaning.
Internal AI assistants, customer support bots that answer from help articles, and tools like Microsoft Copilot searching your files all work this way.
The main risks
OWASP covers RAG under "vector and embedding weaknesses" in its Top 10 for LLM applications. Key risks:
- Unauthorized access and data leakage. If the retrieval step ignores permissions, the AI can quote documents the user was never allowed to see. In systems shared by several customers or departments, OWASP warns of context leaking between users.
- Poisoned documents. Anyone who can add content to the knowledge base, including through public sources like web pages or customer emails, can plant false information the AI will repeat. See AI data poisoning.
- Hidden instructions. Retrieved documents can contain indirect prompt injection that hijacks the AI's response or actions.
- Embedding inversion. OWASP notes attackers may be able to recover significant source information from stored embeddings, so the vector database itself holds sensitive data.
- Stale or conflicting data, leading to confident wrong answers.
How to secure RAG
- Enforce access control at retrieval time. The system should only search documents the current user is already permitted to read, using the original permissions.
- Clean up permissions before connecting data. Overshared folders become overshared AI answers.
- Separate data for different customers or tenants.
- Control and validate what goes into the knowledge base, and track where each document came from.
- Treat retrieved content as untrusted data, not instructions.
- Protect the vector database like any sensitive data store, with encryption, access control and logging.
- Exclude highly sensitive data unless it's truly needed.
- Log queries and retrieved documents for review, and test with AI penetration testing.
Related terms
Sources
- LLM08:2025 Vector and Embedding Weaknesses (OWASP Gen AI Security Project)
- LLM01:2025 Prompt Injection (OWASP Gen AI Security Project)
Drafted with AI assistance, then edited and fact-checked by a person. How we use AI.
