[Doc] Introduce Mem0 based Long-Term Memory - #637
Conversation
6664d89 to
67e8693
Compare
|
@wenjin272 PTAL, thanks! |
There was a problem hiding this comment.
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 | ||
| ``` |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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`: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
I think the Best Practices and Limitations section is not necessary.
| @@ -0,0 +1,434 @@ | |||
| --- | |||
| title: Mem0-based Long-Term Memory | |||
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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:
- Provide an introduction to Flink-Agents Long-Term Memory.
- Explain that Long-Term Memory currently supports only the mem0 backend, and give a brief overview of how mem0 works.
|
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
67e8693 to
b00a1d2
Compare
wenjin272
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Shall we move this section to Operaions? Introducing operation-level content after the sections on Usage in Agent and Context Isolation feels somewhat unnatural.
There was a problem hiding this comment.
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
b00a1d2 to
cd59350
Compare
What is the purpose of the change
Add documentation for Mem0-based Long-Term Memory integration, as described in #621.
Brief change log
docs/content/docs/development/memory/mem0_long_term_memory.mdMem0LongTermMemoryimplementation example (extendingBaseLongTermMemory)Does this pull request potentially affect one of the following parts
Documentation