ANSWERS · AGENT MEMORY: CONCEPTS

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

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-10-28 · UPDATED · 2026-11-15
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.

Try it: RAG, memory, or both?

Answer three questions about your agent

Where does the answer live today?
Does it need to last past this task?
What does a typical question look like?

Retrieve

RAG over your files

Index the folder once, search it on every question, answer from the passages found.

Remember

Agent memory

Save what the agent learns as short notes, recall them in later sessions, delete what goes stale.

Both

One search engine for both

Files and notes in the same local node, so one query can return a passage and a remembered fact.

Runs in your browser and sends nothing. Each answer adds a point to the option it matches. A rule of thumb, not a benchmark.
PASTE THIS TO YOUR AI AGENT. IT DOES THE REST 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.
RUN THIS XERJ COMMAND curl -fsSL https://xerj.org/get | sh Install the single XERJ binary.
RUN THIS XERJ COMMAND xerj autoindex ./docs The RAG side: index a folder of documents so the agent can search them.
RUN THIS XERJ COMMAND 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."}' The memory side: the agent saves something it learned during the task.
RUN THIS XERJ COMMAND curl -s -XPOST 'http://127.0.0.1:9200/_memory/project/_recall' -H 'content-type: application/json' -d '{"query":"report format"}' In a later session, the agent recalls the note before it starts.

The difference in one table

RAGagent memory
what it readsdocuments, code, tickets, data, raw historynotes the agent saved: preferences, decisions, lessons
who writes itpeople and systems, before the questionthe agent, during work
how long it lastsas long as the source filesuntil 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 readsearch, then generatesearch, 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.

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.

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 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.

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 and 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 and 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

Related