Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

typesense-dotnet

> 编程语言
Open source

.NET HTTP client for Typesense.

197 stars0 likes1 views
WebsiteGitHub

About

.NET HTTP client for Typesense.

Typesense-dotnet

.net client for Typesense.

You can get the NuGet package here.

Feel free to make issues or create pull requests if you find any bugs or there are missing features.

Setup

Setup in service collection so it can be dependency injected. The AddTypesenseClient can be found in the Typesense.Setup namespace. Remember to change the settings to match your Typesense service. Right now you can specify multiple nodes, but the implementation has not been completed yet, so if you want to use this for multiple nodes, then put a load balancer in front of your services and point the settings to your load balancer. If you are using externally hosted Typesense, like Typesense Cloud, it is recommended to enable HTTP compression to lower response times and reduce traffic.

csharp
var provider = new ServiceCollection()
    .AddTypesenseClient(config =>
    {
        config.ApiKey = "mysecretapikey";
        config.SearchApiKey = "mysearchonlyapikey"; // optional
        config.Nodes = new List
        {
            new Node("localhost", "8108", "http")
        };
    }, enableHttpCompression: false).BuildServiceProvider();

After that you can get it from the provider instance or dependency inject it.

csharp
var typesenseClient = provider.GetService();

Create collection

When you create the collection, you can specify each field with name, type and if it should be a facet, an optional or an indexed field.

csharp
var schema = new Schema(
    "Addresses",
    new List
    {
        new Field("id", FieldType.Int32, false),
        new Field("houseNumber", FieldType.Int32, false),
        new Field("accessAddress", FieldType.String, false, true),
        new Field("metadataNotes", FieldType.String, false, true, false),
    },
    "houseNumber");

var createCollectionResult = await typesenseClient.CreateCollection(schema);

The example uses camelCase by default for field names, but you override this on the document you want to insert. Below is an example using snake_case.

csharp
public class Address
{
    [JsonPropertyName("id")]
    public string Id { get; set; }
    [JsonPropertyName("house_number")]
    public int HouseNumber { get; set; }
    [JsonPropertyName("access_address")]
    public string AccessAddress { get; set; }
    [JsonPropertyName("metadata_notes")]
    public string MetadataNotes { get; set; }
}

Update collection

Update existing collection.

csharp
var updateSchema = new UpdateSchema(new List
{
    // Example deleting existing field.
    new UpdateSchemaField("metadataNotes", drop: true),
    // Example adding a new field.
    new UpdateSchemaField("city", FieldType.String, facet: false, optional: true)
});

var updateCollectionResponse = await typesenseClient.UpdateCollection("Addresses", updateSchema);

Index document

csharp
var address = new Address
{
    Id = 1,
    HouseNumber = 2,
    AccessAddress = "Smedgade 25B"
};

var createDocumentResult = await typesenseClient.CreateDocument("Addresses", address);

Upsert document

csharp
var address = new Address
{
    Id = 1,
    HouseNumber = 2,
    AccessAddress = "Smedgade 25B"
};

var upsertResult = await typesenseClient.UpsertDocument("Addresses", address);

Search document in collection

csharp
var query = new SearchParameters("Smed", "accessAddress");
var searchResult = await typesenseClient.Search("Addresses", query);

Search grouped

csharp
var query = new GroupedSearchParameters("Stark", "company_name", "country");
var response = await _client.SearchGrouped("companies", query);

Multi search documents

Multi search goes from one query to four, if you need more than that please open an issue and I'll implement more.

Example of using a single query in multi-search.

csharp
var query = new MultiSearchParameters("companies", "Stark", "company_name");

var response = await _client.MultiSearch(queryOne);

Example of using two queries in multi-search.

csharp
var queryOne = new MultiSearchParameters("companies", "Stark", "company_name");
var queryTwo = new MultiSearchParameters("employees", "Kenny", "person_name");

var (r1, r2) = await _client.MultiSearch(queryOne, queryTwo);

Example of using a three queries in multi-search (you get the pattern currently it goes up to four.).

csharp
var queryOne = new MultiSearchParameters("companies", "Stark", "company_name");
var queryTwo = new MultiSearchParameters("employees", "Kenny", "person_name");
var queryThree = new MultiSearchParameters("companies", "Awesome Corp.", "company_name");

var (r1, r2, r3) = await _client.MultiSearch(queryOne, queryTwo, queryThree);

Search with Scoped Search key

csharp
var searchResults = await _client
    .WithSearchScope(new ScopedSearchParameters { CacheTtl = 10 })
    .MultiSearch(searchParameters);

Note To use the WithSearchScope method, the SearchApiKey property in the Config object must be set. The key must only have the documents:search permission and no other permissions.

Note: The cache_ttl parameter can only be set and enforced via a scoped search key. If passed directly in search parameters, its value will be ignored and the default of 60 (seconds) will be used instead.

Vector search

Typesense supports the ability to add embeddings generated by your Machine Learning models to each document, and then doing a nearest-neighbor search on them. This lets you build features like similarity search, recommendations, semantic search, visual search, etc. Here is an example of how to create a vector schema, a vector document, and perform a multi search using a vector as a query parameter.

…

Retrieve a document on id

csharp
var retrievedDocument = await typesenseClient.RetrieveDocument("Addresses", "1");

Update document on id

