<!-- generated by build_articles.py — edit content/answers/agentic-memory-vs-rag.md instead -->
---
title: "Agent memory vs RAG: what each does, and when to use both"
canonical: "https://xerj.org/answers/agentic-memory-vs-rag"
updated: "2026-11-15"
source: "content/answers/agentic-memory-vs-rag.md"
---

# Agent memory vs RAG: the difference, and when you need both

**Short answer** (updated 2026-11-15): What is the difference between agent memory and RAG? RAG retrieves passages from documents, code or data you already have and answers from them. Agent memory keeps what the agent learns during work, such as a user preference, so the next session can recall it. Memory is often read back with RAG-style search, and many agents need both.

**TL;DR** RAG finds the answer in sources you already have, such as docs, code and data, and answers from those passages. Agent memory keeps what the agent learns while it works, such as a preference the user stated, so the next session can use it. Memory is usually read back with search, so the two meet in the retriever. Many agents need both, and XERJ serves file search and agent memory from the same local binary.

## Agent prompt

```text
Act as a coding agent. Read https://xerj.org/llms.txt, install XERJ, run xerj autoindex on this project folder for RAG-style retrieval, store two facts I tell you with POST /_memory/project, then answer one question using both the index and memory recall and cite where each part came from.
```

## Commands

### Command 1

Note: Install the single XERJ binary.

```sh
curl -fsSL https://xerj.org/get | sh
```

### Command 2

Note: The RAG side: index a folder of documents so the agent can search them.

```sh
xerj autoindex ./docs
```

### Command 3

Note: The memory side: the agent saves something it learned during the task.

```sh
curl -s -XPOST 'http://127.0.0.1:9200/_memory/project' -H 'content-type: application/json' -d '{"text":"The customer asked for weekly reports, not daily."}'
```

### Command 4

Note: In a later session, the agent recalls the note before it starts.

```sh
curl -s -XPOST 'http://127.0.0.1:9200/_memory/project/_recall' -H 'content-type: application/json' -d '{"query":"report format"}'
```

*Figure: Runs in your browser and sends nothing. Each answer adds a point to the option it matches. A rule of thumb, not a benchmark.*

## The difference in one table

| | RAG | agent memory |
| --- | --- | --- |
| what it reads | documents, code, tickets, data, raw history | notes the agent saved: preferences, decisions, lessons |
| who writes it | people and systems, before the question | the agent, during work |
| how long it lasts | as long as the source files | until the agent updates or deletes the note |
| typical question | "where is the retry logic for webhooks?" | "what did the user say about report format?" |
| how it is read | search, then generate | search, then generate |

The last row is the important one. Both sides end in a search step. The quality of an agent's answers depends on how well that search finds the right passage or note, whatever you call the layer above it.

## What RAG does well

Retrieval augmented generation answers a question from evidence. A retriever finds a few passages, and the model writes its answer from them, ideally with citations. RAG fits any source that already exists: a docs folder, a repo, a ticket export, a log archive. Nothing has to be learned first, and when the files change you re-index them.

RAG does not keep anything on its own. If the user tells the agent "reports should be weekly, not daily", that sentence is gone after the session unless something writes it down. For a step-by-step build, see [RAG without a vector database](/answers/rag-without-vector-database).

## What agent memory adds

Agent memory, also called agentic memory, is the part that writes. The agent saves short notes about what it learned, recalls the relevant ones at the start of a later task, and updates or deletes notes that go stale. Good memory notes are small and specific: a decision, a preference, a lesson from a failed run.

Memory is useful for facts that live nowhere else. It is a poor copy of facts that already live in files, because the note and the file can drift apart. Index the file instead and let RAG read it. More on the concept is in [what is agentic memory](/answers/what-is-agentic-memory).

## When plain retrieval is enough

Two 2026 arXiv preprints tested conversational memory tasks. One found a plain raw-history RAG baseline ranked first among the compared memory systems in six of seven settings. The other found no consistent advantage for explicit memory systems over strong raw-history retrieval.

So start simple: keep the history, search it well, and add a memory layer when you can name the facts it should hold. These studies used dense retrieval, reranking and a reader LLM; their results do not measure XERJ.

## Agentic RAG sits in between

Agentic RAG means the agent decides when and what to search, often over several rounds, instead of one fixed lookup before the answer. It is still retrieval. Once the agent also saves what it found for later tasks, a memory workflow joins in. See [agentic RAG vs RAG](/answers/agentic-rag-vs-rag) for the loop in steps.

