1+ using Xunit ;
2+ using Weaviate . Client ;
3+ using Weaviate . Client . Models ;
4+ using System ;
5+ using System . Threading . Tasks ;
6+
7+ namespace WeaviateProject . Tests ;
8+
9+ public class ConfigureBQTest : IAsyncLifetime
10+ {
11+ private WeaviateClient client ;
12+ private const string COLLECTION_NAME = "MyCollection" ;
13+
14+ // Runs before each test
15+ public async Task InitializeAsync ( )
16+ {
17+ // START ConnectCode
18+ // Note: The C# client doesn't support setting headers like 'X-OpenAI-Api-Key' via the constructor for local connections.
19+ // This must be configured in Weaviate's environment variables.
20+ client = new WeaviateClient ( new ClientConfiguration { RestAddress = "localhost" , RestPort = 8080 } ) ;
21+ // END ConnectCode
22+
23+ // Clean slate for each test
24+ if ( await client . Collections . Exists ( COLLECTION_NAME ) )
25+ {
26+ await client . Collections . Delete ( COLLECTION_NAME ) ;
27+ }
28+ }
29+
30+ // Runs after each test
31+ public Task DisposeAsync ( )
32+ {
33+ // No action needed here, as cleanup happens in InitializeAsync before the next test.
34+ return Task . CompletedTask ;
35+ }
36+
37+ [ Fact ]
38+ public async Task TestEnableBQ ( )
39+ {
40+ // START EnableBQ
41+ await client . Collections . Create ( new CollectionConfig
42+ {
43+ Name = "MyCollection" ,
44+ Properties = [ Property . Text ( "title" ) ] ,
45+ VectorConfig = new VectorConfig (
46+ "default" ,
47+ new Vectorizer . Text2VecTransformers ( ) ,
48+ new VectorIndex . HNSW
49+ {
50+ // highlight-start
51+ Quantizer = new VectorIndex . Quantizers . BQ ( )
52+ // highlight-end
53+ }
54+ )
55+ } ) ;
56+ // END EnableBQ
57+ }
58+
59+ [ Fact ]
60+ public async Task TestUpdateSchema ( )
61+ {
62+ // Note: Updating quantization settings on an existing collection is not supported by Weaviate
63+ // and will result in an error, as noted in the Java test. This test demonstrates the syntax for attempting the update.
64+ var collection = await client . Collections . Create ( new CollectionConfig
65+ {
66+ Name = "MyCollection" ,
67+ Properties = [ Property . Text ( "title" ) ] ,
68+ VectorConfig = new VectorConfig ( "default" , new Vectorizer . Text2VecTransformers ( ) )
69+ } ) ;
70+
71+ // START UpdateSchema
72+ await collection . Config . Update ( c =>
73+ {
74+ var vectorConfig = c . VectorConfig [ "default" ] ;
75+ vectorConfig . VectorIndexConfig . UpdateHNSW ( h => h . Quantizer = new VectorIndex . Quantizers . BQ ( ) ) ;
76+ } ) ;
77+ // END UpdateSchema
78+ }
79+
80+ [ Fact ]
81+ public async Task TestBQWithOptions ( )
82+ {
83+ // START BQWithOptions
84+ await client . Collections . Create ( new CollectionConfig
85+ {
86+ Name = "MyCollection" ,
87+ Properties = [ Property . Text ( "title" ) ] ,
88+ VectorConfig = new VectorConfig (
89+ "default" ,
90+ new Vectorizer . Text2VecTransformers ( ) ,
91+ // highlight-start
92+ new VectorIndex . HNSW
93+ {
94+ VectorCacheMaxObjects = 100000 ,
95+ Quantizer = new VectorIndex . Quantizers . BQ
96+ {
97+ Cache = true ,
98+ RescoreLimit = 200
99+ }
100+ }
101+ // highlight-end
102+ )
103+ } ) ;
104+ // END BQWithOptions
105+ }
106+ }
0 commit comments