-
Notifications
You must be signed in to change notification settings - Fork 0
Migrates the current redis package from NAT repo to this repo #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f12638
migrates the current redis package from NAT repo to this repo
justin-cechmanek 3b7be1d
replaces call to keys() with scan_iter()
justin-cechmanek e7a613e
adds more descriptive text to configuration.md
justin-cechmanek c34e334
replaces Agent Memory Server references with Redis Agent Memory
justin-cechmanek c3204a0
updates README
justin-cechmanek f1a833f
removes refs to older nvidia-nat-redis to prevent confusion
justin-cechmanek 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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,16 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, 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. | ||
|
|
||
| """Direct Redis memory and object-store NAT components (NeMo ``nat.plugins.redis`` layout).""" |
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,60 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, 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. | ||
|
|
||
| from nat.builder.builder import Builder | ||
| from nat.cli.register_workflow import register_memory | ||
| from nat.data_models.common import OptionalSecretStr, get_secret_value | ||
| from nat.data_models.component_ref import EmbedderRef | ||
| from nat.data_models.memory import MemoryBaseConfig | ||
| from pydantic import Field | ||
|
|
||
|
|
||
| class RedisMemoryClientConfig(MemoryBaseConfig, name="redis_memory"): | ||
| host: str = Field(default="localhost", description="Redis server host") | ||
| db: int = Field(default=0, description="Redis DB") | ||
| port: int = Field(default=6379, description="Redis server port") | ||
| password: OptionalSecretStr = Field(default=None, description="Password for the Redis server") | ||
| key_prefix: str = Field(default="nat", description="Key prefix to use for redis keys") | ||
| embedder: EmbedderRef = Field(description=("Instance name of the memory client instance from the workflow " | ||
| "configuration object.")) | ||
|
|
||
|
|
||
| @register_memory(config_type=RedisMemoryClientConfig) | ||
| async def redis_memory_client(config: RedisMemoryClientConfig, builder: Builder): | ||
|
|
||
| from nat.builder.framework_enum import LLMFrameworkEnum | ||
|
|
||
| import redis.asyncio as redis | ||
|
|
||
| from .redis_editor import RedisEditor | ||
| from .schema import ensure_index_exists | ||
|
|
||
| redis_client = redis.Redis(host=config.host, | ||
| port=config.port, | ||
| db=config.db, | ||
| password=get_secret_value(config.password), | ||
| decode_responses=True, | ||
| socket_timeout=5.0, | ||
| socket_connect_timeout=5.0) | ||
|
|
||
| embedder = await builder.get_embedder(config.embedder, wrapper_type=LLMFrameworkEnum.LANGCHAIN) | ||
|
|
||
| test_embedding = await embedder.aembed_query("test") | ||
| embedding_dim = len(test_embedding) | ||
| await ensure_index_exists(client=redis_client, key_prefix=config.key_prefix, embedding_dim=embedding_dim) | ||
|
|
||
| memory_editor = RedisEditor(redis_client=redis_client, key_prefix=config.key_prefix, embedder=embedder) | ||
|
|
||
| yield memory_editor | ||
|
justin-cechmanek marked this conversation as resolved.
|
||
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,49 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, 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. | ||
|
|
||
| from nat.builder.builder import Builder | ||
| from nat.cli.register_workflow import register_object_store | ||
| from nat.data_models.common import OptionalSecretStr | ||
| from nat.data_models.object_store import ObjectStoreBaseConfig | ||
| from pydantic import Field, field_validator | ||
|
|
||
|
|
||
| class RedisObjectStoreClientConfig(ObjectStoreBaseConfig, name="redis"): | ||
| """ | ||
| Object store that stores objects in a Redis database with optional TTL. | ||
| """ | ||
|
|
||
| host: str = Field(default="localhost", description="The host of the Redis server") | ||
| db: int = Field(default=0, description="The Redis logical database number") | ||
| port: int = Field(default=6379, description="The port of the Redis server") | ||
| bucket_name: str = Field(description="The name of the bucket to use for the object store") | ||
| password: OptionalSecretStr = Field(default=None, description="The password for the Redis server") | ||
| ttl: int | None = Field(default=None, description="TTL in seconds for objects (None = no expiration)") | ||
|
|
||
| @field_validator("ttl") | ||
| @classmethod | ||
| def validate_ttl(cls, v: int | None) -> int | None: | ||
| if v is not None and v <= 0: | ||
| raise ValueError("TTL must be a positive integer greater than 0") | ||
| return v | ||
|
|
||
|
|
||
| @register_object_store(config_type=RedisObjectStoreClientConfig) | ||
| async def redis_object_store_client(config: RedisObjectStoreClientConfig, _builder: Builder): | ||
|
|
||
| from .redis_object_store import RedisObjectStore | ||
|
|
||
| async with RedisObjectStore(**config.model_dump(exclude={"type"})) as store: | ||
|
|
||
| yield store | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.