## How XERJ does both

XERJ is the search engine for AI agents: a new way for AI to search for data.

- RAG side: `xerj autoindex <folder>` makes your files searchable through the Elasticsearch-compatible API and the MCP server.
- Memory side: `POST /_memory/{namespace}` saves a note, `POST /_memory/{namespace}/_recall` finds it, and `DELETE /_memory/{namespace}/{id}` forgets one. Plain query recall is BM25; `"hybrid": true` adds semantic recall.
- Both live in one local binary without a separate vector database. The lexical default needs no external model-provider key; secured node access uses a XERJ API key.

The default embedder is lexical feature hashing. For neural embeddings, start the node with `--embed-mode neural`. XERJ is single-node. To compare memory tools, see [XERJ vs agent memory tools](/compare/xerj-vs-agent-memory-tools) and [what is an MCP memory server](/answers/what-is-an-mcp-memory-server).

## Try it

Copy the prompt on this page into your coding agent. It indexes a folder, stores two facts and answers one question from both. It cites which part came from files and which from memory.

More comparisons: [best graph database for GraphRAG 2026](/compare/best-graph-database-for-graphrag-2026) and [best memory for AI coding agents 2026](/compare/best-memory-for-ai-coding-agents-2026).

## FAQ

### What is the difference between agent memory and RAG?

RAG retrieves passages from sources you already have and answers from them. Agent memory stores what the agent learns while working so later sessions can use it. Memory systems often use RAG-style search to read their notes back.

### When should I use RAG instead of memory?

Use RAG when the answer is already written down in docs, code, tickets or data. Indexing those files is enough; there is nothing new to remember.

### Is agentic memory the same as RAG?

They overlap. RAG is a retrieval-and-generation technique; agentic memory is information retained across tasks. A memory system can use RAG to retrieve its stored notes or raw history.

### What is agentic RAG?

RAG where the agent decides when and what to search, often over several rounds, instead of one fixed lookup before the answer.

### Do I need both?

Often yes. Use RAG for docs, code and data you already have. Use memory for things the agent learns that are written nowhere else, such as a user preference.

### Is complex agent memory better than plain retrieval?

Not always. Two 2026 arXiv studies found plain retrieval over raw history often matched or beat more complex memory systems on their benchmarks.

### Can one tool do both?

Yes. XERJ indexes your files for search and also has a /_memory API for agent notes, in the same local binary.

## Evidence

- Is Complex Agentic Memory Always Needed? Naive RAG Is Stronger Than We Thought: a raw-history RAG baseline ranks first among the compared memory systems in six of seven benchmark-model settings. Source: [https://arxiv.org/abs/2610.30755](https://arxiv.org/abs/2610.30755)
- Do Conversational Agents Need Explicit Memory? finds only localized gains for explicit memory systems and no consistent advantage over strong raw-history RAG baselines. Source: [https://arxiv.org/abs/2610.24671](https://arxiv.org/abs/2610.24671)
- XERJ memory: POST /_memory/{namespace} stores, POST /_memory/{namespace}/_recall recalls with BM25 by default, each namespace is its own index. Source: `engine/crates/xerj-api/src/memory_api.rs`

## Related

- [How to use agentic memory in XERJ](/answers/what-is-agentic-memory)
- [What is an MCP memory server?](/answers/what-is-an-mcp-memory-server)
- [RAG without a vector database: 3 vectorless RAG setups that work](/answers/rag-without-vector-database)
- [Agentic RAG vs RAG: which one fits your question?](/answers/agentic-rag-vs-rag)
- [Mem0 vs Zep vs Letta vs Cognee: which agent memory framework fits in 2026?](/compare/xerj-vs-agent-memory-tools)
- [Should my agent call a search API or stand up Qdrant for persistent memory?](/compare/xerj-vs-vector-database)
- [What's a simple way to give an agent long-term memory on my laptop without Qdrant?](/answers/agent-memory-without-postgres-qdrant) (same intent: agent memory)
- [XERJ vs agentmemory: which memory for your coding agent?](/compare/xerj-vs-agentmemory) (same intent: agent memory)
- [XERJ vs Mem0: which memory fits your AI agent?](/compare/xerj-vs-mem0) (same intent: agent memory)
