Skip to content

Commit 06f0efd

Browse files
committed
feat: update SelfMemory memory provider with improved encryption handling and async item addition
1 parent ab4ac45 commit 06f0efd

5 files changed

Lines changed: 34 additions & 9 deletions

File tree

packages/nvidia_nat_selfmemory/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies = [
5656
# version when adding a new package. If unsure, default to using `~=` instead of `==`. Does not apply to nvidia-nat packages.
5757
# Keep sorted!!!
5858
"nvidia-nat-core == {version}",
59-
"selfmemory>=0.9.4",
59+
"selfmemory>=0.9.4,<2.0.0",
6060
]
6161

6262
[tool.setuptools_dynamic_dependencies.optional-dependencies]

packages/nvidia_nat_selfmemory/src/nat/meta/pypi.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
<!--
2+
SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
![NVIDIA NeMo Agent Toolkit](https://media.githubusercontent.com/media/NVIDIA/NeMo-Agent-Toolkit/refs/heads/main/docs/source/_static/banner.png "NeMo Agent Toolkit banner image")
19+
120
# nvidia-nat-selfmemory
221

322
SelfMemory memory provider plugin for the NVIDIA NeMo Agent Toolkit.

packages/nvidia_nat_selfmemory/src/nat/plugins/selfmemory/memory.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ async def selfmemory_provider(config: SelfMemoryProviderConfig, builder: Builder
5353
"config": config.llm_config,
5454
}
5555

56-
if config.encryption_key:
57-
os.environ.setdefault("MASTER_ENCRYPTION_KEY", config.encryption_key)
56+
encryption_key = config.encryption_key or os.environ.get("MASTER_ENCRYPTION_KEY")
5857

59-
memory = SelfMemory(config=config_dict)
58+
if encryption_key:
59+
os.environ["MASTER_ENCRYPTION_KEY"] = encryption_key
6060

61-
yield SelfMemoryEditor(memory)
61+
memory = SelfMemory(config=config_dict)
6262

63-
memory.close()
63+
try:
64+
yield SelfMemoryEditor(memory)
65+
finally:
66+
memory.close()

packages/nvidia_nat_selfmemory/src/nat/plugins/selfmemory/selfmemory_editor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ def __init__(self, backend: SelfMemory):
3636

3737
async def add_items(self, items: list[MemoryItem]) -> None:
3838
"""Insert multiple MemoryItems into SelfMemory."""
39-
for item in items:
40-
kwargs = memory_item_to_add_kwargs(item)
41-
await asyncio.to_thread(self._backend.add, **kwargs)
39+
coroutines = [
40+
asyncio.to_thread(self._backend.add, **memory_item_to_add_kwargs(item))
41+
for item in items
42+
]
43+
await asyncio.gather(*coroutines)
4244

4345
async def search(self, query: str, top_k: int = 5, **kwargs) -> list[MemoryItem]:
4446
"""Retrieve items relevant to the given query."""

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ openpipe-art = ["nvidia-nat-openpipe-art == {version}"]
6767
opentelemetry = ["nvidia-nat-opentelemetry == {version}"]
6868
phoenix = ["nvidia-nat-phoenix == {version}"]
6969
profiler = ["nvidia-nat-profiler == {version}"]
70+
selfmemory = ["nvidia-nat-selfmemory == {version}"]
7071
rag = ["nvidia-nat-rag == {version}"]
7172
ragas = ["nvidia-nat-ragas == {version}"]
7273
ragaai = ["nvidia-nat-ragaai == {version}"]

0 commit comments

Comments
 (0)