Skip to content
BriskStack Study
Sign in
RAG Systems

RAG security, 1 of 2, about 3 h 4 min of reading

RAG Systems

About 2 h 52 min left

Concept. A language model that answers from memory alone knows only what it saw in training. Retrieval-Augmented Generation (RAG) fixes that by attaching an external knowledge base to a frozen model. At query time the model retrieves relevant documents and generates its answer grounded in them, instead of relying on parametric memory (the facts stored in its weights) alone. That one design choice is why RAG powers most production LLM apps, and why it opens LLM09:2026 Vector and Embedding Weaknesses (OWASP, 2026 document p. 50; numbered LLM08 in the 2025 list). This week you build the pipeline end to end, so that the attack in RAG Poisoning & Knowledge CorruptionRAG security, 2 of 2, about 3.6 h targets a pipeline you understand.

๐ŸŽฏ Objectives

By the end of this unit you can:

  • Explain why RAG exists, including the split between parametric and non-parametric memory, and say when to reach for it instead of fine-tuning (Lewis et al.).
  • Build a working RAG pipeline: load, chunk, embed, store, retrieve, generate (LangChain).
  • Describe how a vector database indexes embeddings for approximate nearest-neighbor search, and pick one for a given workload (Pinecone).
  • Map the RAG attack surface to LLM09:2026 and name the trust paradox that makes it exploitable (Christian Schneider).
  • (Go deeper) Build and measure three RAG defenses on a local pipeline (permission-aware retrieval, answer-per-passage voting, noise on stored vectors) and show the attack that gets past each.
Next sectionWhy RAG existsabout 1 minOpening question: A product team wants the assistant to know this week's price list and to say where each answer came from. Fine-tune or RAG, and why?

Why RAG exists

Suppose a support assistant must answer from this week's price list. A pretrained model cannot: it stores facts in its weights (parametric memory), and that memory is frozen at training time, cannot be updated without retraining, and cannot cite a source. The original RAG paper paired a sequence-to-sequence generator (BART) with a non-parametric memory, a dense vector index of Wikipedia queried by a neural retriever (Dense Passage Retrieval, DPR). It beat parametric-only baselines on open-domain question answering and produced "more specific, diverse and factual" text (Lewis et al., NeurIPS 2020).

The insight that every production system has carried forward is to hand the model new facts at inference time instead of teaching them to it. RAG updates knowledge by editing a database, not by retraining a model, and it can show you which document an answer came from.

๐Ÿ’ก RAG or fine-tuning. Fine-tuning changes behavior and style; RAG changes what the model knows right now. If your knowledge changes weekly or needs citations, retrieve it instead of baking it into weights.

Recall from memory

A product team wants the assistant to know this week's price list and to say where each answer came from. Fine-tune or RAG, and why?

Not saved. Sign in and this question comes back in Review when you are about to forget it.

Next sectionHow the pipeline works (Needs access)
Sign in to keep reading. It is free, and your place is kept. Sign in and continue

How the pipeline works

The attack surface: a preview of RAG Poisoning & Knowledge Corruption

Offensive depth: exploiting RAG pipelines

Offensive depth: attacking embeddings

Go deeper: reading a claim of RAG protection

Go deeper: candidate order in the prompt

Go deeper: defending the pipeline you just attacked

โœ… Check yourself

๐Ÿ“‡ Reference appendix

๐Ÿงช This unit's build

Finish RAG Systems

About 2 h 52 min left in this unit.

From memory first

Write the main points of this unit, in your own words.

The unit is done when you have answered the check and marked the required sources.

  1. 1 Check yourself

    Do the check
  2. 2 Required sources

    Go to the sources

Sources in this unit

  • Lewis et al.: "Retrieval-Augmented Generation" (2020)
  • LangChain RAG Tutorial
  • Pinecone: What is a Vector Database?
  • OWASP LLM08:2025: Vector and Embedding Weaknesses
  • PoisonedRAG (USENIX 2025)
  • Christian Schneider: RAG Security: The Forgotten Attack Surface
  • freeCodeCamp: RAG Tutorial with LangChain
  • freeCodeCamp: RAG From Scratch
  • Venelin Valkov: Advanced Retrieval Pipeline for RAG
  • Microsoft: Generative AI for Beginners: RAG & Vector DBs
  • ChromaDB Getting Started
  • MTEB Leaderboard
  • Orca โ€” Pre-Auth RCE in ChromaDB (CVE-2026-45829, CVSS 10.0)
  • Orca โ€” The AI Data You Forgot to Lock (Exposed Vector DBs)
  • DEF CON 33: Exploiting Shadow Data from AI Models and Embeddings (Patrick Walsh)
  • princeton-nlp/corpus-poisoning
  • The Vulnerability of LLM Rankers to Prompt Injection Attacks (arXiv 2602.16752)
  • Morris et al.: Text Embeddings Reveal (Almost) As Much As Text (arXiv 2310.06816)
  • vec2text/vec2text
  • Mask-based Membership Inference for RAG (ACM WWW 2025)

Checklist

