Skip to content

Add blog: Reduce Token Cost for LLMs, AI Agent Memory with Valkey and Mem0#503

Open
cnuthalapati wants to merge 7 commits intovalkey-io:mainfrom
cnuthalapati:blog/ai-agent-memory-valkey-mem0
Open

Add blog: Reduce Token Cost for LLMs, AI Agent Memory with Valkey and Mem0#503
cnuthalapati wants to merge 7 commits intovalkey-io:mainfrom
cnuthalapati:blog/ai-agent-memory-valkey-mem0

Conversation

@cnuthalapati
Copy link
Copy Markdown
Contributor

Summary

Adds a technical deep dive on using Valkey with Mem0 to build persistent memory for AI agents, as proposed in #492. The post covers:

  • The three scopes of agent memory (session, state, long-term)
  • When to use local memory (CLAUDE.md, Cursor Rules) vs an external memory store
  • How agent memory is written and retrieved with Valkey and Mem0 (index creation, storage pipeline, retrieval pipeline)
  • Four storage-layer requirements that distinguish agent memory from single-query RAG (scoped ownership, frequent mutation with read-after-write visibility, selective retrieval under concurrency, data life controls)
  • A comparison of Valkey Search, Postgres + pgvector, and OpenSearch against those requirements
  • Production patterns: anonymous-to-authenticated migration, concurrency and consistency, observability, and index health

Also adds a new author profile for Meet Bhagdev (third author).

Files added

  • content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md
  • content/authors/mbhagdev.md
  • static/assets/media/authors/mbhagdev.jpeg

Test plan

  • Validate TOML frontmatter renders correctly in Zola
  • Confirm byline picks up all three authors from profiles
  • Confirm featured image loads
  • Verify all external links resolve

Refs #492

… Mem0

Adds a technical deep dive covering how agent memory works, when to use local vs external memory, an implementation using Valkey and Mem0, storage-layer requirements, and production patterns. Also adds an author profile for Meet Bhagdev.

Refs valkey-io#492

Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Address reviewer feedback:
- Rename "Types of Agent Memory" to "Breaking Down AI Agent Interactions" and reorder memory types by zoom-out (step, turn, session, cross-session)
- Rename "When to use local vs external memory" to "How to Add Memory to Agents", lead with scope of availability as the deciding factor
- Fix FT.CREATE syntax to declare TYPE per field, use TEXT for memory, reorder schema to match narrative
- Add FT.SEARCH and HSET blocks under Memory Storage and Retrieval so code samples match the underlying Valkey layer
- Reframe Mem0 as the actor throughout Memory Layers section
- Scope Storage Layer Considerations to long-term memory
- Tie Anonymous-to-Authenticated Migration back to Valkey low-latency writes and read-after-write visibility
- Consistent Title Case headings, minor typo and formatting fixes

Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Copy link
Copy Markdown
Member

@allenss-amazon allenss-amazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much much better. just a few nits.

Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Copy link
Copy Markdown
Member

@allenss-amazon allenss-amazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of comments remain.

Copy link
Copy Markdown
Member

@stockholmux stockholmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few points:

  1. Does everything in this blog work with open source? There is mem0 blog linked that seems to be a basis for this post but that's specific to ElastiCache.
  2. There is too many bolded words throughout. These should be rare and not a replacement for headings (for many reasons: SEO, linking, etc.)
  3. At several points during the post it seems to go into laundry list mode and lose the sentence clarity entirely.
  4. Throughout the blog post isn't consistent about using inline code blocks, caps, quotes, etc.

Generally, I'm still a little unclear who this post is for - it feels like there is an assumed familiarity with Mem0. That is probably not a good assumption for our readers.

Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
- Memory categorization: rename "local vs external" to "file-based context vs store-backed memory layer"; add naming sentence before examples

- Session memory: ground as the classic Valkey session-store pattern applied to conversation state

- Long-running agents: replace "highlights the need" with a concrete Anthropic quote and drop the OpenAI running-agents link

- Mem0 "memory" terminology: define as a named unit on first use; rename pre-decision "candidate memory" to just "candidate"; remove "hash-backed document" jargon

- Index schema: trim to fields the prose actually explains; fix mislabel that called created_at/updated_at metadata attributes

- Write path: link FT.SEARCH and HSET; note that HSET updates the index in place so writes are immediately searchable

- Scoped ownership: add closing tradeoff sentence contrasting TAG attributes vs namespaced keys; backtick the namespace tuples

- Section 2 framing: replace "if writes are slow" with explicit forced-tradeoff framing and tie Valkey update latency directly to resolving it

- Section 3: replace microsecond/multi-million claim with canonical single-digit millisecond latency and over 99% recall at billions of vectors, linked to valkey.io/topics/search/

