nvidia-nat-redis 1.3.0a20250827__py3-none-any.whl → 1.3.0a20250828__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nat/plugins/redis/memory.py +7 -6
- nat/plugins/redis/object_store.py +40 -0
- nat/plugins/redis/redis_object_store.py +126 -0
- nat/plugins/redis/register.py +1 -0
- {nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/METADATA +2 -2
- nvidia_nat_redis-1.3.0a20250828.dist-info/RECORD +13 -0
- nvidia_nat_redis-1.3.0a20250827.dist-info/RECORD +0 -11
- {nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/WHEEL +0 -0
- {nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/entry_points.txt +0 -0
- {nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/top_level.txt +0 -0
nat/plugins/redis/memory.py
CHANGED
@@ -13,21 +13,19 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
import redis.asyncio as redis
|
17
16
|
from pydantic import Field
|
18
17
|
|
19
18
|
from nat.builder.builder import Builder
|
20
|
-
from nat.builder.framework_enum import LLMFrameworkEnum
|
21
19
|
from nat.cli.register_workflow import register_memory
|
22
20
|
from nat.data_models.component_ref import EmbedderRef
|
23
21
|
from nat.data_models.memory import MemoryBaseConfig
|
24
22
|
|
25
23
|
|
26
24
|
class RedisMemoryClientConfig(MemoryBaseConfig, name="redis_memory"):
|
27
|
-
host: str
|
28
|
-
db:
|
29
|
-
port:
|
30
|
-
key_prefix: str
|
25
|
+
host: str = Field(default="localhost", description="Redis server host")
|
26
|
+
db: int = Field(default=0, description="Redis DB")
|
27
|
+
port: int = Field(default=6379, description="Redis server port")
|
28
|
+
key_prefix: str = Field(default="nat", description="Key prefix to use for redis keys")
|
31
29
|
embedder: EmbedderRef = Field(description=("Instance name of the memory client instance from the workflow "
|
32
30
|
"configuration object."))
|
33
31
|
|
@@ -35,6 +33,9 @@ class RedisMemoryClientConfig(MemoryBaseConfig, name="redis_memory"):
|
|
35
33
|
@register_memory(config_type=RedisMemoryClientConfig)
|
36
34
|
async def redis_memory_client(config: RedisMemoryClientConfig, builder: Builder):
|
37
35
|
|
36
|
+
import redis.asyncio as redis
|
37
|
+
|
38
|
+
from nat.builder.framework_enum import LLMFrameworkEnum
|
38
39
|
from nat.plugins.redis.redis_editor import RedisEditor
|
39
40
|
|
40
41
|
from .schema import ensure_index_exists
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from pydantic import Field
|
17
|
+
|
18
|
+
from nat.builder.builder import Builder
|
19
|
+
from nat.cli.register_workflow import register_object_store
|
20
|
+
from nat.data_models.object_store import ObjectStoreBaseConfig
|
21
|
+
|
22
|
+
|
23
|
+
class RedisObjectStoreClientConfig(ObjectStoreBaseConfig, name="redis"):
|
24
|
+
"""
|
25
|
+
Object store that stores objects in a Redis database.
|
26
|
+
"""
|
27
|
+
|
28
|
+
host: str = Field(default="localhost", description="The host of the Redis server")
|
29
|
+
db: int = Field(default=0, description="The Redis logical database number")
|
30
|
+
port: int = Field(default=6379, description="The port of the Redis server")
|
31
|
+
bucket_name: str = Field(description="The name of the bucket to use for the object store")
|
32
|
+
|
33
|
+
|
34
|
+
@register_object_store(config_type=RedisObjectStoreClientConfig)
|
35
|
+
async def redis_object_store_client(config: RedisObjectStoreClientConfig, _builder: Builder):
|
36
|
+
|
37
|
+
from .redis_object_store import RedisObjectStore
|
38
|
+
|
39
|
+
async with RedisObjectStore(**config.model_dump(exclude={"type"})) as store:
|
40
|
+
yield store
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
import logging
|
17
|
+
|
18
|
+
import redis.asyncio as redis
|
19
|
+
|
20
|
+
from nat.data_models.object_store import KeyAlreadyExistsError
|
21
|
+
from nat.data_models.object_store import NoSuchKeyError
|
22
|
+
from nat.object_store.interfaces import ObjectStore
|
23
|
+
from nat.object_store.models import ObjectStoreItem
|
24
|
+
from nat.utils.type_utils import override
|
25
|
+
|
26
|
+
logger = logging.getLogger(__name__)
|
27
|
+
|
28
|
+
|
29
|
+
class RedisObjectStore(ObjectStore):
|
30
|
+
"""
|
31
|
+
Implementation of ObjectStore that stores objects in Redis.
|
32
|
+
|
33
|
+
Each object is stored as a single binary value at key "nat/object_store/{bucket_name}/{object_key}".
|
34
|
+
"""
|
35
|
+
|
36
|
+
def __init__(self, *, bucket_name: str, host: str, port: int, db: int):
|
37
|
+
|
38
|
+
super().__init__()
|
39
|
+
|
40
|
+
self._bucket_name = bucket_name
|
41
|
+
self._host = host
|
42
|
+
self._port = port
|
43
|
+
self._db = db
|
44
|
+
self._client: redis.Redis | None = None
|
45
|
+
|
46
|
+
async def __aenter__(self) -> "RedisObjectStore":
|
47
|
+
|
48
|
+
if self._client is not None:
|
49
|
+
raise RuntimeError("Connection already established")
|
50
|
+
|
51
|
+
self._client = redis.Redis(
|
52
|
+
host=self._host,
|
53
|
+
port=self._port,
|
54
|
+
db=self._db,
|
55
|
+
socket_timeout=5.0,
|
56
|
+
socket_connect_timeout=5.0,
|
57
|
+
)
|
58
|
+
|
59
|
+
# Ping to ensure connectivity
|
60
|
+
res = await self._client.ping()
|
61
|
+
if not res:
|
62
|
+
raise RuntimeError("Failed to connect to Redis")
|
63
|
+
|
64
|
+
logger.info("Connected Redis client for %s at %s:%s/%s", self._bucket_name, self._host, self._port, self._db)
|
65
|
+
|
66
|
+
return self
|
67
|
+
|
68
|
+
async def __aexit__(self, exc_type, exc_value, traceback) -> None:
|
69
|
+
|
70
|
+
if not self._client:
|
71
|
+
raise RuntimeError("Connection not established")
|
72
|
+
|
73
|
+
await self._client.close()
|
74
|
+
self._client = None
|
75
|
+
|
76
|
+
def _make_key(self, key: str) -> str:
|
77
|
+
return f"nat/object_store/{self._bucket_name}/{key}"
|
78
|
+
|
79
|
+
@override
|
80
|
+
async def put_object(self, key: str, item: ObjectStoreItem):
|
81
|
+
|
82
|
+
if not self._client:
|
83
|
+
raise RuntimeError("Connection not established")
|
84
|
+
|
85
|
+
full_key = self._make_key(key)
|
86
|
+
|
87
|
+
item_json = item.model_dump_json()
|
88
|
+
# Redis SET with NX ensures we do not overwrite existing keys
|
89
|
+
if not await self._client.set(full_key, item_json, nx=True):
|
90
|
+
raise KeyAlreadyExistsError(key=key,
|
91
|
+
additional_message=f"Redis bucket {self._bucket_name} already has key {key}")
|
92
|
+
|
93
|
+
@override
|
94
|
+
async def upsert_object(self, key: str, item: ObjectStoreItem):
|
95
|
+
|
96
|
+
if not self._client:
|
97
|
+
raise RuntimeError("Connection not established")
|
98
|
+
|
99
|
+
full_key = self._make_key(key)
|
100
|
+
item_json = item.model_dump_json()
|
101
|
+
await self._client.set(full_key, item_json)
|
102
|
+
|
103
|
+
@override
|
104
|
+
async def get_object(self, key: str) -> ObjectStoreItem:
|
105
|
+
|
106
|
+
if not self._client:
|
107
|
+
raise RuntimeError("Connection not established")
|
108
|
+
|
109
|
+
full_key = self._make_key(key)
|
110
|
+
data = await self._client.get(full_key)
|
111
|
+
if data is None:
|
112
|
+
raise NoSuchKeyError(key=key,
|
113
|
+
additional_message=f"Redis bucket {self._bucket_name} does not have key {key}")
|
114
|
+
return ObjectStoreItem.model_validate_json(data)
|
115
|
+
|
116
|
+
@override
|
117
|
+
async def delete_object(self, key: str):
|
118
|
+
|
119
|
+
if not self._client:
|
120
|
+
raise RuntimeError("Connection not established")
|
121
|
+
|
122
|
+
full_key = self._make_key(key)
|
123
|
+
deleted = await self._client.delete(full_key)
|
124
|
+
if deleted == 0:
|
125
|
+
raise NoSuchKeyError(key=key,
|
126
|
+
additional_message=f"Redis bucket {self._bucket_name} does not have key {key}")
|
nat/plugins/redis/register.py
CHANGED
{nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/METADATA
RENAMED
@@ -1,12 +1,12 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nvidia-nat-redis
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.0a20250828
|
4
4
|
Summary: Subpackage for Redis integration in NeMo Agent toolkit
|
5
5
|
Keywords: ai,agents,memory
|
6
6
|
Classifier: Programming Language :: Python
|
7
7
|
Requires-Python: <3.13,>=3.11
|
8
8
|
Description-Content-Type: text/markdown
|
9
|
-
Requires-Dist: nvidia-nat==v1.3.
|
9
|
+
Requires-Dist: nvidia-nat==v1.3.0a20250828
|
10
10
|
Requires-Dist: redis~=4.3.4
|
11
11
|
|
12
12
|
<!--
|
@@ -0,0 +1,13 @@
|
|
1
|
+
nat/meta/pypi.md,sha256=TpeNbVZJxzvEf0Gh3BGvLHPYsKnXjgM_KQVCayBPXso,1090
|
2
|
+
nat/plugins/redis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
nat/plugins/redis/memory.py,sha256=wqj_UYqnllc4kTCtFDz3eu-OZnyPWXxNZ3e6G992OGQ,2546
|
4
|
+
nat/plugins/redis/object_store.py,sha256=f_GtCTZ3KHfxE4f0lAzKaoAoInAZZki4Dfo7hrKCAHA,1681
|
5
|
+
nat/plugins/redis/redis_editor.py,sha256=BskJN5R0h1xzz7w5Ic8IVvd4z-qdBp9ZBIpGYNiSwE8,10080
|
6
|
+
nat/plugins/redis/redis_object_store.py,sha256=DX46GEQl4H1Ivf2wrRaSimNcq6EfvRsm-xhyiECudoQ,4302
|
7
|
+
nat/plugins/redis/register.py,sha256=dJBKi-7W72ipkmZTOIo1E3ETffmJIlYhQTOlrkiFH3A,834
|
8
|
+
nat/plugins/redis/schema.py,sha256=lcazZKzWEoJEJmGEt6rk135zJ6kGqw6v2b1B5l1xg7o,5494
|
9
|
+
nvidia_nat_redis-1.3.0a20250828.dist-info/METADATA,sha256=pKeK9u7-KKFMn3oiGknZ8_QLPNK9yJFn_EqklMMR2rw,1435
|
10
|
+
nvidia_nat_redis-1.3.0a20250828.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
nvidia_nat_redis-1.3.0a20250828.dist-info/entry_points.txt,sha256=nyS8t8L9CbRFIMlE70RQBtJXrflBP4Ltl5zAkIl44So,56
|
12
|
+
nvidia_nat_redis-1.3.0a20250828.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
13
|
+
nvidia_nat_redis-1.3.0a20250828.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
nat/meta/pypi.md,sha256=TpeNbVZJxzvEf0Gh3BGvLHPYsKnXjgM_KQVCayBPXso,1090
|
2
|
-
nat/plugins/redis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
nat/plugins/redis/memory.py,sha256=2AbG29r6tul4RVvGnSVrQnT96Hvm725i1X23zvDGWTg,2569
|
4
|
-
nat/plugins/redis/redis_editor.py,sha256=BskJN5R0h1xzz7w5Ic8IVvd4z-qdBp9ZBIpGYNiSwE8,10080
|
5
|
-
nat/plugins/redis/register.py,sha256=n5QJ6VHpLSV4j9WJEc7IgvWHbSyfy8KYeE9XKz4NZxo,807
|
6
|
-
nat/plugins/redis/schema.py,sha256=lcazZKzWEoJEJmGEt6rk135zJ6kGqw6v2b1B5l1xg7o,5494
|
7
|
-
nvidia_nat_redis-1.3.0a20250827.dist-info/METADATA,sha256=wVW_vpHo4X3rP78jmu2o_Wr_4ChjBxnsOLW_mO3Q7RQ,1435
|
8
|
-
nvidia_nat_redis-1.3.0a20250827.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
-
nvidia_nat_redis-1.3.0a20250827.dist-info/entry_points.txt,sha256=nyS8t8L9CbRFIMlE70RQBtJXrflBP4Ltl5zAkIl44So,56
|
10
|
-
nvidia_nat_redis-1.3.0a20250827.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
11
|
-
nvidia_nat_redis-1.3.0a20250827.dist-info/RECORD,,
|
{nvidia_nat_redis-1.3.0a20250827.dist-info → nvidia_nat_redis-1.3.0a20250828.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|