Skip to content

Commit 26e3327

Browse files
Update logic
Signed-off-by: Andy Kwok <[email protected]>
1 parent f7ca992 commit 26e3327

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/strands_tools/mem0_memory.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,14 @@ def _initialize_client(self, config: Optional[Dict] = None) -> Any:
191191
logger.debug("Using Mem0 Platform backend (MemoryClient)")
192192
return MemoryClient()
193193

194+
195+
196+
# Vector search providers
194197
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER_VECTOR") and os.environ.get("OPENSEARCH_HOST"):
195198
raise RuntimeError("""Conflicting backend configurations:
196199
Both NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER_VECTOR and OPENSEARCH_HOST environment variables are set.
197200
Please specify only one backend.""")
198-
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER") and os.environ.get("NEPTUNE_DATABASE_ENDPOINT"):
199-
raise RuntimeError("""Conflicting backend configurations:
200-
Both NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER and NEPTUNE_DATABASE_ENDPOINT environment variables are set.
201-
Please specify only one graph backend.""")
202-
203-
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER"):
204-
logger.debug("Using Neptune Analytics graph backend (Mem0Memory with Neptune Analytics)")
205-
config = self._configure_neptune_analytics_backend(config)
206-
elif os.environ.get("NEPTUNE_DATABASE_ENDPOINT"):
207-
logger.debug("Using Neptune Database graph backend (Mem0Memory with Neptune Database)")
208-
config = self._configure_neptune_backend(config)
209201

210-
# Vector search providers
211202
if os.environ.get("OPENSEARCH_HOST"):
212203
logger.debug("Using OpenSearch backend (Mem0Memory with OpenSearch)")
213204
merged_config = self._initialize_opensearch_client(config)
@@ -220,10 +211,21 @@ def _initialize_client(self, config: Optional[Dict] = None) -> Any:
220211
logger.debug("Using FAISS backend (Mem0Memory with FAISS)")
221212
merged_config = self._initialize_faiss_client(config)
222213

214+
215+
223216
# Graph backend providers
217+
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER") and os.environ.get("NEPTUNE_DATABASE_ENDPOINT"):
218+
raise RuntimeError("""Conflicting backend configurations:
219+
Both NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER and NEPTUNE_DATABASE_ENDPOINT environment variables are set.
220+
Please specify only one graph backend.""")
221+
224222
if os.environ.get("NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER"):
225223
logger.debug("Using Neptune Analytics graph backend (Mem0Memory with Neptune Analytics)")
226-
merged_config = self._configure_neptune_analytics_graph_backend(merged_config)
224+
config = self._configure_neptune_analytics_backend(config)
225+
elif os.environ.get("NEPTUNE_DATABASE_ENDPOINT"):
226+
logger.debug("Using Neptune Database graph backend (Mem0Memory with Neptune Database)")
227+
config = self._configure_neptune_backend(config)
228+
227229

228230
return Mem0Memory.from_config(config_dict=merged_config)
229231

tests/test_mem0.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ def test_mem0_service_client_init(mock_opensearch, mock_mem0_memory, mock_sessio
455455
client = Mem0ServiceClient()
456456
assert client.mem0 is not None
457457

458+
# Test with Neptune Database with OpenSearch
458459
with patch.dict(
459460
os.environ,
460461
{"OPENSEARCH_HOST": "test.opensearch.amazonaws.com",

0 commit comments

Comments
 (0)