It does not count toward done.

  • Explain the difference between retrieval-augmented generation and fine-tuning in terms of parametric and non-parametric memory, and state which one you would use for knowledge that changes weekly.
  • Build a RAG pipeline that loads, chunks, embeds, stores, retrieves and generates, using LangChain with Chroma or Pinecone, and show one answer grounded in a retrieved chunk.
  • Describe how an embedding is generated, how the HNSW, IVF and LSH indexes find neighbors approximately, and how cosine, Euclidean and dot-product similarity differ.
  • Choose a vector database for three given workloads (Chroma for prototyping, Pinecone for production, Milvus for scale) and give one reason for each choice.
  • Map the RAG attack surface to LLM09:2026 (LLM08:2025) and state the trust paradox in one sentence.
  • Poison your own corpus with one crafted document and show the query that makes retrieval surface it.
  • Run the fastest pipeline: add documents to a Chroma auto-embed collection and query it, then switch to the persistent client and show the index survives a restart.
  • Complete the RAG poisoning drill: run black-box PoisonedRAG (S=Q plus an LLM-written I), then defeat a cross-encoder re-ranker with a Decision Objective Hijacking (DOH) injection line and show the poison back at first place.
  • Complete the embedding attack drill: invert embeddings with vec2text, show recall collapsing when you add Gaussian noise, and run a mask-based membership inference attack on a 50-document store.
Drill, planned

One document, one question

Attack: Plant one short document that wins the search for one known question Defend: Measure what the planted document costs: the true answer's rank and other questions' precision

Nothing to do here yet; the unit is complete without it.

Practise this in the lab, The poison that wins on direction.15 to 25 min estimate

Practise this in the lab, Fool a small classifier, then ask what it remembers.1 h to 1 h 30 min estimate

Practise this in the lab, Clone a model through its API, then catch the cloner.1 h to 1 h 15 min estimate

Practise this in the lab, Plant a backdoor, find it without the trigger, remove it.1 h 15 min to 1 h 30 min estimate

Practise this in the lab, Keep planted documents out of a retrieval pipeline.1 h 10 min to 1 h 40 min estimate

Practise this in the lab, Capstone: one engagement, replayable findings and a scope log.1 h 40 min estimate

Study notes

None yet

Sign in to take notes.

More for this unit

14 readings

Readings no section cites. They do not count toward the unit.

Show
RAG architecture and hands-on practice4 readings
  • youtube.comvideoGo deeperabout 1 h 30 min

    This video implements RAG from scratch, hands on. Watch it if you learn better by watching someone type the code.

  • youtube.comvideoGo deeper

    A LangChain engineer teaches indexing, retrieval and query translation (HyDE, RAG Fusion). Watch it for the retrieval half of the pipeline.

  • youtube.comvideoGo deeperabout 15 min

    This video builds hybrid search with reranking, running 100% locally, in a production-grade shape. Watch it after your basic pipeline works.

  • github.compaperGo deeper

    Lesson 15 walks through word-count chunking, embeddings, an sklearn search and augmented generation, using a worked quiz-bot example. Read it if you prefer to wire every stage by hand.

Vector databases4 readings
  • docs.trychroma.comtoolGo deeper

    Chroma is a lightweight open-source vector database that embeds and indexes text automatically, which makes it the fastest path to a working RAG system. Use it for this week's build.

  • huggingface.copaperGo deeper

    The leaderboard compares embedding models on retrieval quality. Open it when you choose an embedder.

  • orca.securityreferenceGo deeper

    user-controlled HuggingFace embedding config is processed before auth in the ChromaDB FastAPI server (v1.0.0โ€“1.5.8), so a crafted trust_remote_code model reference runs arbitrary Python unauthenticated; patch 1.5.9 or use the Rust frontend โ€” directly relevant to any RAG build on Chroma

  • orca.securityreferenceGo deeper

    auth-disabled-by-default Weaviate/Milvus/ChromaDB expose PII, credentials and medical records to the internet; semantic search itself becomes a credential-extraction primitive, with a documented lateral-movement case

RAG security (a preview for Week 12)1 reading
Offensive depth: RAG poisoning and re-ranker attacks2 readings
  • github.comtoolGo deeper

    This repository is a HotFlip adversarial-passage generator. Run it against a local Contriever in the m5 drill.

  • arxiv.orgpaperGo deeper

    Yin, Wang, Koopman and Zuccon test two injection variants planted in a candidate document, decision objective hijacking and decision criteria hijacking, against LLM rankers. Read it before the DOH step of the m5 drill.

Offensive depth: attacking embeddings3 readings
  • arxiv.orgpaperGo deeper

    This is the vec2text paper. It reconstructs 92% of 32-token inputs exactly and recovers patient names from MIMIC-III notes. Read it before the m6 drill.

  • github.comtoolGo deeper

    This is the reference embedding-inversion toolkit, with an iterative corrector, installed with pip install vec2text. Use it in the m6 drill.

  • dl.acm.orgpaperGo deeper

    The method blanks spans of a candidate and uses the reconstruction to signal membership. Read it before the mask-based step of the m6 drill.

This unit's library holds 16 more readings for readers with access.