-
Notifications
You must be signed in to change notification settings - Fork 376
Fix Mem0 plugin to work with v2 API + add mem0 Open Source option #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeremykpark
wants to merge
2
commits into
NVIDIA:develop
Choose a base branch
from
jeremykpark:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/aiqtoolkit_mem0ai/src/aiq/plugins/mem0ai/memory_local_ollama.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# This file is a part of the Nvidia AIQ Toolkit project, Mem0 Plugin | ||
# as a way of integrating lcoal Mem0 with local Ollama, and vector db instances. | ||
|
||
from aiq.builder.builder import Builder | ||
from aiq.cli.register_workflow import register_memory | ||
from aiq.data_models.memory import MemoryBaseConfig | ||
|
||
|
||
class Mem0LocalMemoryClientConfig(MemoryBaseConfig, name="mem0_memory_local_ollama"): | ||
""" | ||
Mem0 Memory Client Configuration. Setup for use with local Ollama instaces. | ||
""" | ||
# Defaults are set to work with Ollama and Milvus local instances with a local Mem0 instance | ||
# change them according to your local setup or override them in your workflow config file | ||
vec_store_provider: str = "milvus" # Change to "qdrant" if you prefer that | ||
vec_store_collection_name: str = "DefaultAIQCollectionNew" | ||
vec_store_url: str = "http://localhost:19530" # Default Local Milvus URL, change if needed | ||
vec_store_embedding_model_dims: int = 1024 # Updated to match the actual embedding dimensions | ||
llm_provider: str = "ollama" | ||
llm_model: str = "aliafshar/gemma3-it-qat-tools:27b" # Change to your preferred model | ||
llm_temperature: float = 0.0 | ||
llm_max_tokens: int = 2000 | ||
llm_base_url: str = "http://localhost:11434" # Default Ollama URL, change if needed | ||
embedder_provider: str = "ollama" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also wondering we can we use the |
||
embedder_model: str = "snowflake-arctic-embed2:latest" | ||
embedder_base_url: str = "http://localhost:11434" # Default Ollama URL, change if needed | ||
|
||
|
||
@register_memory(config_type=Mem0LocalMemoryClientConfig) | ||
async def mem0_memory_client(config: Mem0LocalMemoryClientConfig, builder: Builder): | ||
# UPDATED: Import AsyncMemory for v2 API compatibility | ||
from mem0 import AsyncMemory | ||
|
||
from aiq.plugins.mem0ai.mem0_editor import Mem0Editor | ||
|
||
# UPDATED: Create configuration dictionary for AsyncMemory | ||
# This includes all the necessary configuration for the local embedder, LLM, and vector store | ||
config_dict = { | ||
"vector_store": { | ||
"provider": config.vec_store_provider, | ||
"config": { | ||
"collection_name": config.vec_store_collection_name, | ||
"url": config.vec_store_url, | ||
"embedding_model_dims": config.vec_store_embedding_model_dims, | ||
}, | ||
}, | ||
"llm": { | ||
"provider": config.llm_provider, | ||
"config": { | ||
"model": config.llm_model, | ||
"temperature": config.llm_temperature, | ||
"max_tokens": config.llm_max_tokens, | ||
"ollama_base_url": config.llm_base_url, | ||
}, | ||
}, | ||
"embedder": { | ||
"provider": config.embedder_provider, | ||
"config": { | ||
"model": config.embedder_model, | ||
"ollama_base_url": config.embedder_base_url, | ||
}, | ||
}, | ||
} | ||
|
||
# UPDATED: Initialize AsyncMemory with the configuration | ||
# This is compatible with the v2 API and the updated mem0_editor.py | ||
# Use from_config to create an AsyncMemory instance from a dictionary | ||
mem0_client = await AsyncMemory.from_config(config_dict) | ||
|
||
memory_editor = Mem0Editor(mem0_client=mem0_client) | ||
|
||
yield memory_editor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would these work only for
Ollama
models? I'm wondering if we can abstract this further to use any LLM provider supported by the NeMo Agent Toolkit.