weaviate

Форк
0
/
class_settings_test.go 
106 строк · 2.9 Кб
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 TestClassSettings(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 := NewClassSettings(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 a nil config", func(t *testing.T) {
40
		// this is the case if we were running in a situation such as a
41
		// cross-class vectorization of search time, as is the case with Explore
42
		// {}, we then expect all default values
43

44
		ic := NewClassSettings(nil)
45

46
		assert.True(t, ic.PropertyIndexed("someProp"))
47
		assert.False(t, ic.VectorizePropertyName("someProp"))
48
		assert.True(t, ic.VectorizeClassName())
49
	})
50

51
	t.Run("with all explicit config matching the defaults", func(t *testing.T) {
52
		class := &models.Class{
53
			Class: "MyClass",
54
			ModuleConfig: map[string]interface{}{
55
				"my-module": map[string]interface{}{
56
					"vectorizeClassName": true,
57
					"poolingStrategy":    "masked_mean",
58
				},
59
			},
60
			Properties: []*models.Property{{
61
				Name: "someProp",
62
				ModuleConfig: map[string]interface{}{
63
					"my-module": map[string]interface{}{
64
						"skip":                  false,
65
						"vectorizePropertyName": false,
66
					},
67
				},
68
			}},
69
		}
70

71
		cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "")
72
		ic := NewClassSettings(cfg)
73

74
		assert.True(t, ic.PropertyIndexed("someProp"))
75
		assert.False(t, ic.VectorizePropertyName("someProp"))
76
		assert.True(t, ic.VectorizeClassName())
77
	})
78

79
	t.Run("with all explicit config using non-default values", func(t *testing.T) {
80
		class := &models.Class{
81
			Class: "MyClass",
82
			ModuleConfig: map[string]interface{}{
83
				"my-module": map[string]interface{}{
84
					"vectorizeClassName": false,
85
					"poolingStrategy":    "cls",
86
				},
87
			},
88
			Properties: []*models.Property{{
89
				Name: "someProp",
90
				ModuleConfig: map[string]interface{}{
91
					"my-module": map[string]interface{}{
92
						"skip":                  true,
93
						"vectorizePropertyName": true,
94
					},
95
				},
96
			}},
97
		}
98

99
		cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "")
100
		ic := NewClassSettings(cfg)
101

102
		assert.False(t, ic.PropertyIndexed("someProp"))
103
		assert.True(t, ic.VectorizePropertyName("someProp"))
104
		assert.False(t, ic.VectorizeClassName())
105
	})
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.