yangdx
commited on
Commit
·
49166cd
1
Parent(s):
9c8a458
- Remove useless `_label_exists` method
Browse files- lightrag/kg/neo4j_impl.py +6 -16
lightrag/kg/neo4j_impl.py
CHANGED
@@ -164,23 +164,13 @@ class Neo4JStorage(BaseGraphStorage):
|
|
164 |
# Noe4J handles persistence automatically
|
165 |
pass
|
166 |
|
167 |
-
async def _label_exists(self, label: str) -> bool:
|
168 |
-
"""Check if a label exists in the Neo4j database."""
|
169 |
-
query = "CALL db.labels() YIELD label RETURN label"
|
170 |
-
try:
|
171 |
-
async with self._driver.session(database=self._DATABASE) as session:
|
172 |
-
result = await session.run(query)
|
173 |
-
labels = [record["label"] for record in await result.data()]
|
174 |
-
return label in labels
|
175 |
-
except Exception as e:
|
176 |
-
logger.error(f"Error checking label existence: {e}")
|
177 |
-
return False
|
178 |
-
|
179 |
async def _ensure_label(self, label: str) -> str:
|
180 |
-
"""Ensure a label
|
|
|
|
|
|
|
|
|
181 |
clean_label = label.strip('"')
|
182 |
-
if not await self._label_exists(clean_label):
|
183 |
-
logger.warning(f"Label '{clean_label}' does not exist in Neo4j")
|
184 |
return clean_label
|
185 |
|
186 |
async def has_node(self, node_id: str) -> bool:
|
@@ -290,7 +280,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|
290 |
if record:
|
291 |
try:
|
292 |
result = dict(record["edge_properties"])
|
293 |
-
logger.
|
294 |
# Ensure required keys exist with defaults
|
295 |
required_keys = {
|
296 |
"weight": 0.0,
|
|
|
164 |
# Noe4J handles persistence automatically
|
165 |
pass
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
async def _ensure_label(self, label: str) -> str:
|
168 |
+
"""Ensure a label is valid
|
169 |
+
|
170 |
+
Args:
|
171 |
+
label: The label to validate
|
172 |
+
"""
|
173 |
clean_label = label.strip('"')
|
|
|
|
|
174 |
return clean_label
|
175 |
|
176 |
async def has_node(self, node_id: str) -> bool:
|
|
|
280 |
if record:
|
281 |
try:
|
282 |
result = dict(record["edge_properties"])
|
283 |
+
logger.debug(f"Result: {result}")
|
284 |
# Ensure required keys exist with defaults
|
285 |
required_keys = {
|
286 |
"weight": 0.0,
|