Post

🧵 1/ LLMs are stateless. They don’t remember past interactions. Every prompt is treated as an isolated request. To build actual agents, we need memory. Here’s how to do it using Spring AI and Redis — short-term + long-term memory, fully integrated. (@redis.io)

2/ To fix that, you give your agent memory. T wo types of memory are needed: 🧠 Short-term → conversation history 🧠 Long-term → facts, preferences, experiences We store both in Redis. Short-term in Lists. Long-term as vector embeddings with metadata for filtering.

3/ Short-term memory = the active conversation. It's a list of msgs (user + assistant) that you pass into the LLM. We store it in Redis Lists, reload it on each message, and trim or summarize it to avoid token overflows. In this demo, I reload the chat history from Redis:

4/ Long-term memory = knowledge the agent has accumulated over time and lives through chats. Stored as vector embeddings. Retrieved via semantic search. The agent finds relevant info by similarity when needed. Long-term memory can be used even when we start a new chat:

5/ There are two kinds of long-term memory: - Episodic: personal experiences, user-specific info“User went to Paris in 2009”“User prefers window seats” - Semantic: general knowledge or domain facts“Singapore requires a passport”“Paris is known for art museums”

0 reposts0 likes