WeaviateNET 1.21.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package WeaviateNET --version 1.21.1.3                
NuGet\Install-Package WeaviateNET -Version 1.21.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WeaviateNET" Version="1.21.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WeaviateNET --version 1.21.1.3                
#r "nuget: WeaviateNET, 1.21.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WeaviateNET as a Cake Addin
#addin nuget:?package=WeaviateNET&version=1.21.1.3

// Install WeaviateNET as a Cake Tool
#tool nuget:?package=WeaviateNET&version=1.21.1.3                

Weaviate.NET

This library is designed to wrap Weaviate vector DB for .NET core. The core API has been wrapped with NSwagStudio and then some extra layer has been added. The API mapping is incomplete and Unit tests should be generalized (they currently use a demo instance).

It is designed to manipulate Weaviate objects and not just to adapt the connection to some LLM framework as other NuGet packages do.

What's new in version 1.21.1.3

  • Added attributes VectorIndexConfig, ReplicationConfig, IndexStopwords, IndexTimestamps, IndexNullState, IndexPropertyLength, BM25Index, MultiTenancy to decorate class definition and control indexing options.
  • Added attributes Tokenization, IndexFilterable, IndexSearchable to decorate class fields and control indexing options.

Implementation status

The library implements almost all the schema, class, and object manipulation. It is possible to perform GraphQL queries though the current implementation is pretty raw. Thanks to Newtonsoft JObject it is possible to parse returned data pretty easily.

Note that it is still possible to use the NSwag generated API from Weaviate swagger file by using the Client property of the WeaviateDB connection. By missing APIs we intend that the calls have not yet been nicely wrapped in the object model and tested.

Missing APIs

  • References management
  • /batch/references endpoint is not implemented

Untested APIs

  • Tenant
  • Shards
  • Backups
  • Classifications

Roadmap

After implementing the missing endpoints in the object model we will work in providing a better GraphQL experience. In the ideal world a LINQ provider would be great to integrate queries into C#.

Package versioning

The Weaviate.NET package on NuGet follows the versioning schema of Weaviate: version 1.20.5.1 of the package is the first release tested on version 1.20.5 of Weaviate. So look at the last number to check the library revision.

Using the library

The data model is respectful of the database object model. To start create a connection (using the authorization key) and update the Schema to load the configuration:

weaviateDB = new WeaviateDB("https://yourhost/v1", "WEAVIATE_KEY");
await weaviateDB.Update();

In the Weaviate model objects are made of a set of fields (i.e. properties) with the appropriate data type (see WeaviateDataType class for the full list). Weaviate.NET maps properties to class fields (with few restrictions of course). So we can define the class Movie to describe a movie document:

[IndexNullState] // annotation to configure indexing options
public class Movie
{
    public string? film;
    public string? genre;
    public string? leadStudio;
    public int audienceScore;
    public double profitability;
    public int rottenTomatoes;
    public double worldWideGross;
    public int year;
}

Notice that all names follow the camel notation, if you use pascal notation Weaviate will lower case the first letter.

If we want to expose the id field in the Movie class we can use the JsonIgnore attribute to avoid mapping it to a property:

    [JsonIgnore]
    public Guid? id;

Important: If you use a class with less properties the library will work, this is useful to perform schema updates or property masking. Magic is performed by Newtonsoft serializer/deserializer.

We can create the class in the schema and load data (of type WeaviateObject< Movie>):

var mc = weaviateDB.Schema.NewClass<Movie>("MovieDBTest");
Movie[] movies = ReadMoviesDBFromCsv();
var toadd = new List<WeaviateObject<Movie>>();
foreach (var m in movies) {
  var d = mc.Create(); // create the document
  d.Properties = m;    // set the properties (of type Movie)
  toadd.Add(d);
}
await mc.Add(toadd);

To query the database you use explicitly the GraphQL syntax and the ability of JObject to deserialize a field. This basic approach will be supported in the future but a better abstraction will be provided.

        var q = new GraphQLQuery();
        q.Query = @"{
  Get {
    MovieDBTest(
      limit: 5
      nearText: { concepts: [ "robot in the future" ] }
    )
    {
      film
      genre
      leadStudio
      audienceScore
      profitability
      rottenTomatoes
      worldWideGross
      year
    }
  }
}";
        var ret = await weaviateDB.Schema.RawQuery(q);
        var d = ret.Data["Get"];
        var a = data.ToObject<Movie[]>();

Previous changes

version 1.21.1.2

  • Now it is possible to define fields in classes that are not mapped to Weaviate properties if annotated with JsonIgnore attribute.

version 1.21.1.1

Now the DateTime? type is supported. The library will convert the DateTime? to DatTime.

version 1.21.0.2

Added method CountObjectsByProperty to count object with a specific value in a property.

Version 1.21.0.1

Added the CountObjects method to WeaviateClass.

Tested against version 1.21.0 of Weaviate

Version 1.20.5.3

Added the ListObjects method to WeaviateClass. Apparently if you omit the limit parameter you get an empty list so the parameter is defaulted to 25.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on WeaviateNET:

Package Downloads
Oraculum

Library to create and organize factual knowledge inside a Weaviate vector DB and define AI GPT based assistants using this knowledge.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.23.9.1 1,398 2/18/2024
1.23.7.1 579 2/3/2024
1.22.2.1 401 11/1/2023
1.21.6.2 476 10/22/2023
1.21.6.1 148 10/22/2023
1.21.3.1 263 9/20/2023
1.21.2.1 213 9/2/2023
1.21.1.5 307 8/29/2023
1.21.1.4 168 8/25/2023
1.21.1.3 164 8/25/2023
1.21.1.2 145 8/24/2023
1.21.1.1 140 8/24/2023
1.21.0.2 155 8/21/2023
1.21.0.1 157 8/21/2023
1.20.5.3 155 8/18/2023
1.20.5.2 129 8/18/2023
1.20.5.1 182 8/13/2023
1.20.5 180 8/12/2023
1.0.0 153 8/11/2023