diff --git a/lightrag/kg/memgraph_impl.py b/lightrag/kg/memgraph_impl.py index 07b12c29..18ff4cd9 100644 --- a/lightrag/kg/memgraph_impl.py +++ b/lightrag/kg/memgraph_impl.py @@ -36,10 +36,8 @@ class MemgraphStorage(BaseGraphStorage): def __init__(self, namespace, global_config, embedding_func, workspace=None): # Priority: 1) MEMGRAPH_WORKSPACE env 2) user arg 3) default 'base' memgraph_workspace = os.environ.get("MEMGRAPH_WORKSPACE") + original_workspace = workspace # Save original value for logging if memgraph_workspace and memgraph_workspace.strip(): - logger.info( - f"Using MEMGRAPH_WORKSPACE environment variable: '{memgraph_workspace}' (overriding '{self.workspace}/{self.namespace}')" - ) workspace = memgraph_workspace if not workspace or not str(workspace).strip(): @@ -51,6 +49,13 @@ class MemgraphStorage(BaseGraphStorage): global_config=global_config, embedding_func=embedding_func, ) + + # Log after super().__init__() to ensure self.workspace is initialized + if memgraph_workspace and memgraph_workspace.strip(): + logger.info( + f"Using MEMGRAPH_WORKSPACE environment variable: '{memgraph_workspace}' (overriding '{original_workspace}/{namespace}')" + ) + self._driver = None def _get_workspace_label(self) -> str: diff --git a/lightrag/kg/neo4j_impl.py b/lightrag/kg/neo4j_impl.py index 9930abcc..dea675e6 100644 --- a/lightrag/kg/neo4j_impl.py +++ b/lightrag/kg/neo4j_impl.py @@ -67,10 +67,8 @@ class Neo4JStorage(BaseGraphStorage): def __init__(self, namespace, global_config, embedding_func, workspace=None): # Read env and override the arg if present neo4j_workspace = os.environ.get("NEO4J_WORKSPACE") + original_workspace = workspace # Save original value for logging if neo4j_workspace and neo4j_workspace.strip(): - logger.info( - f"Using NEO4J_WORKSPACE environment variable: '{neo4j_workspace}' (overriding '{self.workspace}/{self.namespace}')" - ) workspace = neo4j_workspace # Default to 'base' when both arg and env are empty @@ -83,6 +81,13 @@ class Neo4JStorage(BaseGraphStorage): global_config=global_config, embedding_func=embedding_func, ) + + # Log after super().__init__() to ensure self.workspace is initialized + if neo4j_workspace and neo4j_workspace.strip(): + logger.info( + f"Using NEO4J_WORKSPACE environment variable: '{neo4j_workspace}' (overriding '{original_workspace}/{namespace}')" + ) + self._driver = None def _get_workspace_label(self) -> str: