Skip to content
306 changes: 153 additions & 153 deletions _includes/code/csharp/ConfigureRQTest.cs
Original file line number Diff line number Diff line change
@@ -1,166 +1,166 @@
// using Xunit;
// using Weaviate.Client;
// using Weaviate.Client.Models;
// using System;
// using System.Threading.Tasks;
using Xunit;
using Weaviate.Client;
using Weaviate.Client.Models;
using System;
using System.Threading.Tasks;

// namespace WeaviateProject.Tests;
namespace WeaviateProject.Tests;

// public class ConfigureRQTest : IAsyncLifetime
// {
// private WeaviateClient client;
// private const string COLLECTION_NAME = "MyCollection";
public class ConfigureRQTest : IAsyncLifetime
{
private WeaviateClient client;
private const string COLLECTION_NAME = "MyCollection";

// // Runs before each test
// public async Task InitializeAsync()
// {
// // START ConnectCode
// // Note: The C# client doesn't support setting headers like 'X-OpenAI-Api-Key' via the constructor for local connections.
// // This must be configured in Weaviate's environment variables.
// client = new WeaviateClient(new ClientConfiguration { RestAddress = "localhost", RestPort = 8080 });
// // END ConnectCode
// Runs before each test
public async Task InitializeAsync()
{
// START ConnectCode
// Note: The C# client doesn't support setting headers like 'X-OpenAI-Api-Key' via the constructor for local connections.
// This must be configured in Weaviate's environment variables.
client = new WeaviateClient(new ClientConfiguration { RestAddress = "localhost", RestPort = 8080 });
// END ConnectCode

// // Clean slate for each test
// if (await client.Collections.Exists(COLLECTION_NAME))
// {
// await client.Collections.Delete(COLLECTION_NAME);
// }
// }
// Clean slate for each test
if (await client.Collections.Exists(COLLECTION_NAME))
{
await client.Collections.Delete(COLLECTION_NAME);
}
}

// // Runs after each test
// public Task DisposeAsync()
// {
// // No action needed here, as cleanup happens in InitializeAsync before the next test.
// return Task.CompletedTask;
// }
// Runs after each test
public Task DisposeAsync()
{
// No action needed here, as cleanup happens in InitializeAsync before the next test.
return Task.CompletedTask;
}

// [Fact]
// public async Task TestEnableRQ()
// {
// // START EnableRQ
// await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig(
// "default",
// new Vectorizer.Text2VecTransformers(),
// new VectorIndex.HNSW
// {
// // highlight-start
// Quantizer = new VectorIndex.Quantizers.RQ()
// // highlight-end
// }
// )
// });
// // END EnableRQ
// }
[Fact]
public async Task TestEnableRQ()
{
// START EnableRQ
await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig(
"default",
new Vectorizer.Text2VecTransformers(),
new VectorIndex.HNSW
{
// highlight-start
Quantizer = new VectorIndex.Quantizers.RQ()
// highlight-end
}
)
});
// END EnableRQ
}

// [Fact]
// public async Task Test1BitEnableRQ()
// {
// // START 1BitEnableRQ
// await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig(
// "default",
// new Vectorizer.Text2VecTransformers(),
// new VectorIndex.HNSW
// {
// // highlight-start
// Quantizer = new VectorIndex.Quantizers.RQ { Bits = 1 }
// // highlight-end
// }
// )
// });
// // END 1BitEnableRQ
// }
[Fact]
public async Task Test1BitEnableRQ()
{
// START 1BitEnableRQ
await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig(
"default",
new Vectorizer.Text2VecTransformers(),
new VectorIndex.HNSW
{
// highlight-start
Quantizer = new VectorIndex.Quantizers.RQ { Bits = 1 }
// highlight-end
}
)
});
// END 1BitEnableRQ
}

// [Fact]
// public async Task TestUncompressed()
// {
// // START Uncompressed
// await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig(
// "default",
// new Vectorizer.Text2VecTransformers(),
// // highlight-start
// // Omitting the Quantizer property results in an uncompressed index.
// new VectorIndex.HNSW()
// // highlight-end
// )
// });
// // END Uncompressed
// }
[Fact]
public async Task TestUncompressed()
{
// START Uncompressed
await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig(
"default",
new Vectorizer.Text2VecTransformers(),
// highlight-start
// Omitting the Quantizer property results in an uncompressed index.
new VectorIndex.HNSW()
// highlight-end
)
});
// END Uncompressed
}

// [Fact]
// public async Task TestRQWithOptions()
// {
// // START RQWithOptions
// await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig(
// "default",
// new Vectorizer.Text2VecTransformers(),
// new VectorIndex.HNSW
// {
// // highlight-start
// Quantizer = new VectorIndex.Quantizers.RQ
// {
// Bits = 8, // Optional: Number of bits
// RescoreLimit = 20 // Optional: Number of candidates to fetch before rescoring
// }
// // highlight-end
// }
// )
// });
// // END RQWithOptions
// }
[Fact]
public async Task TestRQWithOptions()
{
// START RQWithOptions
await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig(
"default",
new Vectorizer.Text2VecTransformers(),
new VectorIndex.HNSW
{
// highlight-start
Quantizer = new VectorIndex.Quantizers.RQ
{
Bits = 8, // Optional: Number of bits
RescoreLimit = 20 // Optional: Number of candidates to fetch before rescoring
}
// highlight-end
}
)
});
// END RQWithOptions
}

