github.com/weaviate/weaviate@v1.24.6/entities/vectorindex/flat/config_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package flat 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/stretchr/testify/require" 19 "github.com/weaviate/weaviate/entities/vectorindex/common" 20 ) 21 22 func Test_FlatUserConfig(t *testing.T) { 23 type test struct { 24 name string 25 input interface{} 26 expected UserConfig 27 expectErr bool 28 expectErrMsg string 29 } 30 31 tests := []test{ 32 { 33 name: "nothing specified, all defaults", 34 input: nil, 35 expected: UserConfig{ 36 VectorCacheMaxObjects: common.DefaultVectorCacheMaxObjects, 37 Distance: common.DefaultDistanceMetric, 38 PQ: CompressionUserConfig{ 39 Enabled: DefaultCompressionEnabled, 40 RescoreLimit: DefaultCompressionRescore, 41 Cache: DefaultVectorCache, 42 }, 43 BQ: CompressionUserConfig{ 44 Enabled: DefaultCompressionEnabled, 45 RescoreLimit: DefaultCompressionRescore, 46 Cache: DefaultVectorCache, 47 }, 48 }, 49 }, 50 { 51 name: "bq enabled", 52 input: map[string]interface{}{ 53 "vectorCacheMaxObjects": float64(100), 54 "distance": "cosine", 55 "bq": map[string]interface{}{ 56 "enabled": true, 57 "rescoreLimit": float64(100), 58 "cache": true, 59 }, 60 }, 61 expected: UserConfig{ 62 VectorCacheMaxObjects: 100, 63 Distance: common.DefaultDistanceMetric, 64 PQ: CompressionUserConfig{ 65 Enabled: false, 66 RescoreLimit: DefaultCompressionRescore, 67 Cache: DefaultVectorCache, 68 }, 69 BQ: CompressionUserConfig{ 70 Enabled: true, 71 RescoreLimit: 100, 72 Cache: true, 73 }, 74 }, 75 }, 76 { 77 name: "pq enabled", 78 input: map[string]interface{}{ 79 "vectorCacheMaxObjects": float64(100), 80 "distance": "cosine", 81 "pq": map[string]interface{}{ 82 "enabled": true, 83 "rescoreLimit": float64(100), 84 "cache": true, 85 }, 86 }, 87 expectErr: true, 88 expectErrMsg: "PQ is not currently supported for flat indices", 89 // expected: UserConfig{ 90 // VectorCacheMaxObjects: 100, 91 // Distance: common.DefaultDistanceMetric, 92 // PQ: CompressionUserConfig{ 93 // Enabled: true, 94 // RescoreLimit: 100, 95 // Cache: true, 96 // }, 97 // BQ: CompressionUserConfig{ 98 // Enabled: false, 99 // RescoreLimit: DefaultCompressionRescore, 100 // Cache: DefaultVectorCache, 101 // }, 102 // }, 103 }, 104 } 105 106 for _, test := range tests { 107 t.Run(test.name, func(t *testing.T) { 108 cfg, err := ParseAndValidateConfig(test.input) 109 if test.expectErr { 110 require.NotNil(t, err) 111 assert.Contains(t, err.Error(), test.expectErrMsg) 112 return 113 } else { 114 assert.Nil(t, err) 115 assert.Equal(t, test.expected, cfg) 116 } 117 }) 118 } 119 }