github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearText/param.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 nearText 13 14 import ( 15 "github.com/pkg/errors" 16 ) 17 18 type ObjectMove struct { 19 ID string 20 Beacon string 21 } 22 23 // ExploreMove moves an existing Search Vector closer (or further away from) a specific other search term 24 type ExploreMove struct { 25 Values []string 26 Force float32 27 Objects []ObjectMove 28 } 29 30 type NearTextParams struct { 31 Values []string 32 Limit int 33 MoveTo ExploreMove 34 MoveAwayFrom ExploreMove 35 Certainty float64 36 Distance float64 37 WithDistance bool 38 Network bool 39 Autocorrect bool 40 TargetVectors []string 41 } 42 43 func (n NearTextParams) GetCertainty() float64 { 44 return n.Certainty 45 } 46 47 func (n NearTextParams) GetDistance() float64 { 48 return n.Distance 49 } 50 51 func (n NearTextParams) SimilarityMetricProvided() bool { 52 return n.Certainty != 0 || n.WithDistance 53 } 54 55 func (n NearTextParams) GetTargetVectors() []string { 56 return n.TargetVectors 57 } 58 59 func (n NearTextParams) Validate() error { 60 if n.MoveTo.Force > 0 && 61 n.MoveTo.Values == nil && n.MoveTo.Objects == nil { 62 return errors.Errorf("'nearText.moveTo' parameter " + 63 "needs to have defined either 'concepts' or 'objects' fields") 64 } 65 66 if n.MoveAwayFrom.Force > 0 && 67 n.MoveAwayFrom.Values == nil && n.MoveAwayFrom.Objects == nil { 68 return errors.Errorf("'nearText.moveAwayFrom' parameter " + 69 "needs to have defined either 'concepts' or 'objects' fields") 70 } 71 72 if n.Certainty != 0 && n.WithDistance { 73 return errors.Errorf( 74 "nearText cannot provide both distance and certainty") 75 } 76 77 if len(n.TargetVectors) > 1 { 78 return errors.Errorf( 79 "nearText.targetVectors cannot provide more than 1 target vector value") 80 } 81 82 return nil 83 } 84 85 func (g *GraphQLArgumentsProvider) validateNearTextFn(param interface{}) error { 86 text, ok := param.(*NearTextParams) 87 if !ok { 88 return errors.New("'nearText' invalid parameter") 89 } 90 return text.Validate() 91 }