github.com/weaviate/weaviate@v1.24.6/usecases/traverser/target_vector_param_helper.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 traverser 13 14 import ( 15 "fmt" 16 17 "github.com/weaviate/weaviate/entities/dto" 18 "github.com/weaviate/weaviate/entities/modulecapabilities" 19 "github.com/weaviate/weaviate/entities/schema" 20 ) 21 22 type TargetVectorParamHelper struct{} 23 24 func NewTargetParamHelper() *TargetVectorParamHelper { 25 return &TargetVectorParamHelper{} 26 } 27 28 func (t *TargetVectorParamHelper) GetTargetVectorOrDefault(sch schema.Schema, className, targetVector string) (string, error) { 29 if targetVector == "" { 30 class := sch.FindClassByName(schema.ClassName(className)) 31 32 if len(class.VectorConfig) > 1 { 33 return "", fmt.Errorf("multiple vectorizers configuration found, please specify target vector name") 34 } 35 36 if len(class.VectorConfig) == 1 { 37 for name := range class.VectorConfig { 38 return name, nil 39 } 40 } 41 } 42 return targetVector, nil 43 } 44 45 func (t *TargetVectorParamHelper) GetTargetVectorFromParams(params dto.GetParams) string { 46 if params.NearObject != nil && len(params.NearObject.TargetVectors) == 1 { 47 return params.NearObject.TargetVectors[0] 48 } 49 if params.NearVector != nil && len(params.NearVector.TargetVectors) == 1 { 50 return params.NearVector.TargetVectors[0] 51 } 52 if params.HybridSearch != nil && len(params.HybridSearch.TargetVectors) == 1 { 53 return params.HybridSearch.TargetVectors[0] 54 } 55 if len(params.ModuleParams) > 0 { 56 for _, moduleParam := range params.ModuleParams { 57 if nearParam, ok := moduleParam.(modulecapabilities.NearParam); ok && len(nearParam.GetTargetVectors()) == 1 { 58 return nearParam.GetTargetVectors()[0] 59 } 60 } 61 } 62 return "" 63 }