Skip to content

Commit

Permalink
add 增加删除图谱数据
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzeyu91 committed Aug 5, 2024
1 parent 5dcac45 commit 0a3511e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>
<Version>0.1.4</Version>
<SKVersion>1.16.0</SKVersion>
<Version>0.1.5</Version>
<SKVersion>1.16.2</SKVersion>
</PropertyGroup>
</Project>
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ namespace GraphRag.Net.Api.Controllers
await _graphService.GraphGlobalAsync(index);
return Ok();
}
/// <summary>
/// 删除图谱数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
[HttpGet]
public async Task<IActionResult> DeleteGraph(string index)
{
await _graphService.DeleteGraph(index);
return Ok();
}
}
public class InputModel
Expand Down
28 changes: 20 additions & 8 deletions src/GraphRag.Net.Web/Controllers/GraphDemoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace GraphRag.Net.Api.Controllers
public class GraphDemoController(IGraphService _graphService) : ControllerBase
{
/// <summary>
/// 获取所有的索引数据
/// 获取所有的索引数据
/// </summary>
/// <returns></returns>
[HttpGet]
Expand All @@ -21,7 +21,7 @@ public async Task<IActionResult> GetAllIndex()


/// <summary>
/// 获取所有的图谱数据
/// 获取所有的图谱数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
Expand All @@ -38,7 +38,7 @@ public async Task<IActionResult> GetAllGraphs(string index)


/// <summary>
/// 插入文本数据
/// 插入文本数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Expand All @@ -50,7 +50,7 @@ public async Task<IActionResult> InsertGraphData(InputModel model)
}

/// <summary>
/// 搜索递归获取节点相关的所有边和节点进行图谱对话
/// 搜索递归获取节点相关的所有边和节点进行图谱对话
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Expand All @@ -62,7 +62,7 @@ public async Task<IActionResult> SearchGraph(InputModel model)
}

/// <summary>
/// 通过社区算法检索社区节点进行对话
/// 通过社区算法检索社区节点进行对话
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Expand All @@ -74,7 +74,7 @@ public async Task<IActionResult> SearchGraphCommunity(InputModel model)
}

/// <summary>
/// 导入txt文档
/// 导入txt文档
/// </summary>
/// <param name="index"></param>
/// <param name="file"></param>
Expand All @@ -92,7 +92,7 @@ public async Task<IActionResult> ImportTxt(string index,IFormFile file)
}

/// <summary>
/// 通过社区检测生成社区和摘要
/// 通过社区检测生成社区和摘要
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
Expand All @@ -104,7 +104,7 @@ public async Task<IActionResult> GraphCommunities(string index)
}

/// <summary>
/// 通过社区摘要生成全局摘要
/// 通过社区摘要生成全局摘要
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
Expand All @@ -114,6 +114,18 @@ public async Task<IActionResult> GraphGlobal(string index)
await _graphService.GraphGlobalAsync(index);
return Ok();
}

/// <summary>
/// 删除图谱数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
[HttpGet]
public async Task<IActionResult> DeleteGraph(string index)
{
await _graphService.DeleteGraph(index);
return Ok();
}
}

public class InputModel
Expand Down
7 changes: 7 additions & 0 deletions src/GraphRag.Net/Domain/Interface/IGraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,12 @@ public interface IGraphService
/// <param name="index"></param>
/// <returns></returns>
Task GraphGlobalAsync(string index);

/// <summary>
/// 删除图谱数据
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
Task DeleteGraph(string index);
}
}
19 changes: 19 additions & 0 deletions src/GraphRag.Net/Domain/Service/GraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,23 @@ public async Task GraphGlobalAsync(string index)
_globals_Repositories.Insert(globals);
}

public async Task DeleteGraph(string index)
{
SemanticTextMemory textMemory = await _semanticService.GetTextMemory();
var nodes = await _nodes_Repositories.GetListAsync(p => p.Index == index);
foreach (var node in nodes)
{
//删除向量数据
await textMemory.RemoveAsync(index, node.Id);
}
//删除索引数据
await _nodes_Repositories.DeleteAsync(p => p.Index == index);
await _edges_Repositories.DeleteAsync(p => p.Index == index);
await _communities_Repositories.DeleteAsync(p => p.Index == index);
await _communitieNodes_Repositories.DeleteAsync(p => p.Index == index);
await _globals_Repositories.DeleteAsync(p => p.Index == index);
}


#region 内部方法
/// <summary>
Expand Down Expand Up @@ -615,6 +632,8 @@ private List<Nodes> GetNodes(string index, List<Edges> edges)
return nodes;
}



#endregion
}
}

0 comments on commit 0a3511e

Please sign in to comment.