Merge pull request #1050 from danielaskdd/fix-neo4j-duplicate-nodes
Refactor Neo4J storage to use entity_id for node identification
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
lightrag/api/webui/** -diff
|
@@ -3,16 +3,21 @@ repos:
|
|||||||
rev: v5.0.0
|
rev: v5.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
- id: requirements-txt-fixer
|
- id: requirements-txt-fixer
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
|
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.6.4
|
rev: v0.6.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: [--fix, --ignore=E402]
|
args: [--fix, --ignore=E402]
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
|
|
||||||
|
|
||||||
- repo: https://github.com/mgedmin/check-manifest
|
- repo: https://github.com/mgedmin/check-manifest
|
||||||
@@ -20,3 +25,4 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: check-manifest
|
- id: check-manifest
|
||||||
stages: [manual]
|
stages: [manual]
|
||||||
|
exclude: ^lightrag/api/webui/
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Lightrag</title>
|
<title>Lightrag</title>
|
||||||
<script type="module" crossorigin src="./assets/index-CJz72b6Q.js"></script>
|
<script type="module" crossorigin src="./assets/index-BlVvSIic.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="./assets/index-CH-3l4_Z.css">
|
<link rel="stylesheet" crossorigin href="./assets/index-CH-3l4_Z.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@@ -553,18 +553,6 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
logger.error(f"Error during upsert: {str(e)}")
|
logger.error(f"Error during upsert: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@retry(
|
|
||||||
stop=stop_after_attempt(3),
|
|
||||||
wait=wait_exponential(multiplier=1, min=4, max=10),
|
|
||||||
retry=retry_if_exception_type(
|
|
||||||
(
|
|
||||||
neo4jExceptions.ServiceUnavailable,
|
|
||||||
neo4jExceptions.TransientError,
|
|
||||||
neo4jExceptions.WriteServiceUnavailable,
|
|
||||||
neo4jExceptions.ClientError,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@retry(
|
@retry(
|
||||||
stop=stop_after_attempt(3),
|
stop=stop_after_attempt(3),
|
||||||
wait=wait_exponential(multiplier=1, min=4, max=10),
|
wait=wait_exponential(multiplier=1, min=4, max=10),
|
||||||
@@ -666,7 +654,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
main_query = """
|
main_query = """
|
||||||
MATCH (n)
|
MATCH (n)
|
||||||
OPTIONAL MATCH (n)-[r]-()
|
OPTIONAL MATCH (n)-[r]-()
|
||||||
WITH n, count(r) AS degree
|
WITH n, COALESCE(count(r), 0) AS degree
|
||||||
WHERE degree >= $min_degree
|
WHERE degree >= $min_degree
|
||||||
ORDER BY degree DESC
|
ORDER BY degree DESC
|
||||||
LIMIT $max_nodes
|
LIMIT $max_nodes
|
||||||
@@ -703,7 +691,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
WITH start, nodes, relationships
|
WITH start, nodes, relationships
|
||||||
UNWIND nodes AS node
|
UNWIND nodes AS node
|
||||||
OPTIONAL MATCH (node)-[r]-()
|
OPTIONAL MATCH (node)-[r]-()
|
||||||
WITH node, count(r) AS degree, start, nodes, relationships
|
WITH node, COALESCE(count(r), 0) AS degree, start, nodes, relationships
|
||||||
WHERE node = start OR EXISTS((start)--(node)) OR degree >= $min_degree
|
WHERE node = start OR EXISTS((start)--(node)) OR degree >= $min_degree
|
||||||
ORDER BY
|
ORDER BY
|
||||||
CASE
|
CASE
|
||||||
@@ -744,11 +732,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
result.nodes.append(
|
result.nodes.append(
|
||||||
KnowledgeGraphNode(
|
KnowledgeGraphNode(
|
||||||
id=f"{node_id}",
|
id=f"{node_id}",
|
||||||
labels=[
|
labels=[node.get("entity_id")],
|
||||||
label
|
|
||||||
for label in node.labels
|
|
||||||
if label != "base"
|
|
||||||
],
|
|
||||||
properties=dict(node),
|
properties=dict(node),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -865,9 +849,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
# Create KnowledgeGraphNode for target
|
# Create KnowledgeGraphNode for target
|
||||||
target_node = KnowledgeGraphNode(
|
target_node = KnowledgeGraphNode(
|
||||||
id=f"{target_id}",
|
id=f"{target_id}",
|
||||||
labels=[
|
labels=list(f"{target_id}"),
|
||||||
label for label in b_node.labels if label != "base"
|
|
||||||
],
|
|
||||||
properties=dict(b_node.properties),
|
properties=dict(b_node.properties),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -907,9 +889,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
# Create initial KnowledgeGraphNode
|
# Create initial KnowledgeGraphNode
|
||||||
start_node = KnowledgeGraphNode(
|
start_node = KnowledgeGraphNode(
|
||||||
id=f"{node_record['n'].get('entity_id')}",
|
id=f"{node_record['n'].get('entity_id')}",
|
||||||
labels=[
|
labels=list(f"{node_record['n'].get('entity_id')}"),
|
||||||
label for label in node_record["n"].labels if label != "base"
|
|
||||||
],
|
|
||||||
properties=dict(node_record["n"].properties),
|
properties=dict(node_record["n"].properties),
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
|
@@ -96,9 +96,9 @@ const refineNodeProperties = (node: RawNodeType): NodeType => {
|
|||||||
const neighbour = state.rawGraph.getNode(neighbourId)
|
const neighbour = state.rawGraph.getNode(neighbourId)
|
||||||
if (neighbour) {
|
if (neighbour) {
|
||||||
relationships.push({
|
relationships.push({
|
||||||
type: isTarget ? 'Target' : 'Source',
|
type: 'Neighbour',
|
||||||
id: neighbourId,
|
id: neighbourId,
|
||||||
label: neighbour.labels.join(', ')
|
label: neighbour.properties['entity_id'] ? neighbour.properties['entity_id'] : neighbour.labels.join(', ')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user