AI Memory, RAG & Prompt Injection Explained | Stanford CS193T Lecture 3 with Cynthia Bailey
From Stanford Online · · 1 hr 3 min

The player loads from YouTube only when you click. It uses YouTube's privacy-enhanced mode.
If the video does not play, the owner may have turned off embedding. Watch it on YouTube instead.
Description
Explore AI courses and programs from Stanford Online: https://stanford.io/4BYTekh
What else is sharing your AI's context window besides your prompt? In this Stanford CS193T: Thinking with AI lecture recording, Senior Lecturer Cynthia Bailey focuses on context, information, and prompt instructions that persist beyond a single chat session: settings, remembered facts, uploaded files, and retrieved web pages. Examples include how to use these tools to reduce sycophancy and "AI style," understanding what your chat history is (and isn't) used for, saving your best prompts as reusable Skills or Gems, and strategic withholding, where the smartest prompt leaves something out. She introduces retrieval-augmented generation (RAG) for grounding AI in your own documents when they would overflow the context window, and the documented ways trust in a RAG store can fail. The lecture closes on a cybersecurity note with prompt injection: why an AI can't always tell your instructions apart from malicious text on the internet.
Key questions answered in this lecture recording: Q: Does ChatGPT learn from my conversations? A: A released model's weights are frozen, so memories change behavior only through the context window. But a company that sees your chat history could use it to train future models; Stanford's licensed AI tools prohibit that, while personal accounts may not.
Q: What is retrieval-augmented generation (RAG)? A: RAG is a user-curated document store, much larger than the context window, that the tool searches to place only relevant documents into the context. Because RAG content gets extra weight, Bailey warns that bad sources can poison results.
Q: What is the adaptive chameleon vs stubborn sloth problem in LLMs? A: Citing the paper "Adaptive Chameleon or Stubborn Sloth," Bailey explains that models sometimes accept bad information in your RAG too eagerly and sometimes ignore your sources in favor of training data. Either behavior can help or hurt.
Q: How do I get more honest feedback from ChatGPT or Claude? A: Use strategic withholding: ask the AI to evaluate "this essay," not "my essay," or frame your resume as a candidate's, and use a temporary chat so memories don't reveal it's yours.
Q: What is prompt injection? A: The system prompt, your prompt, and retrieved web pages are one continuous stream of tokens, so hidden text on a web page can issue instructions the model may obey. The risk grows when AI has connectors to email or files.
Q: Do Claude Skills or Gemini Gems fine-tune the model? A: No. Bailey says skills and gems are one more piece of text in the context window, functioning between the system prompt and your prompt, and they do not change the model's weights.
Chapters: 0:00 Managing sources and the context window 1:06 Saving preferences in ChatGPT 3:24 Claude's system prompt and custom instructions 6:53 How AI memory works across chats 9:44 Importing ChatGPT memories into Gemini 11:25 Everything that fills the context window 15:47 Chat privacy: do your chats train AI models? 18:41 RAG: retrieval-augmented generation 22:31 Adaptive Chameleon or Stubborn Sloth 28:43 Saving reusable prompts: Claude Skills, Gems 36:19 Strategic withholding for candid AI feedback 44:47 Overriding the system prompt and red teaming 50:01 Prompt injection from web documents 53:57 Q&A: connectors and prompt injection defenses
About the speaker: Cynthia Bailey is a Senior Lecturer in the Computer Science Department at Stanford University. In 2023-2024, she served as an AI Policy Fellow in the United States Senate through the American Association for the Advancement of Science (AAAS). Her scholarship focuses on computer science education, AI/machine learning, and the social impacts of technology, including creating courses such as Equity and Governance for Artificial Intelligence and Race and Gender in Silicon Valley. Her teaching and research awards include the Lloyd W. Dinkelspiel Award for exceptional contributions to undergraduate…