ArnoChen
commited on
Commit
·
858f35e
1
Parent(s):
07feee7
handle missing edge types in graph data
Browse files
lightrag/types.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from pydantic import BaseModel
|
2 |
-
from typing import List, Dict, Any
|
3 |
|
4 |
|
5 |
class GPTKeywordExtractionFormat(BaseModel):
|
@@ -15,7 +15,7 @@ class KnowledgeGraphNode(BaseModel):
|
|
15 |
|
16 |
class KnowledgeGraphEdge(BaseModel):
|
17 |
id: str
|
18 |
-
type: str
|
19 |
source: str # id of source node
|
20 |
target: str # id of target node
|
21 |
properties: Dict[str, Any] # anything else goes here
|
|
|
1 |
from pydantic import BaseModel
|
2 |
+
from typing import List, Dict, Any, Optional
|
3 |
|
4 |
|
5 |
class GPTKeywordExtractionFormat(BaseModel):
|
|
|
15 |
|
16 |
class KnowledgeGraphEdge(BaseModel):
|
17 |
id: str
|
18 |
+
type: Optional[str]
|
19 |
source: str # id of source node
|
20 |
target: str # id of target node
|
21 |
properties: Dict[str, Any] # anything else goes here
|
lightrag_webui/src/components/PropertiesView.tsx
CHANGED
@@ -200,7 +200,7 @@ const EdgePropertiesView = ({ edge }: { edge: EdgeType }) => {
|
|
200 |
<label className="text-md pl-1 font-bold tracking-wide text-teal-600">Relationship</label>
|
201 |
<div className="bg-primary/5 max-h-96 overflow-auto rounded p-1">
|
202 |
<PropertyRow name={'Id'} value={edge.id} />
|
203 |
-
<PropertyRow name={'Type'} value={edge.type} />
|
204 |
<PropertyRow
|
205 |
name={'Source'}
|
206 |
value={edge.sourceNode ? edge.sourceNode.labels.join(', ') : edge.source}
|
|
|
200 |
<label className="text-md pl-1 font-bold tracking-wide text-teal-600">Relationship</label>
|
201 |
<div className="bg-primary/5 max-h-96 overflow-auto rounded p-1">
|
202 |
<PropertyRow name={'Id'} value={edge.id} />
|
203 |
+
{edge.type && <PropertyRow name={'Type'} value={edge.type} />}
|
204 |
<PropertyRow
|
205 |
name={'Source'}
|
206 |
value={edge.sourceNode ? edge.sourceNode.labels.join(', ') : edge.source}
|
lightrag_webui/src/hooks/useLightragGraph.tsx
CHANGED
@@ -24,7 +24,7 @@ const validateGraph = (graph: RawGraph) => {
|
|
24 |
}
|
25 |
|
26 |
for (const edge of graph.edges) {
|
27 |
-
if (!edge.id || !edge.source || !edge.target
|
28 |
return false
|
29 |
}
|
30 |
}
|
@@ -88,6 +88,14 @@ const fetchGraph = async (label: string) => {
|
|
88 |
if (source !== undefined && source !== undefined) {
|
89 |
const sourceNode = rawData.nodes[source]
|
90 |
const targetNode = rawData.nodes[target]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
sourceNode.degree += 1
|
92 |
targetNode.degree += 1
|
93 |
}
|
@@ -146,7 +154,7 @@ const createSigmaGraph = (rawGraph: RawGraph | null) => {
|
|
146 |
|
147 |
for (const rawEdge of rawGraph?.edges ?? []) {
|
148 |
rawEdge.dynamicId = graph.addDirectedEdge(rawEdge.source, rawEdge.target, {
|
149 |
-
label: rawEdge.type
|
150 |
})
|
151 |
}
|
152 |
|
|
|
24 |
}
|
25 |
|
26 |
for (const edge of graph.edges) {
|
27 |
+
if (!edge.id || !edge.source || !edge.target) {
|
28 |
return false
|
29 |
}
|
30 |
}
|
|
|
88 |
if (source !== undefined && source !== undefined) {
|
89 |
const sourceNode = rawData.nodes[source]
|
90 |
const targetNode = rawData.nodes[target]
|
91 |
+
if (!sourceNode) {
|
92 |
+
console.error(`Source node ${edge.source} is undefined`)
|
93 |
+
continue
|
94 |
+
}
|
95 |
+
if (!targetNode) {
|
96 |
+
console.error(`Target node ${edge.target} is undefined`)
|
97 |
+
continue
|
98 |
+
}
|
99 |
sourceNode.degree += 1
|
100 |
targetNode.degree += 1
|
101 |
}
|
|
|
154 |
|
155 |
for (const rawEdge of rawGraph?.edges ?? []) {
|
156 |
rawEdge.dynamicId = graph.addDirectedEdge(rawEdge.source, rawEdge.target, {
|
157 |
+
label: rawEdge.type || undefined
|
158 |
})
|
159 |
}
|
160 |
|
lightrag_webui/src/stores/graph.ts
CHANGED
@@ -19,7 +19,7 @@ export type RawEdgeType = {
|
|
19 |
id: string
|
20 |
source: string
|
21 |
target: string
|
22 |
-
type
|
23 |
properties: Record<string, any>
|
24 |
|
25 |
dynamicId: string
|
|
|
19 |
id: string
|
20 |
source: string
|
21 |
target: string
|
22 |
+
type?: string
|
23 |
properties: Record<string, any>
|
24 |
|
25 |
dynamicId: string
|