Skip to content

[Doc] Introduce Mem0 based Long-Term Memory - #637

Merged
wenjin272 merged 2 commits into
apache:mainfrom
matrixsparse:feature/mem0-long-term-memory-docs
May 11, 2026
Merged

[Doc] Introduce Mem0 based Long-Term Memory#637
wenjin272 merged 2 commits into
apache:mainfrom
matrixsparse:feature/mem0-long-term-memory-docs

Conversation

@matrixsparse

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Add documentation for Mem0-based Long-Term Memory integration, as described in #621.

Brief change log

  • Add docs/content/docs/development/memory/mem0_long_term_memory.md
    • Overview and prerequisites for Mem0 integration
    • Mem0LongTermMemory implementation example (extending BaseLongTermMemory)
    • Agent usage examples with correct Flink Agents Python API
    • Configuration options (vector store, LLM, embedder) and multi-provider support
    • Advanced features: multi-user isolation, memory categories, async operations
    • Best practices and known limitations

Does this pull request potentially affect one of the following parts

  • Dependencies
  • The public API
  • Integration tests
  • Documentation

Documentation

  • Does this pull request introduce a new feature? (yes, Mem0 LTM docs)
  • If yes, how is the feature documented? (docs)

@github-actions github-actions Bot added doc-label-missing The Bot applies this label either because none or multiple labels were provided. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue. labels Apr 20, 2026
@wenjin272 wenjin272 added doc-included Your PR already contains the necessary documentation updates. and removed doc-label-missing The Bot applies this label either because none or multiple labels were provided. labels Apr 21, 2026
@matrixsparse
matrixsparse force-pushed the feature/mem0-long-term-memory-docs branch from 6664d89 to 67e8693 Compare April 29, 2026 19:45
@matrixsparse

Copy link
Copy Markdown
Contributor Author

@wenjin272 PTAL, thanks!

@wenjin272 wenjin272 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, @matrixsparse, Ty for your work.

I believe the document itself is comprehensive and accurate; however, I think some content does not need to be exposed to users. Therefore, I mainly left comments suggesting the removal of certain parts.

Additionally, #647 has been merged. You can now attach Java sample code.

1. **Install Mem0 Python SDK**:
```bash
pip install mem0ai
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mem0ai is a dependency of flink-agents and will be installed automatically when install flink-agents, so there's no need to install it separately.

agents_config = env.get_config()

# Set job identifier (maps to Mem0 user_id)
agents_config.set(AgentConfigOptions.JOB_IDENTIFIER, "my_job")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be worth mentioning here that if the user does not configure it, the Flink job ID will be used by default.


### Getting a Memory Set

Unlike the VectorStore-based LTM, Mem0 does not require explicit `get_or_create_memory_set` with capacity and compaction config — simply call `get_memory_set`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, there is no need to mention VectorStore-based LTM here.


## Architecture

The integration uses a three-layer adapter pattern. `Mem0LongTermMemory` orchestrates a Mem0 `Memory` instance, and three adapters (`FlinkAgentsLLM`, `FlinkAgentsEmbedding`, `FlinkAgentsMem0VectorStore`) bridge Flink Agents resources (ChatModel, EmbeddingModel, VectorStore) to Mem0's factory system under the `flink_agents` provider. See [Adapter Mechanism](#adapter-mechanism-advanced) for details.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This document is primarily a user guide. Since these adapters are internal implementations of Mem0LongTermMemory, I do not think they need to be introduced to users.

Flink Agents provides built-in support for [Mem0](https://github.com/mem0ai/mem0) as a Long-Term Memory backend. Mem0 is an intelligent memory layer for AI agents that provides automatic memory extraction, consolidation, and semantic retrieval.

{{< hint info >}}
Mem0 replaces the previous VectorStore-based Long-Term Memory implementation since Flink Agents 0.3.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe there is no need to mention VectorStore-based LTM here, as flink-agents is still in beta and does not guarantee API compatibility. Additionally, VectorStore-based LTM has not been around for long and has no active users. Mentioning it might only increase the cognitive load for users.

memory_set.add(items=f"User said: {event.input}")

# Search — only returns memories for the current key
results = memory_set.search(query=event.input, limit=10)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is necessary to explain the importance of context isolation to users, but providing code examples may not be needed, as the code itself does not intuitively demonstrate this isolation.

The introduction to scope was already covered in the previous section on MemorySet; I suggest moving that explanation here.

4. **Monitor token usage**: Mem0 makes two LLM calls per `add` operation (fact extraction + memory update), which impacts cost
5. **Choose appropriate vector store**: Use Chroma for development, Elasticsearch/OpenSearch for production

## Limitations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the Best Practices and Limitations section is not necessary.

@@ -0,0 +1,434 @@
---
title: Mem0-based Long-Term Memory

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can just replace the original Long-Term Memory section rather than add a new section. Since the content in Long-Term Memory section is invalid.

Even if we support backends other than mem0 in the future, I believe the API and functionality of Long-Term Memory will remain unchanged. We only need to document the configuration methods and characteristics of each backend within the Long-Term Memory section.


## Overview

Flink Agents provides built-in support for [Mem0](https://github.com/mem0ai/mem0) as a Long-Term Memory backend. Mem0 is an intelligent memory layer for AI agents that provides automatic memory extraction, consolidation, and semantic retrieval.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After we move the content of this document to the original Long-Term Memory section, the Overview section can be consolidated. My proposal is as follows:

  1. Provide an introduction to Flink-Agents Long-Term Memory.

  2. Explain that Long-Term Memory currently supports only the mem0 backend, and give a brief overview of how mem0 works.

@matrixsparse

Copy link
Copy Markdown
Contributor Author

Thanks! Will remove the flagged sections and add Java sample code.

Add documentation for integrating Mem0 as a Long-Term Memory backend
in Flink Agents, including:
- Mem0 overview, concepts, and prerequisites
- BaseLongTermMemory implementation example
- Agent usage examples with correct API
- Configuration options for multiple LLM providers
- Multi-user memory management and async operations
- Best practices and limitations

Closes apache#621
@matrixsparse
matrixsparse force-pushed the feature/mem0-long-term-memory-docs branch from 67e8693 to b00a1d2 Compare May 8, 2026 21:11

@wenjin272 wenjin272 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good to me, just one comment. PTAL @xintongsong.

{{< tabs "Compaction Config" >}}
This means you can safely use the same memory set name across different partitions — each partition will only access its own memories.

## Metadata Filtering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we move this section to Operaions? Introducing operation-level content after the sections on Usage in Agent and Context Isolation feels somewhat unnatural.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved "Metadata Filtering" into the Operations section as a subsection.

- Consolidate mem0_long_term_memory.md into long_term_memory.md
- Remove Architecture, Best Practices, Limitations sections
- Remove pip install instruction (mem0ai is auto-installed)
- Add JOB_IDENTIFIER default behavior hint
- Move scope explanation to Context Isolation section
- Add Java code examples based on PR apache#647
- Fix @action/@action usage to match framework convention
- Use Event base type with fromEvent()/from_event() pattern
@matrixsparse
matrixsparse force-pushed the feature/mem0-long-term-memory-docs branch from b00a1d2 to cd59350 Compare May 9, 2026 12:12

@wenjin272 wenjin272 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@wenjin272
wenjin272 merged commit df89798 into apache:main May 11, 2026
45 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-included Your PR already contains the necessary documentation updates. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants