@@ -131,8 +131,8 @@ public async Task InsertGraphDataAsync(string index, string input)
131
131
bool isContinue = false ;
132
132
133
133
//判断是否存在相同节点
134
- var oldNode = _nodes_Repositories . GetFirst ( p => p . Index == index && p . Name == n . Name ) ;
135
- if ( oldNode . IsNotNull ( ) )
134
+ var oldNode = _nodes_Repositories . GetFirst ( p => p . Index == index && p . Name == n . Name ) ;
135
+ if ( oldNode . IsNotNull ( ) && ! string . IsNullOrWhiteSpace ( n . Desc ) )
136
136
{
137
137
//相同节点关联edge关系
138
138
var newDesc = await _semanticService . MergeDesc ( oldNode . Desc . ConvertToString ( ) , n . Desc . ConvertToString ( ) ) ;
@@ -188,7 +188,7 @@ public async Task InsertGraphDataAsync(string index, string input)
188
188
}
189
189
if ( ! _edges_Repositories . IsAny ( p => p . Target == relationShip . Edge . Target && p . Source == relationShip . Edge . Source ) )
190
190
{
191
- relationShip . Edge . Id = Guid . NewGuid ( ) . ToString ( ) ;
191
+ relationShip . Edge . Id = Guid . NewGuid ( ) . ToString ( ) ;
192
192
relationShip . Edge . Index = index ;
193
193
_edges_Repositories . Insert ( relationShip . Edge ) ;
194
194
}
@@ -223,7 +223,7 @@ public async Task InsertGraphDataAsync(string index, string input)
223
223
{
224
224
Edges edge = new Edges ( )
225
225
{
226
- Id = Guid . NewGuid ( ) . ToString ( ) ,
226
+ Id = Guid . NewGuid ( ) . ToString ( ) ,
227
227
Index = index ,
228
228
Source = nodeDic [ e . Source ] ,
229
229
Target = nodeDic [ e . Target ] ,
@@ -239,9 +239,9 @@ public async Task InsertGraphDataAsync(string index, string input)
239
239
. ToList ( ) . Where ( p => p . Count > 1 ) . ToList ( ) ;
240
240
//合并查询Edges 的Source和Target 重复数据
241
241
foreach ( var edge in repeatEdges )
242
- {
242
+ {
243
243
var edges = _edges_Repositories . GetList ( p => p . Source == edge . Source && p . Target == edge . Target ) ;
244
- var firstEdge = edges . First ( ) ;
244
+ var firstEdge = edges . First ( ) ;
245
245
246
246
for ( int i = 1 ; i < edges . Count ( ) ; i ++ )
247
247
{
@@ -251,11 +251,11 @@ public async Task InsertGraphDataAsync(string index, string input)
251
251
_edges_Repositories . Delete ( edges [ i ] ) ;
252
252
continue ;
253
253
}
254
- var newDesc = await _semanticService . MergeDesc ( firstEdge . Relationship , edges [ i ] . Relationship ) ;
255
- firstEdge . Relationship = newDesc ;
254
+ var newDesc = await _semanticService . MergeDesc ( firstEdge . Relationship , edges [ i ] . Relationship ) ;
255
+ firstEdge . Relationship = newDesc ;
256
256
_edges_Repositories . Update ( firstEdge ) ;
257
257
_edges_Repositories . Delete ( edges [ i ] ) ;
258
- }
258
+ }
259
259
}
260
260
}
261
261
catch ( Exception ex )
@@ -271,7 +271,8 @@ public async Task InsertGraphDataAsync(string index, string input)
271
271
/// <param name="input"></param>
272
272
/// <returns></returns>
273
273
/// <exception cref="ArgumentException"></exception>
274
- public async Task < GraphModel > SearchGraphModel ( string index , string input ) {
274
+ public async Task < GraphModel > SearchGraphModel ( string index , string input )
275
+ {
275
276
if ( string . IsNullOrWhiteSpace ( index ) || string . IsNullOrWhiteSpace ( input ) )
276
277
{
277
278
throw new ArgumentException ( "Values required for index and input cannot be null." ) ;
@@ -327,7 +328,7 @@ public async Task<GraphModel> SearchGraphCommunityModel(string index, string inp
327
328
/// <returns></returns>
328
329
public async Task < string > SearchGraphAsync ( string index , string input )
329
330
{
330
- var graphModel = await SearchGraphModel ( index , input ) ;
331
+ var graphModel = await SearchGraphModel ( index , input ) ;
331
332
string answer = await _semanticService . GetGraphAnswerAsync ( JsonConvert . SerializeObject ( graphModel ) , input ) ;
332
333
return answer ;
333
334
}
@@ -362,8 +363,8 @@ public async Task<string> SearchGraphCommunityAsync(string index, string input)
362
363
string answer = "" ;
363
364
var graphModel = await SearchGraphCommunityModel ( index , input ) ;
364
365
var global = _globals_Repositories . GetFirst ( p => p . Index == index ) ? . Summaries ;
365
- if ( graphModel . Nodes . Count ( ) > 0 )
366
- {
366
+ if ( graphModel . Nodes . Count ( ) > 0 )
367
+ {
367
368
var community = string . Join ( Environment . NewLine , _communities_Repositories . GetDB ( ) . Queryable < Communities > ( ) . Where ( p => p . Index == index ) . Select ( p => p . Summaries ) . ToList ( ) ) ;
368
369
369
370
//这里数据有点多,要通过语义进行一次过滤
@@ -388,7 +389,7 @@ public async IAsyncEnumerable<StreamingKernelContent> SearchGraphCommunityStream
388
389
var textMemModelList = await RetrieveTextMemModelList ( index , input ) ;
389
390
var global = _globals_Repositories . GetFirst ( p => p . Index == index ) ? . Summaries ;
390
391
IAsyncEnumerable < StreamingKernelContent > answer ;
391
-
392
+
392
393
//匹配到节点信息
393
394
var graphModel = await SearchGraphCommunityModel ( index , input ) ;
394
395
if ( graphModel . Nodes . Count ( ) > 0 )
@@ -475,8 +476,8 @@ public async Task GraphCommunitiesAsync(string index)
475
476
public async Task GraphGlobalAsync ( string index )
476
477
{
477
478
_globals_Repositories . Delete ( p => p . Index == index ) ;
478
- var communitieSummariesList = _communities_Repositories . GetDB ( ) . Queryable < Communities > ( ) . Where ( p => p . Index == index ) . Select ( p=> p . Summaries ) . ToList ( ) ;
479
- var communitieSummaries = string . Join ( Environment . NewLine , communitieSummariesList ) ;
479
+ var communitieSummariesList = _communities_Repositories . GetDB ( ) . Queryable < Communities > ( ) . Where ( p => p . Index == index ) . Select ( p => p . Summaries ) . ToList ( ) ;
480
+ var communitieSummaries = string . Join ( Environment . NewLine , communitieSummariesList ) ;
480
481
var globalSummaries = await _semanticService . GlobalSummaries ( communitieSummaries ) ;
481
482
482
483
Globals globals = new Globals ( )
@@ -578,7 +579,7 @@ private GraphModel GetGraphAllRecursion(string index, List<Nodes> initialNodes)
578
579
// 如果节点数超过最大限制,进行截断
579
580
if ( allNodes . Count > GraphSearchOption . MaxNodes )
580
581
{
581
- allNodes = allNodes . Take ( GraphSearchOption . MaxNodes ) . ToList ( ) ;
582
+ allNodes = allNodes . Take ( GraphSearchOption . MaxNodes ) . ToList ( ) ;
582
583
}
583
584
// 需要相应地处理 allEdges,确保边的节点在 allNodes 中
584
585
allEdges = allEdges . Where ( e => allNodes . Any ( p => p . Id == e . Source ) && allNodes . Any ( p => p . Id == e . Target ) ) . ToList ( ) ;
0 commit comments