Skip to content

Commit 799f182

Browse files
committed
Add Membase plugin - a document graph vector database.
1 parent e3c66a9 commit 799f182

File tree

15 files changed

+248
-3
lines changed

15 files changed

+248
-3
lines changed

BotSharp.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 18
4-
VisualStudioVersion = 18.0.11217.181 d18.0
4+
VisualStudioVersion = 18.0.11217.181
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{E29DC6C4-5E57-48C5-BCB0-6B8F84782749}"
77
EndProject
@@ -149,6 +149,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.ImageHandle
149149
EndProject
150150
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.FuzzySharp", "src\Plugins\BotSharp.Plugin.FuzzySharp\BotSharp.Plugin.FuzzySharp.csproj", "{E7C243B9-E751-B3B4-8F16-95C76CA90D31}"
151151
EndProject
152+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.Membase", "src\Plugins\BotSharp.Plugin.Membase\BotSharp.Plugin.Membase.csproj", "{13223C71-9EAC-9835-28ED-5A4833E6F915}"
153+
EndProject
152154
Global
153155
GlobalSection(SolutionConfigurationPlatforms) = preSolution
154156
Debug|Any CPU = Debug|Any CPU
@@ -629,6 +631,14 @@ Global
629631
{E7C243B9-E751-B3B4-8F16-95C76CA90D31}.Release|Any CPU.Build.0 = Release|Any CPU
630632
{E7C243B9-E751-B3B4-8F16-95C76CA90D31}.Release|x64.ActiveCfg = Release|Any CPU
631633
{E7C243B9-E751-B3B4-8F16-95C76CA90D31}.Release|x64.Build.0 = Release|Any CPU
634+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
635+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Debug|Any CPU.Build.0 = Debug|Any CPU
636+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Debug|x64.ActiveCfg = Debug|Any CPU
637+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Debug|x64.Build.0 = Debug|Any CPU
638+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Release|Any CPU.ActiveCfg = Release|Any CPU
639+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Release|Any CPU.Build.0 = Release|Any CPU
640+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Release|x64.ActiveCfg = Release|Any CPU
641+
{13223C71-9EAC-9835-28ED-5A4833E6F915}.Release|x64.Build.0 = Release|Any CPU
632642
EndGlobalSection
633643
GlobalSection(SolutionProperties) = preSolution
634644
HideSolutionNode = FALSE
@@ -701,6 +711,7 @@ Global
701711
{FC63C875-E880-D8BB-B8B5-978AB7B62983} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
702712
{242F2D93-FCCE-4982-8075-F3052ECCA92C} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
703713
{E7C243B9-E751-B3B4-8F16-95C76CA90D31} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
714+
{13223C71-9EAC-9835-28ED-5A4833E6F915} = {53E7CD86-0D19-40D9-A0FA-AB4613837E89}
704715
EndGlobalSection
705716
GlobalSection(ExtensibilityGlobals) = postSolution
706717
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

