github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/hnsw/config_update_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 hnsw 13 14 import ( 15 "testing" 16 17 "github.com/pkg/errors" 18 "github.com/stretchr/testify/assert" 19 "github.com/stretchr/testify/require" 20 "github.com/weaviate/weaviate/entities/schema" 21 ent "github.com/weaviate/weaviate/entities/vectorindex/hnsw" 22 ) 23 24 func TestUserConfigUpdates(t *testing.T) { 25 t.Run("various immutable and mutable fields", func(t *testing.T) { 26 type test struct { 27 name string 28 initial schema.VectorIndexConfig 29 update schema.VectorIndexConfig 30 expectedError error 31 } 32 33 tests := []test{ 34 { 35 name: "attempting to change ef construction", 36 initial: ent.UserConfig{EFConstruction: 64}, 37 update: ent.UserConfig{EFConstruction: 128}, 38 expectedError: errors.Errorf( 39 "efConstruction is immutable: " + 40 "attempted change from \"64\" to \"128\""), 41 }, 42 { 43 name: "attempting to change ef construction", 44 initial: ent.UserConfig{MaxConnections: 10}, 45 update: ent.UserConfig{MaxConnections: 15}, 46 expectedError: errors.Errorf( 47 "maxConnections is immutable: " + 48 "attempted change from \"10\" to \"15\""), 49 }, 50 { 51 name: "attempting to change cleanup interval seconds", 52 initial: ent.UserConfig{CleanupIntervalSeconds: 60}, 53 update: ent.UserConfig{CleanupIntervalSeconds: 90}, 54 expectedError: errors.Errorf( 55 "cleanupIntervalSeconds is immutable: " + 56 "attempted change from \"60\" to \"90\""), 57 }, 58 { 59 name: "attempting to change distance", 60 initial: ent.UserConfig{Distance: "cosine"}, 61 update: ent.UserConfig{Distance: "l2-squared"}, 62 expectedError: errors.Errorf( 63 "distance is immutable: " + 64 "attempted change from \"cosine\" to \"l2-squared\""), 65 }, 66 { 67 name: "changing ef", 68 initial: ent.UserConfig{EF: 100}, 69 update: ent.UserConfig{EF: -1}, 70 expectedError: nil, 71 }, 72 { 73 name: "changing other mutable settings", 74 initial: ent.UserConfig{ 75 VectorCacheMaxObjects: 700, 76 FlatSearchCutoff: 800, 77 }, 78 update: ent.UserConfig{ 79 VectorCacheMaxObjects: 730, 80 FlatSearchCutoff: 830, 81 }, 82 expectedError: nil, 83 }, 84 { 85 name: "attempting to change dynamic ef settings", 86 initial: ent.UserConfig{ 87 DynamicEFMin: 100, 88 DynamicEFMax: 200, 89 DynamicEFFactor: 5, 90 }, 91 update: ent.UserConfig{ 92 DynamicEFMin: 101, 93 DynamicEFMax: 201, 94 DynamicEFFactor: 6, 95 }, 96 expectedError: nil, 97 }, 98 { 99 name: "setting bq compression on", 100 initial: ent.UserConfig{ 101 BQ: ent.BQConfig{ 102 Enabled: false, 103 }, 104 }, 105 update: ent.UserConfig{ 106 BQ: ent.BQConfig{ 107 Enabled: true, 108 }, 109 }, 110 expectedError: nil, 111 }, 112 } 113 114 for _, test := range tests { 115 t.Run(test.name, func(t *testing.T) { 116 err := ValidateUserConfigUpdate(test.initial, test.update) 117 if test.expectedError == nil { 118 assert.Nil(t, err) 119 } else { 120 require.NotNil(t, err, "update validation must error") 121 assert.Equal(t, test.expectedError.Error(), err.Error()) 122 } 123 }) 124 } 125 }) 126 }