VENative.ChromaDB.Client
9.0.1
See the version list below for details.
dotnet add package VENative.ChromaDB.Client --version 9.0.1
NuGet\Install-Package VENative.ChromaDB.Client -Version 9.0.1
<PackageReference Include="VENative.ChromaDB.Client" Version="9.0.1" />
paket add VENative.ChromaDB.Client --version 9.0.1
#r "nuget: VENative.ChromaDB.Client, 9.0.1"
// Install VENative.ChromaDB.Client as a Cake Addin #addin nuget:?package=VENative.ChromaDB.Client&version=9.0.1 // Install VENative.ChromaDB.Client as a Cake Tool #tool nuget:?package=VENative.ChromaDB.Client&version=9.0.1
VENative.ChromaDB.Client
VENative.ChromaDB.Client 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.
Nuget
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.
}
}
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);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 is compatible. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.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.