yangdx
commited on
Commit
·
33d79e1
1
Parent(s):
e621fd6
Fix linting
Browse files- lightrag/kg/neo4j_impl.py +10 -8
lightrag/kg/neo4j_impl.py
CHANGED
@@ -164,16 +164,18 @@ class Neo4JStorage(BaseGraphStorage):
|
|
164 |
check_result = await session.run(check_query)
|
165 |
record = await check_result.single()
|
166 |
await check_result.consume()
|
167 |
-
|
168 |
index_exists = record and record.get("exists", False)
|
169 |
-
|
170 |
if not index_exists:
|
171 |
# Create index only if it doesn't exist
|
172 |
result = await session.run(
|
173 |
"CREATE INDEX FOR (n:base) ON (n.entity_id)"
|
174 |
)
|
175 |
await result.consume()
|
176 |
-
logger.info(
|
|
|
|
|
177 |
except Exception:
|
178 |
# Fallback if db.indexes() is not supported in this Neo4j version
|
179 |
result = await session.run(
|
@@ -709,7 +711,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|
709 |
WITH node, COALESCE(count(r), 0) AS degree, start, nodes, relationships
|
710 |
ORDER BY
|
711 |
CASE
|
712 |
-
WHEN node = start THEN 0
|
713 |
ELSE length(shortestPath((start)--(node)))
|
714 |
END ASC,
|
715 |
degree DESC
|
@@ -778,13 +780,13 @@ class Neo4JStorage(BaseGraphStorage):
|
|
778 |
logger.warning(
|
779 |
"Neo4j: falling back to basic Cypher recursive search..."
|
780 |
)
|
781 |
-
return await self._robust_fallback(
|
782 |
-
node_label, max_depth, max_nodes
|
783 |
-
)
|
784 |
|
785 |
return result
|
786 |
|
787 |
-
async def _robust_fallback(
|
|
|
|
|
788 |
"""
|
789 |
Fallback implementation when APOC plugin is not available or incompatible.
|
790 |
This method implements the same functionality as get_knowledge_graph but uses
|
|
|
164 |
check_result = await session.run(check_query)
|
165 |
record = await check_result.single()
|
166 |
await check_result.consume()
|
167 |
+
|
168 |
index_exists = record and record.get("exists", False)
|
169 |
+
|
170 |
if not index_exists:
|
171 |
# Create index only if it doesn't exist
|
172 |
result = await session.run(
|
173 |
"CREATE INDEX FOR (n:base) ON (n.entity_id)"
|
174 |
)
|
175 |
await result.consume()
|
176 |
+
logger.info(
|
177 |
+
f"Created index for base nodes on entity_id in {database}"
|
178 |
+
)
|
179 |
except Exception:
|
180 |
# Fallback if db.indexes() is not supported in this Neo4j version
|
181 |
result = await session.run(
|
|
|
711 |
WITH node, COALESCE(count(r), 0) AS degree, start, nodes, relationships
|
712 |
ORDER BY
|
713 |
CASE
|
714 |
+
WHEN node = start THEN 0
|
715 |
ELSE length(shortestPath((start)--(node)))
|
716 |
END ASC,
|
717 |
degree DESC
|
|
|
780 |
logger.warning(
|
781 |
"Neo4j: falling back to basic Cypher recursive search..."
|
782 |
)
|
783 |
+
return await self._robust_fallback(node_label, max_depth, max_nodes)
|
|
|
|
|
784 |
|
785 |
return result
|
786 |
|
787 |
+
async def _robust_fallback(
|
788 |
+
self, node_label: str, max_depth: int, max_nodes: int
|
789 |
+
) -> KnowledgeGraph:
|
790 |
"""
|
791 |
Fallback implementation when APOC plugin is not available or incompatible.
|
792 |
This method implements the same functionality as get_knowledge_graph but uses
|