From 4e6ccdd958b622bc59daa2311f72856b9bed1171 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 20 Jan 2026 11:50:14 -0600 Subject: [PATCH] clean graph db --- .../BotSharp.Abstraction/Graph/IGraphDb.cs | 15 ----- .../Graph/IGraphKnowledgeService.cs | 10 --- .../Graph/Models/GraphEdge.cs | 5 -- .../Graph/Models/GraphNode.cs | 15 ----- .../Graph/Options/GraphNodeOptions.cs | 6 -- .../Graph/Requests/GraphNodeCreationModel.cs | 16 ----- .../Graph/Requests/GraphNodeUpdateModel.cs | 10 --- .../Responses/GraphNodeDeleteResponse.cs | 6 -- .../Graph/GraphKnowledgeService.Node.cs | 43 ------------- .../GraphDb/MembaseGraphDb.Node.cs | 62 ------------------- .../Models/Graph/Node.cs | 11 ---- .../Models/Requests/NodeCreationModel.cs | 18 ------ .../Models/Requests/NodeUpdateModel.cs | 18 ------ .../Services/MembaseService.cs | 3 +- 14 files changed, 2 insertions(+), 236 deletions(-) delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphEdge.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphNode.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Options/GraphNodeOptions.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeCreationModel.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeUpdateModel.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Graph/Responses/GraphNodeDeleteResponse.cs delete mode 100644 src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.Node.cs delete mode 100644 src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.Node.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs index 01701e0be..785be11e5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs @@ -1,7 +1,5 @@ using BotSharp.Abstraction.Graph.Models; using BotSharp.Abstraction.Graph.Options; -using BotSharp.Abstraction.Graph.Requests; -using BotSharp.Abstraction.Graph.Responses; namespace BotSharp.Abstraction.Graph; @@ -11,17 +9,4 @@ public interface IGraphDb Task ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null) => throw new NotImplementedException(); - - #region Node - Task GetNodeAsync(string graphId, string nodeId) - => throw new NotImplementedException(); - Task CreateNodeAsync(string graphId, GraphNodeCreationModel node) - => throw new NotImplementedException(); - Task UpdateNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node) - => throw new NotImplementedException(); - Task UpsertNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node) - => throw new NotImplementedException(); - Task DeleteNodeAsync(string graphId, string nodeId) - => throw new NotImplementedException(); - #endregion } diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphKnowledgeService.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphKnowledgeService.cs index 22852a11b..6f612cf1c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphKnowledgeService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Graph/IGraphKnowledgeService.cs @@ -1,19 +1,9 @@ using BotSharp.Abstraction.Graph.Models; using BotSharp.Abstraction.Graph.Options; -using BotSharp.Abstraction.Graph.Requests; -using BotSharp.Abstraction.Graph.Responses; namespace BotSharp.Abstraction.Graph; public interface IGraphKnowledgeService { Task ExecuteQueryAsync(string query, GraphQueryOptions? options = null); - - #region Node - Task GetNodeAsync(string graphId, string nodeId, GraphNodeOptions? options = null); - Task CreateNodeAsync(string graphId, GraphNodeCreationModel node, GraphNodeOptions? options = null); - Task UpdateNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node, GraphNodeOptions? options = null); - Task UpsertNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node, GraphNodeOptions? options = null); - Task DeleteNodeAsync(string graphId, string nodeId, GraphNodeOptions? options = null); - #endregion } diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphEdge.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphEdge.cs deleted file mode 100644 index b73c6744a..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphEdge.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Models; - -public class GraphEdge -{ -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphNode.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphNode.cs deleted file mode 100644 index e427070cf..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Models/GraphNode.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Models; - -public class GraphNode -{ - public string Id { get; set; } = string.Empty; - public List Labels { get; set; } = new(); - public object Properties { get; set; } = new(); - public DateTime? Time { get; set; } = DateTime.UtcNow; - - public override string ToString() - { - var labelsString = Labels.Count > 0 ? string.Join(", ", Labels) : "No Labels"; - return $"Node ({labelsString}: {Id})"; - } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Options/GraphNodeOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Options/GraphNodeOptions.cs deleted file mode 100644 index fb0ab5015..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Options/GraphNodeOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Options; - -public class GraphNodeOptions -{ - public string? Provider { get; set; } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeCreationModel.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeCreationModel.cs deleted file mode 100644 index 308acbedc..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeCreationModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Requests; - -public class GraphNodeCreationModel -{ - public string? Id { get; set; } - public string[]? Labels { get; set; } - public object? Properties { get; set; } - public GraphNodeEmbedding? Embedding { get; set; } - public DateTime? Time { get; set; } -} - -public class GraphNodeEmbedding -{ - public string Model { get; set; } - public float[] Vector { get; set; } -} \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeUpdateModel.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeUpdateModel.cs deleted file mode 100644 index 6b27fb93f..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Requests/GraphNodeUpdateModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Requests; - -public class GraphNodeUpdateModel -{ - public string Id { get; set; } = null!; - public string[]? Labels { get; set; } - public object? Properties { get; set; } - public GraphNodeEmbedding? Embedding { get; set; } - public DateTime? Time { get; set; } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Graph/Responses/GraphNodeDeleteResponse.cs b/src/Infrastructure/BotSharp.Abstraction/Graph/Responses/GraphNodeDeleteResponse.cs deleted file mode 100644 index fb568587b..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Graph/Responses/GraphNodeDeleteResponse.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace BotSharp.Abstraction.Graph.Responses; - -public class GraphNodeDeleteResponse : ResponseBase -{ - public string? Message { get; set; } -} diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.Node.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.Node.cs deleted file mode 100644 index 529229ff4..000000000 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.Node.cs +++ /dev/null @@ -1,43 +0,0 @@ -using BotSharp.Abstraction.Graph.Options; -using BotSharp.Abstraction.Graph.Requests; -using BotSharp.Abstraction.Graph.Responses; - -namespace BotSharp.Plugin.KnowledgeBase.Graph; - -public partial class GraphKnowledgeService -{ - public async Task GetNodeAsync(string graphId, string nodeId, GraphNodeOptions? options = null) - { - var db = GetGraphDb(options?.Provider); - var result = await db.GetNodeAsync(graphId, nodeId); - return result; - } - - public async Task CreateNodeAsync(string graphId, GraphNodeCreationModel node, GraphNodeOptions? options = null) - { - var db = GetGraphDb(options?.Provider); - var result = await db.CreateNodeAsync(graphId, node); - return result; - } - - public async Task UpdateNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node, GraphNodeOptions? options = null) - { - var db = GetGraphDb(options?.Provider); - var result = await db.UpdateNodeAsync(graphId, nodeId, node); - return result; - } - - public async Task UpsertNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node, GraphNodeOptions? options = null) - { - var db = GetGraphDb(options?.Provider); - var result = await db.UpsertNodeAsync(graphId, nodeId, node); - return result; - } - - public async Task DeleteNodeAsync(string graphId, string nodeId, GraphNodeOptions? options = null) - { - var db = GetGraphDb(options?.Provider); - var result = await db.DeleteNodeAsync(graphId, nodeId); - return result; - } -} diff --git a/src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.Node.cs b/src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.Node.cs deleted file mode 100644 index 3259e0f88..000000000 --- a/src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.Node.cs +++ /dev/null @@ -1,62 +0,0 @@ -using BotSharp.Abstraction.Graph.Models; -using BotSharp.Abstraction.Graph.Requests; -using BotSharp.Abstraction.Graph.Responses; - -namespace BotSharp.Plugin.Membase.GraphDb; - -public partial class MembaseGraphDb -{ - public async Task GetNodeAsync(string graphId, string nodeId) - { - var found = await _membaseApi.GetNodeAsync(graphId, nodeId); - if (found == null) - { - return null; - } - - return new GraphNode - { - Id = found.Id, - Labels = found.Labels, - Properties = found.Properties, - Time = found.Time - }; - } - - public async Task CreateNodeAsync(string graphId, GraphNodeCreationModel node) - { - var model = NodeCreationModel.From(node); - var createdNode = await _membaseApi.CreateNodeAsync(graphId, model); - return createdNode.ToGraphNode(); - } - - public async Task UpdateNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node) - { - var model = NodeUpdateModel.From(node); - var updatedNode = await _membaseApi.UpdateNodeAsync(graphId, nodeId, model); - return updatedNode.ToGraphNode(); - } - - public async Task UpsertNodeAsync(string graphId, string nodeId, GraphNodeUpdateModel node) - { - var model = NodeUpdateModel.From(node); - var updatedNode = await _membaseApi.MergeNodeAsync(graphId, nodeId, model); - return updatedNode.ToGraphNode(); - } - - public async Task DeleteNodeAsync(string graphId, string nodeId) - { - try - { - var response = await _membaseApi.DeleteNodeAsync(graphId, nodeId); - return new GraphNodeDeleteResponse { Success = response != null, Message = response?.Message }; - } - catch (Exception ex) - { - return new GraphNodeDeleteResponse - { - ErrorMsg = ex.Message - }; - } - } -} diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Graph/Node.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Graph/Node.cs index 25bab3f79..c561558ef 100644 --- a/src/Plugins/BotSharp.Plugin.Membase/Models/Graph/Node.cs +++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Graph/Node.cs @@ -10,17 +10,6 @@ public class Node public NodeEmbedding? Embedding { get; set; } public DateTime? Time { get; set; } = DateTime.UtcNow; - public GraphNode ToGraphNode() - { - return new GraphNode - { - Id = Id, - Labels = Labels ?? [], - Properties = Properties ?? new(), - Time = Time - }; - } - public override string ToString() { var labelsString = Labels.Count > 0 ? string.Join(", ", Labels) : "No Labels"; diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs index abd038279..79213b578 100644 --- a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs +++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeCreationModel.cs @@ -1,5 +1,3 @@ -using BotSharp.Abstraction.Graph.Requests; - namespace BotSharp.Plugin.Membase.Models; public class NodeCreationModel @@ -9,22 +7,6 @@ public class NodeCreationModel public object? Properties { get; set; } public NodeEmbedding? Embedding { get; set; } public DateTime? Time { get; set; } - - public static NodeCreationModel From(GraphNodeCreationModel request) - { - return new NodeCreationModel - { - Id = request.Id, - Labels = request.Labels, - Properties = request.Properties, - Time = request.Time, - Embedding = request?.Embedding != null ? new NodeEmbedding - { - Model = request.Embedding.Model, - Vector = request.Embedding.Vector - } : null - }; - } } public class NodeEmbedding diff --git a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs index 2de701664..153d8dcf8 100644 --- a/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs +++ b/src/Plugins/BotSharp.Plugin.Membase/Models/Requests/NodeUpdateModel.cs @@ -1,5 +1,3 @@ -using BotSharp.Abstraction.Graph.Requests; - namespace BotSharp.Plugin.Membase.Models; public class NodeUpdateModel @@ -9,20 +7,4 @@ public class NodeUpdateModel public object? Properties { get; set; } public NodeEmbedding? Embedding { get; set; } public DateTime? Time { get; set; } - - public static NodeUpdateModel From(GraphNodeUpdateModel request) - { - return new NodeUpdateModel - { - Id = request.Id, - Labels = request.Labels, - Properties = request.Properties, - Time = request.Time, - Embedding = request?.Embedding != null ? new NodeEmbedding - { - Model = request.Embedding.Model, - Vector = request.Embedding.Vector - } : null - }; - } } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs index 87aa21566..380e9b703 100644 --- a/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs +++ b/src/Plugins/BotSharp.Plugin.Membase/Services/MembaseService.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Graph.Models; +using BotSharp.Plugin.Membase.Models.Graph; namespace BotSharp.Plugin.Membase.Services; @@ -29,7 +30,7 @@ public async Task Execute(string graphId, string query, Dictio }; } - public async Task MergeNode(string graphId, GraphNode node) + public async Task MergeNode(string graphId, Node node) { var newNode = await _membase.MergeNodeAsync(graphId, node.Id, new NodeUpdateModel {