// [Fact]
// public async Task TestUpdateSchema()
// {
// // Note: Updating quantization settings on an existing collection is not supported by Weaviate
// // and will result in an error, as noted in the Java test. This test demonstrates the syntax for attempting the update.
// var collection = await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig("default", new Vectorizer.Text2VecTransformers())
// });
[Fact]
public async Task TestUpdateSchema()
{
// Note: Updating quantization settings on an existing collection is not supported by Weaviate
// and will result in an error, as noted in the Java test. This test demonstrates the syntax for attempting the update.
var collection = await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig("default", new Vectorizer.Text2VecTransformers())
});

// // START UpdateSchema
// await collection.Config.Update(c =>
// {
// var vectorConfig = c.VectorConfig["default"];
// vectorConfig.VectorIndexConfig.UpdateHNSW(h => h.Quantizer = new VectorIndex.Quantizers.RQ());
// });
// // END UpdateSchema
// }
// START UpdateSchema
await collection.Config.Update(c =>
{
var vectorConfig = c.VectorConfig["default"];
vectorConfig.VectorIndexConfig.UpdateHNSW(h => h.Quantizer = new VectorIndex.Quantizers.RQ());
});
// END UpdateSchema
}

// [Fact]
// public async Task Test1BitUpdateSchema()
// {
// var collection = await client.Collections.Create(new CollectionConfig
// {
// Name = "MyCollection",
// Properties = [Property.Text("title")],
// VectorConfig = new VectorConfig("default", new Vectorizer.Text2VecTransformers())
// });
[Fact]
public async Task Test1BitUpdateSchema()
{
var collection = await client.Collections.Create(new CollectionConfig
{
Name = "MyCollection",
Properties = [Property.Text("title")],
VectorConfig = new VectorConfig("default", new Vectorizer.Text2VecTransformers())
});

// // START 1BitUpdateSchema
// await collection.Config.Update(c =>
// {
// var vectorConfig = c.VectorConfig["default"];
// vectorConfig.VectorIndexConfig.UpdateHNSW(h => h.Quantizer = new VectorIndex.Quantizers.RQ { Bits = 1 });
// });
// // END 1BitUpdateSchema
// }
// }
// START 1BitUpdateSchema
await collection.Config.Update(c =>
{
var vectorConfig = c.VectorConfig["default"];
vectorConfig.VectorIndexConfig.UpdateHNSW(h => h.Quantizer = new VectorIndex.Quantizers.RQ { Bits = 1 });
});
// END 1BitUpdateSchema
}
}
6 changes: 3 additions & 3 deletions _includes/code/csharp/ConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task TestConnectWCDWithApiKey()
string weaviateUrl = Environment.GetEnvironmentVariable("WEAVIATE_URL");
string weaviateApiKey = Environment.GetEnvironmentVariable("WEAVIATE_API_KEY");

WeaviateClient client = Connect.Cloud(
WeaviateClient client = await Connect.Cloud(
weaviateUrl, // Replace with your Weaviate Cloud URL
weaviateApiKey // Replace with your Weaviate Cloud key
);
Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task TestCustomApiKeyConnection()
public async Task TestConnectLocalNoAuth()
{
// START LocalNoAuth
WeaviateClient client = Connect.Local();
WeaviateClient client = await Connect.Local();

var isReady = await client.IsReady();
Console.WriteLine(isReady);
Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task TestConnectWCDWithThirdPartyKeys()
string weaviateApiKey = Environment.GetEnvironmentVariable("WEAVIATE_API_KEY");
string cohereApiKey = Environment.GetEnvironmentVariable("COHERE_API_KEY");

WeaviateClient client = Connect.Cloud(
WeaviateClient client = await Connect.Cloud(
weaviateUrl, // Replace with your Weaviate Cloud URL
weaviateApiKey, // Replace with your Weaviate Cloud key
new Dictionary<string, string>
Expand Down
4 changes: 2 additions & 2 deletions _includes/code/csharp/GetStartedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GetStartedTests
[Fact]
public async Task GetStarted()
{
var client = Connect.Local();
var client = await Connect.Local();
const string collectionName = "Question";

try
Expand Down Expand Up @@ -87,7 +87,7 @@ public async Task CreateCollectionAndRunNearTextQuery()
string weaviateApiKey = Environment.GetEnvironmentVariable("WEAVIATE_API_KEY");

// 1. Connect to Weaviate
var client = Connect.Cloud(weaviateUrl, weaviateApiKey);
var client = await Connect.Cloud(weaviateUrl, weaviateApiKey);

// 2. Prepare data (same as Python data_objects)
var dataObjects = new List<object>
Expand Down
Loading
Loading