github.com/weaviate/weaviate@v1.24.6/modules/text2vec-transformers/vectorizer/class_settings.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  	"errors"
    16  
    17  	"github.com/weaviate/weaviate/entities/models"
    18  	"github.com/weaviate/weaviate/entities/moduletools"
    19  	basesettings "github.com/weaviate/weaviate/usecases/modulecomponents/settings"
    20  )
    21  
    22  const (
    23  	DefaultPropertyIndexed       = true
    24  	DefaultVectorizeClassName    = true
    25  	DefaultVectorizePropertyName = false
    26  	DefaultPoolingStrategy       = "masked_mean"
    27  )
    28  
    29  type classSettings struct {
    30  	basesettings.BaseClassSettings
    31  	cfg moduletools.ClassConfig
    32  }
    33  
    34  func NewClassSettings(cfg moduletools.ClassConfig) *classSettings {
    35  	return &classSettings{cfg: cfg, BaseClassSettings: *basesettings.NewBaseClassSettings(cfg)}
    36  }
    37  
    38  func (ic *classSettings) PoolingStrategy() string {
    39  	return ic.BaseClassSettings.GetPropertyAsString("poolingStrategy", DefaultPoolingStrategy)
    40  }
    41  
    42  func (ic *classSettings) InferenceURL() string {
    43  	return ic.getSetting("inferenceUrl")
    44  }
    45  
    46  func (ic *classSettings) PassageInferenceURL() string {
    47  	return ic.getSetting("passageInferenceUrl")
    48  }
    49  
    50  func (ic *classSettings) QueryInferenceURL() string {
    51  	return ic.getSetting("queryInferenceUrl")
    52  }
    53  
    54  func (ic *classSettings) getSetting(property string) string {
    55  	return ic.BaseClassSettings.GetPropertyAsString(property, "")
    56  }
    57  
    58  func (ic *classSettings) Validate(class *models.Class) error {
    59  	if err := ic.BaseClassSettings.Validate(); err != nil {
    60  		return err
    61  	}
    62  	if ic.InferenceURL() != "" && (ic.PassageInferenceURL() != "" || ic.QueryInferenceURL() != "") {
    63  		return errors.New("either inferenceUrl or passageInferenceUrl together with queryInferenceUrl needs to be set, not both")
    64  	}
    65  	if ic.PassageInferenceURL() == "" && ic.QueryInferenceURL() != "" {
    66  		return errors.New("queryInferenceUrl is set but passageInferenceUrl is empty, both needs to be set")
    67  	}
    68  	if ic.PassageInferenceURL() != "" && ic.QueryInferenceURL() == "" {
    69  		return errors.New("passageInferenceUrl is set but queryInferenceUrl is empty, both needs to be set")
    70  	}
    71  	return ic.BaseClassSettings.Validate()
    72  }