diff --git a/Directory.Build.props b/Directory.Build.props
index edc8067..7c71bd1 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,7 @@
- 0.1.14
+ 0.1.15
1.17.1
diff --git a/src/GraphRag.Net/Domain/Service/GraphService.cs b/src/GraphRag.Net/Domain/Service/GraphService.cs
index a1037cd..0145d30 100644
--- a/src/GraphRag.Net/Domain/Service/GraphService.cs
+++ b/src/GraphRag.Net/Domain/Service/GraphService.cs
@@ -195,6 +195,7 @@ public async Task InsertGraphDataAsync(string index, string input)
}
if (!_edges_Repositories.IsAny(p => p.Target == relationShip.Edge.Target && p.Source == relationShip.Edge.Source))
{
+ relationShip.Edge.Id=Guid.NewGuid().ToString();
relationShip.Edge.Index = index;
_edges_Repositories.Insert(relationShip.Edge);
}
@@ -233,6 +234,7 @@ public async Task InsertGraphDataAsync(string index, string input)
{
Edges edge = new Edges()
{
+ Id=Guid.NewGuid().ToString(),
Index = index,
Source = nodeDic[e.Source],
Target = nodeDic[e.Target],
@@ -240,6 +242,32 @@ public async Task InsertGraphDataAsync(string index, string input)
};
_edges_Repositories.Insert(edge);
}
+
+ //查询Edges 的Source和Target 重复数据
+ var repeatEdges = _edges_Repositories.GetDB().Queryable()
+ .GroupBy(p => new { p.Source, p.Target })
+ .Select(p => new { p.Source, p.Target, Count = SqlFunc.AggregateCount(p.Source) })
+ .ToList().Where(p => p.Count > 1).ToList();
+ //合并查询Edges 的Source和Target 重复数据
+ foreach (var edge in repeatEdges)
+ {
+ var edges = _edges_Repositories.GetList(p => p.Source == edge.Source && p.Target == edge.Target);
+ var firstEdge=edges.First();
+
+ for (int i = 1; i < edges.Count(); i++)
+ {
+ if (firstEdge.Relationship == edges[i].Relationship)
+ {
+ //相同的边进行合并
+ _edges_Repositories.Delete(edges[i]);
+ continue;
+ }
+ var newDesc=await _semanticService.MergeDesc(firstEdge.Relationship, edges[i].Relationship);
+ firstEdge.Relationship= newDesc;
+ _edges_Repositories.Update(firstEdge);
+ _edges_Repositories.Delete(edges[i]);
+ }
+ }
}
catch (Exception ex)
{
diff --git a/src/GraphRag.Net/Repositories/Graph/Edges/Edges.cs b/src/GraphRag.Net/Repositories/Graph/Edges/Edges.cs
index 19fc213..0341717 100644
--- a/src/GraphRag.Net/Repositories/Graph/Edges/Edges.cs
+++ b/src/GraphRag.Net/Repositories/Graph/Edges/Edges.cs
@@ -11,6 +11,11 @@ namespace GraphRag.Net.Repositories
[SugarIndex("i_edges_target", nameof(Edges.Target), OrderByType.Asc)]
public class Edges
{
+ ///
+ /// 主键
+ ///
+ [SugarColumn(IsPrimaryKey = true)]
+ public string Id { get; set; }
///
/// 索引
///