- Section 4: link EXPIRE, TTL, PERSIST, UNLINK, HEXPIRE, HTTL to Valkey command docs

- Concurrency pattern: backtick and link SET and INCR

- Observability: replace long metrics list with three failure-mode-to-metric sentences (latency regressions, memory drift, storage-layer issues)

- Misc: fix Bechmarks typo; tighten user_id backticking; swap filing-taxes/rollback example pair for insurance-claim/multi-step-checkout

Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
@cnuthalapati
Copy link
Copy Markdown
Contributor Author

Pushed e9220fc addressing reviewer threads in this round:

  • Memory categorization: renamed "local vs external" throughout to "file-based context vs store-backed memory layer"; added a naming sentence so the two categories are explicit before examples.
  • Session memory: grounded as the classic Valkey session-store pattern applied to conversation state.
  • Long-running agents: replaced "highlights the need" with a concrete Anthropic quote and dropped the weaker OpenAI running-agents link.
  • Mem0 "memory" terminology: defined as a named unit on first use; renamed pre-decision "candidate memory" to just "candidate" to avoid collision with Valkey's memory sense; removed "hash-backed document" jargon.
  • Index schema: trimmed to fields the prose actually explains; fixed the mislabel that called created_at / updated_at metadata attributes.
  • Write path: linked FT.SEARCH and HSET; noted that HSET updates the index in place so writes are immediately searchable.
  • Scoped ownership: added a closing tradeoff sentence contrasting TAG attributes vs namespaced keys; backticked the namespace tuples.
  • Section 2 framing: replaced "if writes are slow ..." with the explicit forced-tradeoff framing and tied Valkey's short update latency directly to resolving it.
  • Section 3: replaced the microsecond / multi-million claim with the canonical "single-digit millisecond latency and over 99% recall at billions of vectors", linked to valkey.io/topics/search/.
  • Section 4: linked EXPIRE, TTL, PERSIST, UNLINK, HEXPIRE, HTTL to their Valkey command docs.
  • Concurrency pattern: backticked and linked SET and INCR.
  • Observability: replaced the long metrics list with three failure-mode-to-metric sentences (latency regressions, memory drift, storage-layer issues).
  • Misc: fixed the "Bechmarks" typo; tightened user_id backticking; swapped the "filing taxes / rollback step" example pair for consistent user-facing workflows (insurance claim / multi-step checkout).

Signed-off-by: Chaitanya Nuthalapati cnu@amazon.com

- Update date to 2026-05-05 and remove time
- Add grading rubric paragraph before the comparison table
- Adjust labels: upgraded pgvector Resume/handoff to Best fit, pgvector High-throughput to Strong fit, OpenSearch Resume/handoff to Strong fit
- Swap all 12 citations for more specific sources and anchor text

Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Copy link
Copy Markdown
Contributor Author

@cnuthalapati cnuthalapati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all comments from Kyle, Madelyn and Allen

Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-04-30-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
@cnuthalapati
Copy link
Copy Markdown
Contributor Author

Thanks Kyle. Addressed all of your top-level points:

I have defined "memory" and created bridges explicitly so readers don't need prior Mem0 familiarity. The audience is developers building AI agents that are looking to implement an agent memory layer.

  1. Open source: the mem0 code uses open-source strands + mem0 and runs on any Valkey endpoint, clarified in the line-24 thread.
  2. Bolding: removed most in-paragraph bold, kept only for memory-type labels and production-pattern sub-headings.
  3. Laundry lists: rewrote the dense enumeration sentences into more encompassing framing.
  4. Inline code / caps / quotes: commands and field names backticked and linked throughout for consistency.
  5. Added a rubric to the comparison table defining Best fit / Strong fit / Supported, and swapped all 12 citations for more specific sources.

Please Take Another Look.

Copy link
Copy Markdown
Contributor Author

@cnuthalapati cnuthalapati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all comments addressed

Copy link
Copy Markdown
Contributor

@makubo-aws makubo-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great. Two small call outs

Comment thread content/blog/2026-05-05-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
Comment thread content/blog/2026-05-05-ai-agent-memory-with-valkey-and-mem0/index.md Outdated
- Replace soft LLM stateless opener with value-first hook (90% token cut, sub-2s responses per Mem0 benchmarks)
- Compress second paragraph into the post roadmap
- Rename "Valkey vs Other Open Source Solutions" to "Open Source Storage Options: A Side-by-Side"

Signed-off-by: Chaitanya Nuthalapati <cnu@amazon.com>
Copy link
Copy Markdown
Contributor Author

@cnuthalapati cnuthalapati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved the intro para and reframed the section title

Copy link
Copy Markdown
Contributor

@makubo-aws makubo-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants