![]() |
VOOZH | about |
dotnet add package Weaviate.Client.Managed --version 1.0.1
NuGet\Install-Package Weaviate.Client.Managed -Version 1.0.1
<PackageReference Include="Weaviate.Client.Managed" Version="1.0.1" />
<PackageVersion Include="Weaviate.Client.Managed" Version="1.0.1" />Directory.Packages.props
<PackageReference Include="Weaviate.Client.Managed" />Project file
paket add Weaviate.Client.Managed --version 1.0.1
#r "nuget: Weaviate.Client.Managed, 1.0.1"
#:package Weaviate.Client.Managed@1.0.1
#addin nuget:?package=Weaviate.Client.Managed&version=1.0.1Install as a Cake Addin
#tool nuget:?package=Weaviate.Client.Managed&version=1.0.1Install as a Cake Tool
A declarative ORM layer for the Weaviate C# client, providing attribute-based schema definition and type-safe LINQ-style queries.
✅ Production Ready - Complete ORM implementation with 100% feature parity with manual CollectionConfig creation.
using Weaviate.Client.Managed.Attributes;
using Weaviate.Client.Models;
[WeaviateCollection("Articles", Description = "Blog articles")]
[InvertedIndex(IndexTimestamps = true)]
public class Article
{
[Property(DataType.Text)]
[Index(Filterable = true, Searchable = true)]
[Tokenization(PropertyTokenization.Word)]
public string Title { get; set; } = string.Empty;
[Property(DataType.Text)]
[Index(Searchable = true)]
public string Content { get; set; } = string.Empty;
[Property(DataType.Int)]
[Index(Filterable = true, RangeFilters = true)]
public int WordCount { get; set; }
[Property(DataType.Date)]
[Index(Filterable = true)]
public DateTime PublishedAt { get; set; }
// Named vector - property name becomes vector name
[Vector<Vectorizer.Text2VecOpenAI>(
Model = "text-embedding-ada-002",
Dimensions = 1536,
SourceProperties = [nameof(Title), nameof(Content)]
)]
public float[]? TitleContentEmbedding { get; set; }
// Reference to another collection (target inferred from property type)
[Reference]
public Category? Category { get; set; }
}
[WeaviateCollection("Category")]
public class Category
{
[Property(DataType.Text)]
public string Name { get; set; } = string.Empty;
}
using Weaviate.Client.Managed.Extensions;
var client = new WeaviateClient(new WeaviateConfig { Host = "localhost:8080" });
// Create collection from class attributes
var collection = await client.Collections.CreateFromClass<Article>();
[WeaviateCollection] - Define collection name, description, and configuration
[InvertedIndex] - Configure inverted index settings
[Generative<TModule>] - Configure generative AI (RAG) module
[Reranker<TModule>] - Configure reranker module
[Property] - Define Weaviate property with data type
[Index] - Configure filtering, searching, and range filters
[Tokenization] - Specify tokenization strategy for text properties
[NestedType] - Define nested object structure (optional, auto-inferred)
[Vector<TVectorizer>] - Define named vector with vectorizer configuration
float[]) vs multi-vector (float[,])[VectorIndex<TIndexConfig>] - Configure vector index
[QuantizerBQ] - Binary Quantization
[QuantizerPQ] - Product Quantization
[QuantizerSQ] - Scalar Quantization
[QuantizerRQ] - Residual Quantization
[Encoding] - Multi-vector (ColBERT) encoding
[Reference] - Define cross-reference to another collection
Category?)Guid?)List<Article>?)All Weaviate data types are supported:
DataType.Text, DataType.TextArrayDataType.Int, DataType.IntArrayDataType.Number, DataType.NumberArrayDataType.Bool, DataType.BoolArrayDataType.Date, DataType.DateArrayDataType.Uuid, DataType.UuidArrayDataType.GeoCoordinateDataType.PhoneNumberDataType.BlobDataType.Object, DataType.ObjectArrayAll Weaviate vectorizers are supported via generic type parameter:
Text Vectorizers:
Vectorizer.Text2VecOpenAIVectorizer.Text2VecCohereVectorizer.Text2VecHuggingFaceVectorizer.Text2VecTransformersVectorizer.Text2VecAWSVectorizer.Text2VecGoogleVectorizer.Text2VecJinaAIVectorizer.Text2VecOllamaMulti-Modal Vectorizers:
Vectorizer.Multi2VecClipVectorizer.Multi2VecCohereVectorizer.Multi2VecBindVectorizer.Multi2VecGoogleSpecial Vectorizers:
Vectorizer.SelfProvided - For user-provided vectorsVectorizer.Ref2VecCentroid - For reference-based vectorization[WeaviateCollection("Documents")]
public class Document
{
[Property(DataType.Text)]
public string Content { get; set; } = string.Empty;
// Vector with HNSW index and BQ quantization
[Vector<Vectorizer.Text2VecOpenAI>(
Model = "text-embedding-3-large",
SourceProperties = [nameof(Content)]
)]
[VectorIndex<VectorIndexConfig.Hnsw>(
DistanceMetric = DistanceMetric.Cosine,
EfConstruction = 128,
MaxConnections = 64
)]
[QuantizerBQ(Cache = true, RescoreLimit = 200)]
public float[]? ContentEmbedding { get; set; }
}
[WeaviateCollection("KnowledgeBase")]
[Generative<GenerativeConfig.OpenAI>(
Model = "gpt-4",
MaxTokens = 500,
Temperature = 0.7
)]
[Reranker<Reranker.Cohere>(Model = "rerank-english-v2.0")]
public class KnowledgeArticle
{
[Property(DataType.Text)]
public string Title { get; set; } = string.Empty;
[Property(DataType.Text)]
public string Content { get; set; } = string.Empty;
[Vector<Vectorizer.Text2VecOpenAI>(
Model = "text-embedding-ada-002",
SourceProperties = [nameof(Content)]
)]
public float[]? ContentVector { get; set; }
}
[WeaviateCollection(
"TenantData",
MultiTenancyEnabled = true,
AutoTenantCreation = true,
AutoTenantActivation = true
)]
public class TenantDocument
{
[Property(DataType.Text)]
public string Title { get; set; } = string.Empty;
[Property(DataType.Text)]
public string Content { get; set; } = string.Empty;
}
[WeaviateCollection(
"HighAvailabilityData",
ShardingDesiredCount = 3,
ReplicationFactor = 2,
ReplicationAsyncEnabled = true
)]
public class HADocument
{
[Property(DataType.Text)]
public string Title { get; set; } = string.Empty;
[Property(DataType.Text)]
public string Content { get; set; } = string.Empty;
}
[WeaviateCollection("Products")]
public class Product
{
[Property(DataType.Text)]
public string Name { get; set; } = string.Empty;
[Property(DataType.Text)]
public string Description { get; set; } = string.Empty;
[Property(DataType.Blob)]
public byte[]? ProductImage { get; set; }
// Text-only vector
[Vector<Vectorizer.Text2VecOpenAI>(
Model = "text-embedding-ada-002",
SourceProperties = [nameof(Name), nameof(Description)]
)]
public float[]? TextEmbedding { get; set; }
// Multi-modal vector (text + image)
[Vector<Vectorizer.Multi2VecClip>(
TextFields = [nameof(Name), nameof(Description)],
ImageFields = [nameof(ProductImage)]
)]
public float[]? MultiModalEmbedding { get; set; }
// Custom vector you provide
[Vector<Vectorizer.SelfProvided>()]
public float[]? CustomEmbedding { get; set; }
}
[WeaviateCollection("BlogPost")]
public class BlogPost
{
[Property(DataType.Text)]
public string Title { get; set; } = string.Empty;
[Property(DataType.Object)]
[NestedType(typeof(Author))]
public Author Author { get; set; } = new();
[Property(DataType.ObjectArray)]
[NestedType(typeof(Comment))]
public List<Comment> Comments { get; set; } = new();
}
public class Author
{
[Property(DataType.Text)]
public string Name { get; set; } = string.Empty;
[Property(DataType.Text)]
public string Email { get; set; } = string.Empty;
}
public class Comment
{
[Property(DataType.Text)]
public string Text { get; set; } = string.Empty;
[Property(DataType.Date)]
public DateTime PostedAt { get; set; }
}
[WeaviateCollection("Articles")]
public class Article
{
[Property(DataType.Text)]
public string Title { get; set; } = string.Empty;
// Use ConfigMethod for properties not available as attribute parameters
[Vector<Vectorizer.Text2VecOpenAI>(
Model = "text-embedding-ada-002",
SourceProperties = [nameof(Title)],
ConfigMethod = nameof(CustomizeVector)
)]
public float[]? TitleEmbedding { get; set; }
// ConfigMethod signature: static TVectorizer MethodName(string vectorName, TVectorizer prebuilt)
private static Vectorizer.Text2VecOpenAI CustomizeVector(
string vectorName,
Vectorizer.Text2VecOpenAI prebuilt)
{
// Access any property not exposed in attribute
prebuilt.VectorizeCollectionName = false;
return prebuilt;
}
}
// Check for schema changes without applying them
var plan = await client.Collections.CheckMigrate<Article>();
Console.WriteLine(plan.GetSummary());
// Output:
// Migration plan for 'Article' (2 changes):
// ✓ AddProperty: Add property 'tags' (TEXT_ARRAY)
// ✓ AddVector: Add vector 'contentEmbedding'
if (plan.HasChanges)
{
if (plan.IsSafe)
{
// Apply safe (additive) changes
await client.Collections.Migrate<Article>();
Console.WriteLine("Migration applied successfully");
}
else
{
// Breaking changes detected - require explicit confirmation
Console.WriteLine("Breaking changes detected:");
Console.WriteLine(plan.GetSummary());
// Apply with allowBreakingChanges=true (USE WITH CAUTION)
await client.Collections.Migrate<Article>(allowBreakingChanges: true);
}
}
The CollectionMapperQueryClient<T> provides a fluent, type-safe API for building Weaviate queries. Access it via collection.Query<T>(). All methods are chainable.
var collection = await client.Collections.CreateFromClass<Article>();
// Simple query
var results = await collection.Query<Article>()
.Where(a => a.WordCount > 100)
.Limit(10)
.ExecuteAsync();
Where(Expression<Func<T, bool>> predicate)Type-safe filtering with lambda expressions. Multiple Where calls are combined with AND logic.
Supported Operators:
==, !=, >, <, >=, <=&& (AND), || (OR).Contains(), .ContainsAny(), .ContainsAll()a.Category.Name// Single condition
.Where(a => a.WordCount > 100)
// Multiple conditions (AND)
.Where(a => a.WordCount > 100 && a.PublishedAt > DateTime.UtcNow.AddDays(-7))
// Nested properties
.Where(a => a.Category.Name == "Technology")
// String operations
.Where(a => a.Tags.Contains("AI"))
NearText(string text, Expression<Func<T, object>>? vector, float? certainty, float? distance)Text-to-vector search using Weaviate's vectorizers.
// Basic near text
.NearText("artificial intelligence")
// With named vector
.NearText("machine learning", vector: a => a.TitleEmbedding)
// With certainty threshold (0-1, higher = more certain)
.NearText("AI", certainty: 0.7f)
// With distance threshold (lower = more similar)
.NearText("neural networks", distance: 0.3f)
NearVector(float[] vectorValues, Expression<Func<T, object>>? vector, float? certainty, float? distance)Vector similarity search with a provided vector.
float[] queryVector = GetEmbedding("my query");
.NearVector(queryVector)
.NearVector(queryVector, vector: a => a.ContentEmbedding)
.NearVector(queryVector, certainty: 0.8f)
Hybrid(string query, Expression<Func<T, object>>? vector, float? alpha)Combines BM25 keyword search with vector search.
Alpha: 0.0 = keyword only, 0.5 = balanced, 1.0 = vector only
// Balanced hybrid
.Hybrid("machine learning")
// Favor keyword search
.Hybrid("specific terms", alpha: 0.3f)
// Favor vector search
.Hybrid("conceptual query", alpha: 0.8f)
Limit(uint limit) - Limit results.Limit(10) // Top 10 results
Sort<TProp>(Expression<Func<T, TProp>> property, bool descending) - Sort results.Sort(a => a.PublishedAt) // Ascending
.Sort(a => a.PublishedAt, descending: true) // Descending
WithVectors(params Expression<Func<T, object>>[] vectors) - Include vectors in resultsWithout this, vector properties return null.
.WithVectors(a => a.TitleEmbedding)
.WithVectors(a => a.TitleEmbedding, a => a.ContentEmbedding)
// Vectors are populated
foreach (var article in results)
{
float[]? embedding = article.TitleEmbedding; // Not null!
}
WithReferences(params Expression<Func<T, object>>[] references) - Expand referencesPopulates reference properties with full objects.
.WithReferences(a => a.Category)
.WithReferences(a => a.Category, a => a.Author)
// References are populated
foreach (var article in results)
{
Category? category = article.Category; // Fully hydrated!
}
Select(Expression<Func<T, object>> selector) - Property projection.Select(a => new { a.Title, a.PublishedAt })
WithMetadata(MetadataQuery metadata) - Include metadataRequires ExecuteWithMetadataAsync().
.WithMetadata(MetadataQuery.Distance | MetadataQuery.Certainty)
var results = await query.ExecuteWithMetadataAsync();
foreach (var obj in results.Objects)
{
Console.WriteLine($"Distance: {obj.Metadata?.Distance}");
}
ExecuteAsync() - Returns IEnumerable<T>Standard execution with automatic object mapping.
IEnumerable<Article> results = await collection.Query<Article>()
.Where(a => a.WordCount > 100)
.ExecuteAsync();
ExecuteWithMetadataAsync() - Returns WeaviateResult<WeaviateObject<T>>Returns full result with metadata (distance, certainty, etc.).
var result = await collection.Query<Article>()
.NearText("AI")
.WithMetadata(MetadataQuery.Distance | MetadataQuery.Certainty)
.ExecuteWithMetadataAsync();
foreach (var obj in result.Objects)
{
Console.WriteLine($"{obj.Properties.Title}");
Console.WriteLine($" Distance: {obj.Metadata?.Distance}");
Console.WriteLine($" Certainty: {obj.Metadata?.Certainty}");
}
var articles = await collection.Query<Article>()
.Where(a => a.WordCount >= 500 && a.WordCount <= 2000)
.Where(a => a.PublishedAt > DateTime.UtcNow.AddMonths(-6))
.Where(a => a.Category.Name == "Technology")
.Sort(a => a.PublishedAt, descending: true)
.Limit(50)
.ExecuteAsync();
var relevant = await collection.Query<Article>()
.Where(a => a.WordCount > 300)
.NearText("machine learning", vector: a => a.ContentEmbedding, certainty: 0.75f)
.WithReferences(a => a.Category, a => a.Author)
.WithVectors(a => a.ContentEmbedding)
.Sort(a => a.PublishedAt, descending: true)
.Limit(20)
.ExecuteAsync();
foreach (var article in relevant)
{
Console.WriteLine($"{article.Title} by {article.Author?.Name}");
Console.WriteLine($"Category: {article.Category?.Name}");
Console.WriteLine($"Embedding: {article.ContentEmbedding?.Length} dims");
}
var results = await collection.Query<Article>()
.Hybrid("neural networks deep learning", alpha: 0.6f)
.Where(a => a.WordCount > 200)
.WithMetadata(MetadataQuery.Score | MetadataQuery.Distance)
.Limit(15)
.ExecuteWithMetadataAsync();
foreach (var obj in results.Objects)
{
Console.WriteLine($"{obj.Properties.Title}");
Console.WriteLine($" Score: {obj.Metadata?.Score}");
Console.WriteLine($" Distance: {obj.Metadata?.Distance}");
}
For comprehensive guides and examples, see:
Weaviate.Client - Core Weaviate client (referenced as project dependency)Humanizer.Core - String transformations (PascalCase → camelCase)Same as Weaviate C# client - BSD 3-Clause
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 140 | 3/16/2026 |