Skip to content

Commit bc1aaff

Browse files
feat: Add optional Neptune Analytics graph backend for mem0_memory tool (#230)
--------- Signed-off-by: Andy Kwok <[email protected]>
1 parent 657b2a7 commit bc1aaff

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,25 @@ The Mem0 Memory Tool supports three different backend configurations:
828828
- Uses FAISS as the local vector store backend
829829
- Requires faiss-cpu package for local vector storage
830830

831+
4. **Neptune Analytics** (Optional Graph backend for search enhancement):
832+
- Uses Neptune Analytics as the graph store backend to enhance memory recall.
833+
- Requires AWS credentials and Neptune Analytics configuration
834+
```
835+
# Configure your Neptune Analytics graph ID in the .env file:
836+
export NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER=sample-graph-id
837+
838+
# Configure your Neptune Analytics graph ID in Python code:
839+
import os
840+
os.environ['NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER'] = "g-sample-graph-id"
841+
842+
```
843+
831844
| Environment Variable | Description | Default | Required For |
832845
|----------------------|-------------|---------|--------------|
833846
| MEM0_API_KEY | Mem0 Platform API key | None | Mem0 Platform |
834847
| OPENSEARCH_HOST | OpenSearch Host URL | None | OpenSearch |
835848
| AWS_REGION | AWS Region for OpenSearch | us-west-2 | OpenSearch |
849+
| NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER | Neptune Analytics Graph Identifier | None | Neptune Analytics |
836850
| DEV | Enable development mode (bypasses confirmations) | false | All modes |
837851
| MEM0_LLM_PROVIDER | LLM provider for memory processing | aws_bedrock | All modes |
838852
| MEM0_LLM_MODEL | LLM model for memory processing | anthropic.claude-3-5-haiku-20241022-v1:0 | All modes |
@@ -846,6 +860,7 @@ The Mem0 Memory Tool supports three different backend configurations:
846860
- If `MEM0_API_KEY` is set, the tool will use the Mem0 Platform
847861
- If `OPENSEARCH_HOST` is set, the tool will use OpenSearch
848862
- If neither is set, the tool will default to FAISS (requires `faiss-cpu` package)
863+
- If `NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER` is set, the tool will configure Neptune Analytics as graph store to enhance memory search
849864
- LLM configuration applies to all backend modes and allows customization of the language model used for memory processing
850865

851866
#### Bright Data Tool

src/strands_tools/mem0_memory.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,33 @@ def _initialize_client(self, config: Optional[Dict] = None) -> Any:
204204
logger.debug("Using Mem0 Platform backend (MemoryClient)")
205205
return MemoryClient()
206206

207+
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER"):
208+
logger.debug("Using Neptune Analytics graph backend (Mem0Memory with Neptune Analytics)")
209+
config = self._configure_neptune_analytics_backend(config)
210+
207211
if os.environ.get("OPENSEARCH_HOST"):
208212
logger.debug("Using OpenSearch backend (Mem0Memory with OpenSearch)")
209213
return self._initialize_opensearch_client(config)
210214

211215
logger.debug("Using FAISS backend (Mem0Memory with FAISS)")
212216
return self._initialize_faiss_client(config)
213217

218+
def _configure_neptune_analytics_backend(self, config: Optional[Dict] = None) -> Dict:
219+
"""Initialize a Mem0 client with Neptune Analytics graph backend.
220+
221+
Args:
222+
config: Optional configuration dictionary to override defaults.
223+
224+
Returns:
225+
An configuration dict with graph backend.
226+
"""
227+
config = config or {}
228+
config["graph_store"] = {
229+
"provider": "neptune",
230+
"config": {"endpoint": f"neptune-graph://{os.environ.get('NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER')}"},
231+
}
232+
return config
233+
214234
def _initialize_opensearch_client(self, config: Optional[Dict] = None) -> Mem0Memory:
215235
"""Initialize a Mem0 client with OpenSearch backend.
216236

tests/test_mem0.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,15 @@ def test_mem0_service_client_init(mock_opensearch, mock_mem0_memory, mock_sessio
424424
client = Mem0ServiceClient()
425425
assert client.region == os.environ.get("AWS_REGION", "us-west-2")
426426

427+
# Test with optional Graph backend
428+
with patch.dict(
429+
os.environ,
430+
{"OPENSEARCH_HOST": "test.opensearch.amazonaws.com", "NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER": "g-5aaaaa1234"},
431+
):
432+
client = Mem0ServiceClient()
433+
assert client.region == os.environ.get("AWS_REGION", "us-west-2")
434+
assert client.mem0 is not None
435+
427436
# Test with custom config (OpenSearch)
428437
custom_config = {
429438
"embedder": {"provider": "custom", "config": {"model": "custom-model"}},

0 commit comments

Comments
 (0)