Skip to content

Commit 83c2222

Browse files
feat: Integrate Neo4j and fix CI issues
This commit resolves the issues from the previous PR eosphoros-ai#2951 by successfully integrating the Neo4j database. Key changes include: - Fixed code style issues, passing `make fmt` and `make fmt-check`. - Added `examples/neo4j_example.py` to demonstrate the usage of the new Neo4j connector. - Added `tests/intetration_tests/datasource/test_conn_neo4j.py` and `tests/intetration_tests/graph_store/test_neo4j_store.py` to provide integration tests for the new Neo4j functionality. - Resolved an issue with Neo4j startup in high-version Java environments. - Addressed all feedback from the code review, including fixing broken tests and moving an import statement. Note: I was unable to run the integration tests locally due to a lack of Docker permissions. The tests have been written and should be run in the CI/CD pipeline.
1 parent 251dbbb commit 83c2222

File tree

7 files changed

+232
-81
lines changed

7 files changed

+232
-81
lines changed

examples/neo4j_example.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import asyncio
2+
from typing import List
3+
4+
from dbgpt.storage.graph_store.graph import Edge, Graph, Vertex
5+
from dbgpt_ext.storage.graph_store.neo4j_store import Neo4jStore
6+
7+
8+
async def main():
9+
# Create a Neo4jStore instance
10+
neo4j_store = Neo4jStore()
11+
12+
# Create a graph
13+
graph = Graph("test_graph")
14+
v1 = Vertex("1", "node1")
15+
v2 = Vertex("2", "node2")
16+
graph.add_vertex(v1)
17+
graph.add_vertex(v2)
18+
edge = Edge("1", "2", "edge1")
19+
graph.add_edge(edge)
20+
21+
# Add the graph to the store
22+
await neo4j_store.add_graph(graph)
23+
24+
# Get the graph from the store
25+
retrieved_graph = await neo4j_store.get_graph("test_graph")
26+
print(retrieved_graph)
27+
28+
# Get all graph names
29+
graph_names = await neo4j_store.get_all_graph_names()
30+
print(graph_names)
31+
32+
# Delete the graph from the store
33+
await neo4j_store.delete_graph("test_graph")
34+
35+
36+
if __name__ == "__main__":
37+
asyncio.run(main())

packages/dbgpt-ext/src/dbgpt_ext/datasource/conn_neo4j.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ def from_uri_db(
119119

120120
def create_graph(self, graph_name: str) -> bool:
121121
"""Create a graph in Neo4j.
122-
122+
123123
Note: In Neo4j, databases are created at the system level.
124124
For knowledge graphs, we don't need to explicitly create a graph structure.
125125
This method is here for compatibility with TuGraph adapter.
126-
126+
127127
Returns:
128128
bool: True (graph always exists in Neo4j)
129129
"""
@@ -133,10 +133,10 @@ def create_graph(self, graph_name: str) -> bool:
133133

134134
def is_exist(self, graph_name: str) -> bool:
135135
"""Check if a database exists in Neo4j.
136-
136+
137137
Args:
138138
graph_name: Database name to check
139-
139+
140140
Returns:
141141
bool: True if database exists
142142
"""
@@ -149,7 +149,7 @@ def is_exist(self, graph_name: str) -> bool:
149149

150150
def delete_graph(self, graph_name: str) -> None:
151151
"""Delete all data from the current database.
152-
152+
153153
Note: This deletes all nodes and relationships, not the database itself.
154154
"""
155155
with self._driver.session(database=self._database) as session:
@@ -171,11 +171,11 @@ def get_system_info(self) -> Dict:
171171
system_info["neo4j_version"] = versions[0]
172172
# For compatibility with TuGraph adapter
173173
system_info["lgraph_version"] = versions[0]
174-
except Exception as e:
174+
except Exception:
175175
# Fallback for older Neo4j versions
176176
system_info["neo4j_version"] = "unknown"
177177
system_info["lgraph_version"] = "5.0.0" # Default compatible version
178-
178+
179179
return system_info
180180

181181
def get_table_names(self) -> Iterator[str]:
@@ -187,7 +187,9 @@ def get_table_names(self) -> Iterator[str]:
187187

188188
# Get relationship types
189189
result = session.run("CALL db.relationshipTypes()")
190-
rel_types = [record["relationshipType"] + "_relationship" for record in result]
190+
rel_types = [
191+
record["relationshipType"] + "_relationship" for record in result
192+
]
191193

192194
return iter(node_labels + rel_types)
193195

@@ -340,4 +342,3 @@ def get_database_names(self) -> List[str]:
340342
def is_graph_type(cls) -> bool:
341343
"""Return whether the connector is a graph database connector."""
342344
return True
343-

packages/dbgpt-ext/src/dbgpt_ext/storage/graph_store/neo4j_store.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import os
55
from dataclasses import dataclass, field
6-
from typing import List
76

87
from dbgpt.core.awel.flow import Parameter, ResourceCategory, register_resource
98
from dbgpt.storage.graph_store.base import GraphStoreBase, GraphStoreConfig
@@ -182,10 +181,10 @@ def get_config(self) -> Neo4jStoreConfig:
182181

183182
def is_exist(self, name: str) -> bool:
184183
"""Check if graph (database) exists in Neo4j.
185-
184+
186185
Args:
187186
name: Database name to check
188-
187+
189188
Returns:
190189
bool: True if database exists
191190
"""

0 commit comments

Comments
 (0)