csharp
var address = new Address
{
    Id = 1,
    HouseNumber = 2,
    AccessAddress = "Smedgade 25B"
};

var updateDocumentResult = await typesenseClient.UpdateDocument("Addresses", "1", address);

Delete document on id

csharp
var deleteResult = await typesenseClient.DeleteDocument("Addresses", "1");

Update documents using filter

csharp
var updateResult = await typesenseClient.UpdateDocuments("Addresses", "houseNumber:=2", { "accessAddress": "Smedgade 25C" });

Delete documents using filter

csharp
var deleteResult = await typesenseClient.DeleteDocuments("Addresses", "houseNumber:>=3", 100);

Drop a collection on name

csharp
var deleteCollectionResult = await typesenseClient.DeleteCollection("Addresses");

Import documents

The default batch size is 40. The default ImportType is Create. You can pick between three different import types Create, Upsert, Update. The returned values are a list of ImportResponse that contains a success code, error and the failed document as a string representation.

csharp

var importDocumentResults = await typesenseClient.ImportDocuments("Addresses", addresses, 40, ImportType.Create);

Export documents

csharp
var addresses = await typesenseClient.ExportDocuments("Addresses");

Api keys

Create key

ExpiresAt is optional. Value is optional.

csharp
var apiKey = new Key(
    "Example key one",
    new[] { "*" },
    new[] { "*" });

var createdKey = await typesenseClient.CreateKey(apiKey);

Retrieve key

csharp
var retrievedKey = await typesenseClient.RetrieveKey(0);

List keys

csharp
var keys = await typesenseClient.ListKeys();

Delete key

csharp
var deletedKey = await typesenseClient.DeleteKey(0);

Generate Scoped Search key

csharp
var scopedSearchKey = typesenseClient.GenerateScopedSearchKey("MainOrParentAPIKey", "{\"filter_by\":\"accessible_to_user_ids:2\"}");

Curation

While Typesense makes it really easy and intuitive to deliver great search results, sometimes you might want to promote certain documents over others. Or, you might want to exclude certain documents from a query's result set.

Using overrides, you can include or exclude specific documents for a given query.

Upsert

csharp
var searchOverride = new SearchOverride(new List { new Include("2", 1) }, new Rule("Sul", "exact"));
var upsertSearchOverrideResponse = await typesenseClient.UpsertSearchOverride("Addresses", "addresses-override", searchOverride);

List all overrides

csharp
var listSearchOverrides = await typesenseClient.ListSearchOverrides("Addresses");

Retrieve overrides

csharp
var retrieveSearchOverride = await typesenseClient.RetrieveSearchOverride("Addresses", "addresses-override");

Delete override

csharp
var deletedSearchOverrideResult = await typesenseClient.DeleteSearchOverride("Addresses", "addresses-override");

Collection alias

An alias is a virtual collection name that points to a real collection. Read more here.

Upsert collection alias

csharp
var upsertCollectionAlias = await typesenseClient.UpsertCollectionAlias("Address_Alias", new CollectionAlias("Addresses"));

List all collection aliases

csharp
var listCollectionAliases = await typesenseClient.ListCollectionAliases();

Retrieve collection alias

csharp
var retrieveCollectionAlias = await typesenseClient.RetrieveCollectionAlias("Address_Alias");

Delete collection alias

csharp
var deleteCollectionAlias = await typesenseClient.DeleteCollectionAlias("Addresses_Alias");

Synonyms

The synonyms feature allows you to define search terms that should be considered equivalent. For eg: when you define a synonym for sneaker as shoe, searching for sneaker will now return all records with the word shoe in them, in addition to records with the word sneaker. Read more here.

Upsert synonym

csharp
var upsertSynonym = await typesenseClient.UpsertSynonym("Addresses", "Address_Synonym", new SynonymSchema(new List { "Sultan", "Soltan", "Softan" }));

Retrieve a synonym

csharp
var retrieveSynonym = await typesenseClient.RetrieveSynonym("Addresses", "Address_Synonym");

List all synonyms

csharp
var listSynonyms = await typesenseClient.ListSynonyms("Addresses");

Delete synonym

csharp
var deleteSynonym = await typesenseClient.DeleteSynonym("Addresses", "Address_Synonym");

Metrics

Get current RAM, CPU, Disk & Network usage metrics.

csharp
var metrics = await typesenseClient.RetrieveMetrics();

Stats

Get stats about API endpoints.

csharp
var stats = await typesenseClient.RetrieveStats();

Health

Get stats about API endpoints.

csharp
var health = await typesenseClient.RetrieveHealth();

Snapshot

Asynchronously initiates a snapshot operation on the Typesense server.

csharp
var snapshotResponse = await typesenseClient.CreateSnapshot("/my_snapshot_path");

Disk Compaction

Asynchronously initiates the running of a compaction of the underlying RocksDB database.

csharp
var diskCompactionResponse = await typesenseClient.CompactDisk();

Typesense API Errors

Typesense API exceptions in the Typesense-api-errors spec.

Type Description
TypesenseApiException Base exception type for Typesense api exceptions.
TypesenseApiBadRequestException Bad Request - The request could not be understood due to malformed syntax.
TypesenseApiUnauthorizedException Unauthorized - Your API key is wrong.
TypesenseApiNotFoundException Not Found - The requested resour

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#dotnettypesense

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言