github.com/weaviate/weaviate@v1.24.6/modules/text2vec-contextionary/vectorizer/index_check_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 vectorizer 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/weaviate/weaviate/entities/models" 19 "github.com/weaviate/weaviate/usecases/modules" 20 ) 21 22 func TestIndexChecker(t *testing.T) { 23 t.Run("with all defaults", func(t *testing.T) { 24 class := &models.Class{ 25 Class: "MyClass", 26 Properties: []*models.Property{{ 27 Name: "someProp", 28 }}, 29 } 30 31 cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "") 32 ic := NewIndexChecker(cfg) 33 34 assert.True(t, ic.PropertyIndexed("someProp")) 35 assert.False(t, ic.VectorizePropertyName("someProp")) 36 assert.True(t, ic.VectorizeClassName()) 37 }) 38 39 t.Run("with all explicit config matching the defaults", func(t *testing.T) { 40 class := &models.Class{ 41 Class: "MyClass", 42 ModuleConfig: map[string]interface{}{ 43 "my-module": map[string]interface{}{ 44 "vectorizeClassName": true, 45 }, 46 }, 47 Properties: []*models.Property{{ 48 Name: "someProp", 49 ModuleConfig: map[string]interface{}{ 50 "my-module": map[string]interface{}{ 51 "skip": false, 52 "vectorizePropertyName": false, 53 }, 54 }, 55 }}, 56 } 57 58 cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "") 59 ic := NewIndexChecker(cfg) 60 61 assert.True(t, ic.PropertyIndexed("someProp")) 62 assert.False(t, ic.VectorizePropertyName("someProp")) 63 assert.True(t, ic.VectorizeClassName()) 64 }) 65 66 t.Run("with all explicit config using non-default values", func(t *testing.T) { 67 class := &models.Class{ 68 Class: "MyClass", 69 ModuleConfig: map[string]interface{}{ 70 "my-module": map[string]interface{}{ 71 "vectorizeClassName": false, 72 }, 73 }, 74 Properties: []*models.Property{{ 75 Name: "someProp", 76 ModuleConfig: map[string]interface{}{ 77 "my-module": map[string]interface{}{ 78 "skip": true, 79 "vectorizePropertyName": true, 80 }, 81 }, 82 }}, 83 } 84 85 cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "") 86 ic := NewIndexChecker(cfg) 87 88 assert.False(t, ic.PropertyIndexed("someProp")) 89 assert.True(t, ic.VectorizePropertyName("someProp")) 90 assert.False(t, ic.VectorizeClassName()) 91 }) 92 }