Directory.Packages.props

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
<PackageVersion Include="System.Threading.Channels" Version="10.0.0" />
8181
<PackageVersion Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.8" />
8282
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
83-
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
8483
<PackageVersion Include="Serilog.Sinks.OpenTelemetry" Version="4.2.0" />
8584
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.0.0" />
8685
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.0.0" />
@@ -139,6 +138,7 @@
139138
<PackageVersion Include="Microsoft.OpenApi" Version="3.0.1" />
140139
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="10.0.0" />
141140
<PackageVersion Include="System.Text.Json" Version="10.0.0" />
141+
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
142142
<PackageVersion Include="Serilog.Extensions.Logging" Version="10.0.0" />
143143
</ItemGroup>
144144
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
@@ -163,7 +163,8 @@
163163
<PackageVersion Include="Microsoft.OpenApi" Version="2.3.10" />
164164
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
165165
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
166-
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.2" />
166+
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
167+
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
167168
</ItemGroup>
168169
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
169170
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
@@ -186,6 +187,7 @@
186187
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.26" />
187188
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="6.0.5" />
188189
<PackageVersion Include="System.Text.Json" Version="6.0.11" />
190+
<PackageVersion Include="Serilog.Extensions.Hosting" Version="7.0.0" />
189191
<PackageVersion Include="Serilog.Extensions.Logging" Version="7.0.0" />
190192
</ItemGroup>
191193
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace BotSharp.Abstraction.MLTasks;
2+
3+
/// <summary>
4+
/// Interface for text reranking services.
5+
/// Reranking is used to improve search results by scoring query-document pairs
6+
/// using more sophisticated models (e.g., cross-encoders, vector embeddings) than initial retrieval.
7+
/// </summary>
8+
public interface ITextReranking
9+
{
10+
/// <summary>
11+
/// The provider name (e.g., "google-ai", "cohere", "jina", "local").
12+
/// </summary>
13+
string Provider { get; }
14+
15+
/// <summary>
16+
/// The model name (e.g., "gemma3-reranker", "rerank-english-v2.0", "jina-reranker-v1").
17+
/// </summary>
18+
string Model { get; }
19+
20+
/// <summary>
21+
/// Rerank a single query-document pair and return the relevance score.
22+
/// </summary>
23+
/// <param name="query">The search query</param>
24+
/// <param name="document">The document text to score</param>
25+
/// <returns>Relevance score (typically between 0 and 1, higher is more relevant)</returns>
26+
Task<float> GetRerankScoreAsync(string query, string document);
27+
28+
/// <summary>
29+
/// Rerank multiple documents for a given query and return their relevance scores.
30+
/// </summary>
31+
/// <param name="query">The search query</param>
32+
/// <param name="documents">List of document texts to score</param>
33+
/// <returns>List of relevance scores in the same order as input documents</returns>
34+
Task<List<float>> GetRerankScoresAsync(string query, List<string> documents);
35+
36+
/// <summary>
37+
/// Rerank multiple documents and return them sorted by relevance score.
38+
/// </summary>
39+
/// <param name="query">The search query</param>
40+
/// <param name="documents">List of document texts to rerank</param>
41+
/// <param name="topK">Number of top results to return (optional, returns all if not specified)</param>
42+
/// <returns>List of (document, score) tuples sorted by relevance (highest first)</returns>
43+
Task<List<(string Document, float Score)>> RerankDocumentsAsync(string query, List<string> documents, int? topK = null);
44+
45+
/// <summary>
46+
/// Set the model name to use for reranking.
47+
/// </summary>
48+
/// <param name="model">Model name</param>
49+
void SetModelName(string model);
50+
}
51+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(TargetFramework)</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>$(LangVersion)</LangVersion>
7+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
8+
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
9+
<OutputPath>$(SolutionDir)packages</OutputPath>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Refit" />
14+
<PackageReference Include="Refit.HttpClientFactory" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace BotSharp.Plugin.Membase.Controllers;
2+
3+
[Authorize]
4+
[ApiController]
5+
public class MembaseController : ControllerBase
6+
{
7+
private readonly IUserIdentity _user;
8+
private readonly IServiceProvider _services;
9+
10+
public MembaseController(
11+
IUserIdentity user,
12+
IServiceProvider services)
13+
{
14+
_user = user;
15+
_services = services;
16+
}
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using BotSharp.Abstraction.Plugins;
2+
using BotSharp.Abstraction.Settings;
3+
using BotSharp.Plugin.Membase.Services;
4+
using BotSharp.Plugin.Membase.Settings;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Refit;
8+
using System.Threading.Tasks;
9+
10+
namespace BotSharp.Plugin.Membase;
11+
12+
public class MembasePlugin : IBotSharpPlugin
13+
{
14+
public string Id => "8df12767-9a44-45d9-93cd-12a10adf3933";
15+
public string Name => "Membase";
16+
public string Description => "Document Database with Graph Traversal & Vector Search.";
17+
public string IconUrl => "https://membase.dev/favicon.png";
18+
19+
public void RegisterDI(IServiceCollection services, IConfiguration config)
20+
{
21+
var dbSettings = new MembaseSettings();
22+
config.Bind("Membase", dbSettings);
23+
services.AddSingleton(sp => dbSettings);
24+
25+
services
26+
.AddRefitClient<IMembaseApi>(new RefitSettings
27+
{
28+
AuthorizationHeaderValueGetter = (message, cancellation) =>
29+
Task.FromResult($"Bearer {dbSettings.ApiKey}")
30+
})
31+
.ConfigureHttpClient(c => c.BaseAddress = new Uri(dbSettings.Host));
32+
}
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace BotSharp.Plugin.Membase.Models;
9+
10+
public class Node
11+
{
12+
public string Id { get; set; } = string.Empty;
13+
14+
public List<string> Labels { get; set; } = new();
15+
16+
public Dictionary<string, object> Properties { get; set; } = new();
17+
18+
public DateTime Time { get; set; } = DateTime.UtcNow;
19+
20+
public override string ToString()
21+
{
22+
var labelsString = Labels.Count > 0 ? string.Join(", ", Labels) : "No Labels";
23+
return $"Node ({labelsString}: {Id})";
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BotSharp.Plugin.Membase.Models;
2+
3+
public class NodeCreationModel
4+
{
5+
public string? Id { get; set; }
6+
public string[]? Labels { get; set; }
7+
public Dictionary<string, object>? Properties { get; set; }
8+
9+
public Node ToNode()
10+
{
11+
return new Node
12+
{
13+
Id = Id,
14+
Labels = Labels?.ToList() ?? new List<string>(),
15+
Properties = Properties ?? new Dictionary<string, object>(),
16+
Time = DateTime.UtcNow
17+
};
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BotSharp.Plugin.Membase.Models;
2+
3+
public class NodeUpdateModel
4+
{
5+
public string Id { get; set; } = null!;
6+
public string[]? Labels { get; set; }
7+
public Dictionary<string, object>? Properties { get; set; }
8+
9+
public Node ToNode()
10+
{
11+
return new Node
12+
{
13+
Id = Id,
14+
Labels = Labels?.ToList() ?? new List<string>(),
15+
Properties = Properties ?? new Dictionary<string, object>(),
16+
Time = DateTime.UtcNow
17+
};
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using BotSharp.Plugin.Membase.Models;
2+
using Refit;
3+
using System.Threading.Tasks;
4+
5+
namespace BotSharp.Plugin.Membase.Services;
6+
7+
public interface IMembaseApi
8+
{
9+
[Post("/graph/{graphId}/node")]
10+
Task CreateNode(string graphId, [Body] NodeCreationModel node);
11+
12+
[Get("/graph/{graphId}/node/{nodeId}")]
13+
Task<Node> GetNode(string graphId, string nodeId);
14+
15+
[Put("/graph/{graphId}/node/{nodeId}")]
16+
Task<Node> UpdateNode(string graphId, string nodeId, [Body] NodeUpdateModel node);
17+
18+
[Delete("/graph/{graphId}/node/{nodeId}")]
19+
Task<IActionResult> DeleteNode(string graphId, string nodeId);
20+
}

0 commit comments

Comments
 (0)