ChromaDBSharp 0.0.1
dotnet add package ChromaDBSharp --version 0.0.1
NuGet\Install-Package ChromaDBSharp -Version 0.0.1
<PackageReference Include="ChromaDBSharp" Version="0.0.1" />
paket add ChromaDBSharp --version 0.0.1
#r "nuget: ChromaDBSharp, 0.0.1"
// Install ChromaDBSharp as a Cake Addin #addin nuget:?package=ChromaDBSharp&version=0.0.1 // Install ChromaDBSharp as a Cake Tool #tool nuget:?package=ChromaDBSharp&version=0.0.1
ChromaDB Sharp
ChromaDBSharp is a wrapper around the Chroma API that exposes all functionality of that API to .NET. The project follows the ChromaDB Python and JavaScript client patterns.
Library is consumed as a .net standard 2.1 library.
How to Use
ChromaDB is designed to be used against a deployed version of ChromaDB. See HERE for official documentation on how to deploy ChromaDB.
Each Chroma call features a syncronous and and asyncronous version.
// Create your HttpClient and set the base address to the chroma instance
using HttpClient client = new();
client.BaseAddress = new Uri("http://localhost:8000/"); //
Using local docker version for example.
ChromaDBClient client = new(httpClient);
// Additional options
ChromaDBClient client = new(httpClient, tenantName, databaseName);
string version = client.Version();
long heartbeat = await client.HeartbeatAsync();
- Creating a client using Dependency Injection.
... //Create app builder
builder.Services.RegisterChromaDBSharp("http://localhost:8000/");
builder.Services.RegisterChromaDBSharp(client => {
// Configure HTTP client here. For example, add authentication.
client.BaseAddress = new Uri("http://localhost:8000/");
byte[] byteArray = Encoding.ASCII.GetBytes("username:password");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
});
- Creating a collection
Collections rquire an embedding function otherwise an error will through. Define an embedding class as follows:
public sealed class CustomEmbedder : IEmbeddable
{
public Task<IEnumerable<IEnumerable<float>>> Generate(IEnumerable<string> texts)
{
// Embedding logic here
// For example, call an API, create custom c\# embedding logic, or use library. this is for demonstration only.
...
return embeddings.
}
}
For example, using AllMiniLML6v2Sharp
public sealed class AllMiniEmbedder : IEmbeddable
{
private readonly IEmbedder _embedder;
public AllMiniEmbedding()
{
_embedder = new AllMiniLmL6V2Embedder(modelPath: "path/to/model", tokenizer: new AllMiniLmL6V2Sharp.Tokenizer.BertTokenizer("path/to/vocab"));
}
public async Task<IEnumerable<IEnumerable<float>>> Generate(IEnumerable<string> texts)
{
IEnumerable<IEnumerable<float>> result = _embedder.GenerateEmbeddings(texts);
return await Task.FromResult(result);
}
}
Pass into collection when fetching.
IEmbeddable customEmbeddingFunction = new CustomEmbedder();
ICollectionClient collection = client.CreateCollection("Collection Name", metadata: new Dictionary<string, object> { {"prop1", "value 1"},{"prop2",2}}, embeddingFunction: customEmbeddingFunction);
- Add documents
collection.Add(documents: new[] { "This is document 1", "This is document 2" }, metadatas: new[] { new Dictionary<string, object> { { "source", "notion" } }, new Dictionary<string, object> { { "source", "google-docs" } } }, ids: new[] { "doc 1", "doc 2" });
- Query Documents
QueryResult result = collection.Query(queryTexts: new[] { "This is a query document" }, numberOfResults: 5);
- Query Documents with a where clause.
QueryResult result = collection.Query(queryTexts: new[] { "This is a query document" }, where: new Dictionary<string, object> {{"source", "notion"}}, numberOfResults: 5);
Example Applications
- Retrieval-Augmented Generation
- See This Project for an example of how to use ChromaDBSharp with LlamaSharp and AllMiniLML6v2Sharp for a GPT style RAG app.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.1 | 1,274 | 12/27/2023 |