weaviate
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
12package vectorizer13
14import (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
22func TestClassSettings(t *testing.T) {23t.Run("with all defaults", func(t *testing.T) {24class := &models.Class{25Class: "MyClass",26Properties: []*models.Property{{27Name: "someProp",28}},29}30
31cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "")32ic := NewClassSettings(cfg)33
34assert.True(t, ic.PropertyIndexed("someProp"))35assert.False(t, ic.VectorizePropertyName("someProp"))36assert.True(t, ic.VectorizeClassName())37})38
39t.Run("with a nil config", func(t *testing.T) {40// this is the case if we were running in a situation such as a41// cross-class vectorization of search time, as is the case with Explore42// {}, we then expect all default values43
44ic := NewClassSettings(nil)45
46assert.True(t, ic.PropertyIndexed("someProp"))47assert.False(t, ic.VectorizePropertyName("someProp"))48assert.True(t, ic.VectorizeClassName())49})50
51t.Run("with all explicit config matching the defaults", func(t *testing.T) {52class := &models.Class{53Class: "MyClass",54ModuleConfig: map[string]interface{}{55"my-module": map[string]interface{}{56"vectorizeClassName": true,57"poolingStrategy": "masked_mean",58},59},60Properties: []*models.Property{{61Name: "someProp",62ModuleConfig: map[string]interface{}{63"my-module": map[string]interface{}{64"skip": false,65"vectorizePropertyName": false,66},67},68}},69}70
71cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "")72ic := NewClassSettings(cfg)73
74assert.True(t, ic.PropertyIndexed("someProp"))75assert.False(t, ic.VectorizePropertyName("someProp"))76assert.True(t, ic.VectorizeClassName())77})78
79t.Run("with all explicit config using non-default values", func(t *testing.T) {80class := &models.Class{81Class: "MyClass",82ModuleConfig: map[string]interface{}{83"my-module": map[string]interface{}{84"vectorizeClassName": false,85"poolingStrategy": "cls",86},87},88Properties: []*models.Property{{89Name: "someProp",90ModuleConfig: map[string]interface{}{91"my-module": map[string]interface{}{92"skip": true,93"vectorizePropertyName": true,94},95},96}},97}98
99cfg := modules.NewClassBasedModuleConfig(class, "my-module", "tenant", "")100ic := NewClassSettings(cfg)101
102assert.False(t, ic.PropertyIndexed("someProp"))103assert.True(t, ic.VectorizePropertyName("someProp"))104assert.False(t, ic.VectorizeClassName())105})106}
107