RedisVL.Vectorizers.HuggingFace
0.1.0
dotnet add package RedisVL.Vectorizers.HuggingFace --version 0.1.0
NuGet\Install-Package RedisVL.Vectorizers.HuggingFace -Version 0.1.0
<PackageReference Include="RedisVL.Vectorizers.HuggingFace" Version="0.1.0" />
<PackageVersion Include="RedisVL.Vectorizers.HuggingFace" Version="0.1.0" />
<PackageReference Include="RedisVL.Vectorizers.HuggingFace" />
paket add RedisVL.Vectorizers.HuggingFace --version 0.1.0
#r "nuget: RedisVL.Vectorizers.HuggingFace, 0.1.0"
#:package RedisVL.Vectorizers.HuggingFace@0.1.0
#addin nuget:?package=RedisVL.Vectorizers.HuggingFace&version=0.1.0
#tool nuget:?package=RedisVL.Vectorizers.HuggingFace&version=0.1.0
redis-vl-dotnet
redis-vl-dotnet is a .NET-native Redis Vector Library for Redis Search and vector workloads. It gives you a fluent, strongly-typed API over Redis Query Engine so you can define schemas, index HASH or JSON documents, and run vector, full-text, filter, hybrid, and aggregation queries — plus higher-level building blocks for GenAI apps such as semantic caching, semantic routing, embeddings caching, and semantic message history.
It is the .NET sibling of redis-vl-python, built on top of StackExchange.Redis.
Preview: redis-vl-dotnet is pre-1.0 and under active development. APIs may change between releases; pin an exact package version and review the CHANGELOG before upgrading.
Features
- Schema and index management — define indexes in code or load them from YAML, create/drop/list indexes, and reconnect to existing ones.
- Document storage — store and fetch strongly-typed records over HASH or JSON, with partial updates.
- Query types — nearest-neighbor
VectorQuery,MultiVectorQuery, vector range queries,FilterQuery,TextQuery,AggregationQuery, and nativeFT.HYBRIDHybridSearchQuery(Redis 8.4+). - Fluent filters — compose tag, text, numeric, and geo predicates with
&,|, and negation. - Vector indexing options — FLAT, HNSW, and SVS-VAMANA algorithms, with LVQ / LeanVec compression.
- GenAI extensions —
SemanticCache,SemanticRouter,EmbeddingsCache, and semantic message history. - Pluggable vectorizers and rerankers — OpenAI, Cohere, Hugging Face, local ONNX, and
Microsoft.Extensions.AIadapters, shipped as separate packages. - Ecosystem connectors — a
Microsoft.Extensions.VectorData/ Semantic Kernel vector-store connector.
Requirements
- A supported .NET runtime: the packages multi-target .NET 8 (LTS), .NET 9, and .NET 10 (LTS).
- A Redis deployment with the Redis Query Engine (
RediSearch) module — Redis 8 or Redis Cloud. RedisJSONfor JSON-backed document workflows (included in Redis 8).- Redis 8.4+ for native
FT.HYBRIDhybrid search.
You can start a local Redis with everything enabled via Docker:
docker run -d --name redis -p 6379:6379 redis:8
Installation
Install the core package from NuGet:
dotnet add package RedisVL
Add extension packages only as you need them:
| Package | Purpose |
|---|---|
RedisVL |
Core library: schema, indexes, documents, queries, caches, routers |
RedisVL.Vectorizers.OpenAI |
OpenAI-backed embeddings |
RedisVL.Vectorizers.Cohere |
Cohere-backed embeddings |
RedisVL.Vectorizers.HuggingFace |
Hugging Face inference API embeddings |
RedisVL.Vectorizers.Onnx |
Local/offline ONNX SentenceTransformers embeddings |
RedisVL.Vectorizers.ExtensionsAI |
Adapter for any Microsoft.Extensions.AI IEmbeddingGenerator |
RedisVL.Rerankers.Cohere |
Cohere reranking |
RedisVL.Rerankers.Onnx |
Local/offline ONNX cross-encoder reranking |
RedisVL.Connectors.VectorData |
Microsoft.Extensions.VectorData / Semantic Kernel vector-store connector |
Quick start
The core flow is: connect to Redis, define a schema, create the index, load documents, then query.
using RedisVL.Filters;
using RedisVL.Indexes;
using RedisVL.Queries;
using RedisVL.Schema;
using StackExchange.Redis;
// 1. Connect to Redis (StackExchange.Redis).
using var redis = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var database = redis.GetDatabase();
// 2. Define a schema: an index over the "movies:" keyspace with a 2-dim vector field.
var schema = new SearchSchema(
new IndexDefinition("movies-idx", "movies:", StorageType.Hash),
[
new TagFieldDefinition("genre"),
new TextFieldDefinition("title"),
new VectorFieldDefinition(
"embedding",
new VectorFieldAttributes(
VectorAlgorithm.Hnsw,
VectorDataType.Float32,
VectorDistanceMetric.Cosine,
dimensions: 2,
m: 16,
efConstruction: 200))
]);
// 3. Create the index (dropping any existing one with the same name).
var index = new SearchIndex(database, schema);
await index.CreateAsync(new CreateIndexOptions(overwrite: true, dropExistingDocuments: true));
// 4. Load documents. Here we write HASHes directly; in real apps embeddings come from a vectorizer.
static byte[] EncodeFloat32(float[] vector)
{
var bytes = new byte[vector.Length * sizeof(float)];
Buffer.BlockCopy(vector, 0, bytes, 0, bytes.Length);
return bytes;
}
await database.HashSetAsync("movies:heat", new HashEntry[]
{
new("title", "Heat"),
new("genre", "crime"),
new("embedding", EncodeFloat32(new[] { 1f, 0f }))
});
// 5. Run a nearest-neighbor query, filtered to the "crime" genre.
var query = VectorQuery.FromFloat32(
fieldName: "embedding",
vector: new[] { 1f, 0f },
topK: 3,
filter: Filter.Tag("genre").Eq("crime"),
returnFields: ["title"],
scoreAlias: "distance");
var results = await index.SearchAsync(query);
foreach (var doc in results.Documents)
{
Console.WriteLine($"{doc.Values["title"]} (distance={doc.Values["distance"]})");
}
Redis expects vector fields as raw little-endian float32 bytes, hence the
EncodeFloat32helper. See VectorSearchExample for a complete, runnable version.
JSON documents
Prefer JSON storage when you want to work with strongly-typed POCOs and JSONPath partial updates:
var schema = SearchSchema.FromYamlFile("schema.yaml"); // or build in code
var index = new SearchIndex(database, schema);
await index.CreateAsync(new CreateIndexOptions(overwrite: true));
var movies = new[]
{
new Movie("movie-1", "Heat", 1995, "crime"),
new Movie("movie-2", "Arrival", 2016, "science-fiction")
};
await index.LoadJsonAsync(movies);
var arrival = await index.FetchJsonByIdAsync<Movie>("movie-2");
// Filter + text queries, projected onto a type
var query = new FilterQuery(
Filter.And(
Filter.Tag("genre").Eq("science-fiction"),
Filter.Numeric("year").GreaterThan(1980)),
returnFields: ["title", "year", "genre"]);
var scienceFiction = await index.SearchAsync<Movie>(query);
Generating embeddings with a vectorizer
Vectorizer packages implement IBatchTextVectorizer, so you can turn text into embeddings and feed them to any query or cache:
using RedisVL.Vectorizers.OpenAI;
var vectorizer = new OpenAiTextVectorizer(
model: "text-embedding-3-small",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
new OpenAiVectorizerOptions { Dimensions = 256 });
float[] embedding = await vectorizer.VectorizeAsync("A linguist decodes an alien language.");
IReadOnlyList<float[]> batch = await vectorizer.VectorizeAsync(["first prompt", "second prompt"]);
Semantic cache
SemanticCache stores prompt/response pairs keyed by embedding similarity, so repeated (or paraphrased) prompts return a cached answer instead of hitting your LLM:
using RedisVL.Caches;
using RedisVL.Schema;
var cache = new SemanticCache(
database,
new SemanticCacheOptions(
"semantic-cache-example",
new VectorFieldAttributes(
VectorAlgorithm.Flat, VectorDataType.Float32, VectorDistanceMetric.Cosine, dimensions: 3),
distanceThreshold: 0.2d,
timeToLive: TimeSpan.FromMinutes(10)));
await cache.CreateAsync();
await cache.StoreAsync(
prompt: "How do I reset my password?",
response: "Open Settings > Security > Reset password and follow the email link.",
embedding: new[] { 1f, 0f, 0f });
// A near-identical embedding returns the cached response.
var hit = await cache.CheckAsync(prompt: "How do I reset my password?", embedding: new[] { 1f, 0f, 0f });
Console.WriteLine(hit?.Response);
Connecting to a cluster
RedisVL operates on a StackExchange.Redis IDatabase, so any connection you can build works. For cluster topologies, the RedisConnectionFactory helpers normalize seed-node lists and build ConfigurationOptions for you:
ConnectClusterAsync(...)— cluster discoveryCreateClusterOptions(...)— parsed option builder
Examples
The examples/ directory contains runnable projects for every feature area. Run any of them from the repository root, for example:
dotnet run --project examples/VectorSearchExample/VectorSearchExample.csproj
Highlights:
| Area | Example |
|---|---|
| JSON schema, load, fetch, filter/text/aggregate queries | JsonStorageExample |
| Vector KNN, multi-vector, runtime tuning | VectorSearchExample |
| SVS-VAMANA index + vector compression | SvsVamanaExample |
Native FT.HYBRID hybrid search |
HybridSearchExample |
| Semantic cache | SemanticCacheExample |
| Semantic router | SemanticRouterExample |
| Embeddings cache | EmbeddingsCacheExample |
| Semantic message history | MessageHistoryExample |
| OpenAI / Cohere / Hugging Face / ONNX vectorizers | OpenAiVectorizerExample, CohereVectorizerExample, HuggingFaceVectorizerExample, OnnxVectorizerExample |
| Cohere / ONNX rerankers | CohereRerankerExample, OnnxRerankerExample |
| Microsoft.Extensions.VectorData / Semantic Kernel connector | VectorDataConnectorExample, SemanticKernelConnectorExample |
Documentation
Full documentation lives in the Antora docs site source:
- Overview
- Getting Started — installation, connection topologies, environment variables
- Core Features — schema, indexes, documents, queries
- Extensions — vectorizers, rerankers, connectors
- Testing
Build the docs locally from the repository root:
npm install
npm run docs:validate
Contributing
Issues and pull requests are welcome. The solution file is redis-vl-dotnet.sln; build and test with the standard dotnet CLI:
dotnet build redis-vl-dotnet.sln
dotnet test
Integration tests need a reachable Redis with the Query Engine enabled. See Testing for details.
| 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. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- RedisVL.Vectorizers.Abstractions (>= 0.1.0)
-
net8.0
- RedisVL.Vectorizers.Abstractions (>= 0.1.0)
-
net9.0
- RedisVL.Vectorizers.Abstractions (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.