github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearImage/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 nearImage
    13  
    14  import (
    15  	"github.com/pkg/errors"
    16  )
    17  
    18  type NearImageParams struct {
    19  	Image         string
    20  	Certainty     float64
    21  	Distance      float64
    22  	WithDistance  bool
    23  	TargetVectors []string
    24  }
    25  
    26  func (n NearImageParams) GetCertainty() float64 {
    27  	return n.Certainty
    28  }
    29  
    30  func (n NearImageParams) GetDistance() float64 {
    31  	return n.Distance
    32  }
    33  
    34  func (n NearImageParams) SimilarityMetricProvided() bool {
    35  	return n.Certainty != 0 || n.WithDistance
    36  }
    37  
    38  func (n NearImageParams) GetTargetVectors() []string {
    39  	return n.TargetVectors
    40  }
    41  
    42  func ValidateNearImageFn(param interface{}) error {
    43  	nearImage, ok := param.(*NearImageParams)
    44  	if !ok {
    45  		return errors.New("'nearImage' invalid parameter")
    46  	}
    47  
    48  	if len(nearImage.Image) == 0 {
    49  		return errors.Errorf("'nearImage.image' needs to be defined")
    50  	}
    51  
    52  	if nearImage.Certainty != 0 && nearImage.WithDistance {
    53  		return errors.Errorf(
    54  			"nearImage cannot provide both distance and certainty")
    55  	}
    56  
    57  	if len(nearImage.TargetVectors) > 1 {
    58  		return errors.Errorf(
    59  			"nearImage.targetVectors cannot provide more than 1 target vector value")
    60  	}
    61  	return nil
    62  }