# Grounding and memory

> A model only knows its training data and what is in its context window. Grounding supplies the facts a task needs at the moment of asking, usually by retrieving documents. Memory carries information across turns and sessions. This topic explains both, what they fix, what they do not, and how a crowded context degrades.

Page: https://schubergphilis.github.io/ai-training/topics/concepts/grounding/
License: CC BY-SA 4.0, https://creativecommons.org/licenses/by-sa/4.0/

*Concepts* · topic `concepts/grounding`

A model only knows its training data and what is in its context window. Grounding supplies the facts a task needs at the moment of asking, usually by retrieving documents. Memory carries information across turns and sessions. This topic explains both, what they fix, what they do not, and how a crowded context degrades.

## Concepts

- **Retrieval (RAG)**: Retrieval-augmented generation: before the model answers, a search finds the passages most relevant to the question and pastes them into the prompt, so the answer can rest on documents the model never saw in training. It is how assistants answer about your files or a company wiki. Its quality is bounded by the search; irrelevant passages produce confident wrong answers. [glossary](https://schubergphilis.github.io/ai-training/glossary/#retrieval-rag)
- **Grounding**: Tying a model's answer to sources it was given rather than to what it remembers. A grounded answer cites the passage it relied on and says so when the sources do not cover the question. Grounding reduces hallucination about the supplied material but does not make the model check facts on its own, and it cannot fix a source that is wrong. [glossary](https://schubergphilis.github.io/ai-training/glossary/#grounding)
- **Short- and long-term memory**: Short-term memory is the current context window: everything said and seen in this session, gone when it ends. Long-term memory is anything written down outside the window and read back later, such as notes files, summaries or a database the agent searches. Models have no other memory; "it remembered" always means something was stored and re-read. [glossary](https://schubergphilis.github.io/ai-training/glossary/#short-and-long-term-memory)
- **Context rot**: The decline in a model's performance as its context window fills with old turns, tool output and stale instructions. Important details get lost among irrelevant ones, early instructions are followed less reliably and answers drift. Long sessions and large pasted documents cause it. The cure is to keep context short and deliberate: summarize, start fresh, or retrieve only what is needed. [glossary](https://schubergphilis.github.io/ai-training/glossary/#context-rot)

## Links

- **Builds on:** [What an agent is](https://schubergphilis.github.io/ai-training/topics/concepts/what-is-an-agent/)
- **Leads to:** [Agentic retrieval and memory](https://schubergphilis.github.io/ai-training/topics/building-agents/retrieval-memory/), [Context engineering for code](https://schubergphilis.github.io/ai-training/topics/coding-with-agents/context/), [Memory and session context](https://schubergphilis.github.io/ai-training/topics/customizing-agents/memory/)
- **Competencies drawing on it:** [Explains how a language model produces text and where it fails](https://schubergphilis.github.io/ai-training/competencies/concepts/explains-models/)

## Lessons

- [Where memory comes from](https://schubergphilis.github.io/ai-training/concepts/memory/) (explanation)
- [Answers from documents the model never saw](https://schubergphilis.github.io/ai-training/concepts/retrieval/) (tutorial)

## Sources

- `AEC-05` [Memory and context: context engineering, memory kinds, memory versus RAG, context rot](https://lsimons.github.io/agent-engineer-course/05-memory-and-context/), Agent Engineer Course (course)
- `AEC-08` [Agentic RAG: the retrieve, evaluate, refine loop; when basic RAG is enough](https://lsimons.github.io/agent-engineer-course/08-agentic-rag/), Agent Engineer Course (course)
- `Academy ai-capabilities-and-limitations` [AI capabilities and limitations](https://academy.claude.com/courses/ai-capabilities-and-limitations), Claude Academy (course)
- `OpenAI Academy build-with-retrieval-augmented-generation-2v6xg` [Build with Retrieval-Augmented Generation](https://academy.openai.com/public/courses/build-with-retrieval-augmented-generation-2v6xg), OpenAI Academy (course)
