cd /news/large-language-models/rag-memory-systems Β· home β€Ί topics β€Ί large-language-models β€Ί article
[ARTICLE Β· art-95725] src=dev.to β†— pub= topic=large-language-models verified=true sentiment=Β· neutral

RAG - Memory Systems

A developer explains how to implement memory systems for retrieval-augmented generation (RAG) in large language models, distinguishing between short-term memory (using Redis, Valkey, Memcached, or Cosmos) and long-term memory (using Postgres, Pinecone, or MongoDB). The post details episodic, semantic, and entity fact memory types, and recommends storing summaries and relevant facts rather than entire conversations to optimize token usage.

read3 min views1 publishedAug 13, 2026

We need memory to store the previous conversational history.

For example: Previous question is:

User: File handling in Python

Assistant: Explain about file handling.

Next time, the user asks:

User: What are the modes in it?

The LLM should understand the context and then respond.

Below are the details that can be stored in the memory.

Based on the details we are storing, we will choose between long-term or short-term memory.

Redis, Valkey, Memcached, and Cosmos, which are cached databases, can be used for short-term memory to store the last few conversations or a summary.

We can set a general data invalidation rule to erase the content or use an LRU cache eviction policy, where the least recently used data will be erased from the database.

Postgres, Pinecone, and MongoDB can be used for long-term memory to store long conversation histories.

A summary of the entire conversation history will be stored in short-term memory to reduce latency whenever needed.

Episodic memory is a type of memory that stores specific events or experiences that happened in the past, usually together with information about what happened, when it happened, and the context surrounding it.

We can use either a short-term or long-term memory database depending on the use case. It is a kind of combination of short-term and long-term memory.

User:

I am planning a trip to Paris.

Agent:

How many days will you stay?

User:

5 days.

Later, User:

Can you suggest an itinerary?

User wants to travel to Paris.

Trip duration: 5 days.

User previously mentioned:

Destination = Paris

Duration = 5 days

This information can be used to provide a more relevant response.

This helps the LLM understand what happened previously.

Semantic memory contains facts extracted from previous conversational history. Semantic memory is generally considered long-term memory.

Paris is the capital of France.

The Louvre is a museum in Paris.

France uses the Euro.

That's general knowledge.

It is a short-term memory. Here, we store the last 3 to 4 conversations.

Redis or Valkey, like any cache memory, can be used.

Each and every time, the conversation, which includes the user query and response, will be summarized.

Even though token consumption during summarization is more, overall token consumption will be less.

It is a long-term memory.

This memory is used to store facts about a particular entity.

The difference between entity fact memory and semantic memory is that semantic memory is the broader category. Entity fact memory is one way of organizing and storing semantic knowledge about specific entities.

It can be used as either long-term or short-term memory.

Entity: Python

Python β†’ is a programming language

Python β†’ is used for AI

Python β†’ supports object-oriented programming

Python β†’ was created by Guido van Rossum

Entity: Alice

Alice β†’ works at ABC Company

Alice β†’ prefers Python

Alice β†’ is working on Project X

It is not a good practice to store the entire conversation. We can make decisions based on the conversation and then store the relevant information. This is a good practice.

── more in #large-language-models 4 stories Β· sorted by recency
── more on @redis 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/rag-memory-systems] indexed:0 read:3min 2026-08-13 Β· β€”