Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IGraphDb
{
public string Provider { get; }

Task<GraphSearchResult> SearchAsync(string query, GraphSearchOptions? options = null)
Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
=> throw new NotImplementedException();

#region Node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BotSharp.Abstraction.Graph;

public interface IGraphKnowledgeService
{
Task<GraphSearchResult> SearchAsync(string query, GraphSearchOptions? options = null);
Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryOptions? options = null);

#region Node
Task<GraphNode?> GetNodeAsync(string graphId, string nodeId, GraphNodeOptions? options = null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BotSharp.Abstraction.Graph.Models;

public class GraphSearchResult
public class GraphQueryResult
{
public string Result { get; set; } = string.Empty;
public string[] Keys { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace BotSharp.Abstraction.Graph.Options;

public class GraphSearchOptions
public class GraphQueryOptions : GraphQueryExecuteOptions
{
public string Provider { get; set; }
}

public class GraphQueryExecuteOptions
{
public string? Provider { get; set; }
public string? GraphId { get; set; }
public Dictionary<string, object>? Arguments { get; set; }
public string? Method { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ public async Task<bool> DeleteVectorCollectionSnapshots([FromRoute] string colle
[HttpPost("/knowledge/graph/search")]
public async Task<GraphKnowledgeViewModel> SearchGraphKnowledge([FromBody] SearchGraphKnowledgeRequest request)
{
var options = new GraphSearchOptions
var options = new GraphQueryOptions
{
Provider = request.Provider,
GraphId = request.GraphId,
Arguments = request.Arguments,
Method = request.Method
};

var result = await _graphKnowledgeService.SearchAsync(request.Query, options);
var result = await _graphKnowledgeService.ExecuteQueryAsync(request.Query, options);
return new GraphKnowledgeViewModel
{
Result = result.Result
Expand Down
10 changes: 5 additions & 5 deletions src/Plugins/BotSharp.Plugin.Graph/GraphDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public GraphDb(

public string Provider => "Remote";

public async Task<GraphSearchResult> SearchAsync(string query, GraphSearchOptions? options = null)
public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
{
if (string.IsNullOrWhiteSpace(_settings.BaseUrl))
{
return new GraphSearchResult();
return new GraphQueryResult();
}

var url = $"{_settings.BaseUrl}{_settings.SearchPath}";
Expand All @@ -56,9 +56,9 @@ public async Task<GraphSearchResult> SearchAsync(string query, GraphSearchOption


#region Private methods
private async Task<GraphSearchResult> SendRequest(string url, GraphQueryRequest request)
private async Task<GraphQueryResult> SendRequest(string url, GraphQueryRequest request)
{
var result = new GraphSearchResult();
var result = new GraphQueryResult();
var http = _services.GetRequiredService<IHttpClientFactory>();

using (var client = http.CreateClient())
Expand All @@ -79,7 +79,7 @@ private async Task<GraphSearchResult> SendRequest(string url, GraphQueryRequest
rawResponse.EnsureSuccessStatusCode();

var responseStr = await rawResponse.Content.ReadAsStringAsync();
result = JsonSerializer.Deserialize<GraphSearchResult>(responseStr, _jsonOptions);
result = JsonSerializer.Deserialize<GraphQueryResult>(responseStr, _jsonOptions);
return result;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public GraphKnowledgeService(
_settings = settings;
}

public async Task<GraphSearchResult> SearchAsync(string query, GraphSearchOptions? options = null)
public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryOptions? options = null)
{
try
{
var db = GetGraphDb(options?.Provider);
var result = await db.SearchAsync(query, options);
var result = await db.ExecuteQueryAsync(query, options);
return result;
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error when searching graph knowledge (Query: {query}).");
return new GraphSearchResult();
return new GraphQueryResult();
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public async Task<List<string>> GetDomainKnowledges(RoleDialogModel message, str
{
if (knowledgeBase.Type == "relationships")
{
var options = new GraphSearchOptions
var options = new GraphQueryOptions
{
Provider = "Remote",
Method = "local"
};
var result = await _graphKnowledgeService.SearchAsync(text, options);
var result = await _graphKnowledgeService.ExecuteQueryAsync(text, options);
results.Add(result.Result);
}
else if (knowledgeBase.Type == "document")
Expand Down Expand Up @@ -89,11 +90,12 @@ public async Task<List<string>> GetGlobalKnowledges(RoleDialogModel message)
{
if (knowledgeBase.Type == "relationships")
{
var options = new GraphSearchOptions
var options = new GraphQueryOptions
{
Provider = "Remote",
Method = "local"
};
var result = await _graphKnowledgeService.SearchAsync(text, options);
var result = await _graphKnowledgeService.ExecuteQueryAsync(text, options);
results.Add(result.Result);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IActionResult> ExecuteGraphQuery(string graphId, [FromBody] Cy
try
{
var graph = _services.GetServices<IGraphDb>().First(x => x.Provider == "membase");
var result = await graph.SearchAsync(query: request.Query, options: new()
var result = await graph.ExecuteQueryAsync(query: request.Query, options: new()
{
GraphId = graphId,
Arguments = request.Parameters
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MembaseGraphDb(

public string Provider => "membase";

public async Task<GraphSearchResult> SearchAsync(string query, GraphSearchOptions? options = null)
public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
{
if (string.IsNullOrEmpty(options?.GraphId))
{
Expand All @@ -39,7 +39,7 @@ public async Task<GraphSearchResult> SearchAsync(string query, GraphSearchOption
Parameters = options.Arguments ?? new Dictionary<string, object>()
});

return new GraphSearchResult
return new GraphQueryResult
{
Keys = response.Columns,
Values = response.Data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public MembaseService(IServiceProvider services, IMembaseApi membase)
_membase = membase;
}

public async Task<GraphSearchResult> Execute(string graphId, string query, Dictionary<string, object>? args = null)
public async Task<GraphQueryResult> Execute(string graphId, string query, Dictionary<string, object>? args = null)
{
var response = await _membase.CypherQueryAsync(graphId, new CypherQueryRequest
{
Query = query,
Parameters = args ?? []
});

return new GraphSearchResult
return new GraphQueryResult
{
Keys = response.Columns,
Values = response.Data
Expand Down
Loading