github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/generic_module.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 modulecomponents
    13  
    14  import (
    15  	"fmt"
    16  
    17  	"github.com/tailor-inc/graphql"
    18  	"github.com/weaviate/weaviate/entities/modulecapabilities"
    19  	"github.com/weaviate/weaviate/usecases/modulecomponents/additional"
    20  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearAudio"
    21  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearDepth"
    22  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearImage"
    23  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearImu"
    24  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearText"
    25  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearThermal"
    26  	"github.com/weaviate/weaviate/usecases/modulecomponents/arguments/nearVideo"
    27  )
    28  
    29  type ArgumentType int
    30  
    31  const (
    32  	Get ArgumentType = iota
    33  	Aggregate
    34  	Explore
    35  )
    36  
    37  func GetGenericArgument(name, className string, argumentType ArgumentType,
    38  	nearTextTransformer modulecapabilities.TextTransform,
    39  ) *graphql.ArgumentConfig {
    40  	switch name {
    41  	case nearText.NAME:
    42  		return getGenericArgument(nearText.New(nearTextTransformer).Arguments()[name], className, argumentType)
    43  	case nearImage.NAME:
    44  		return getGenericArgument(nearImage.New().Arguments()[name], className, argumentType)
    45  	case nearAudio.NAME:
    46  		return getGenericArgument(nearAudio.New().Arguments()[name], className, argumentType)
    47  	case nearDepth.NAME:
    48  		return getGenericArgument(nearDepth.New().Arguments()[name], className, argumentType)
    49  	case nearImu.NAME:
    50  		return getGenericArgument(nearImu.New().Arguments()[name], className, argumentType)
    51  	case nearThermal.NAME:
    52  		return getGenericArgument(nearThermal.New().Arguments()[name], className, argumentType)
    53  	case nearVideo.NAME:
    54  		return getGenericArgument(nearVideo.New().Arguments()[name], className, argumentType)
    55  	default:
    56  		panic(fmt.Sprintf("Unknown generic argument: %s", name))
    57  	}
    58  }
    59  
    60  func getGenericArgument(arg modulecapabilities.GraphQLArgument,
    61  	className string, argumentType ArgumentType,
    62  ) *graphql.ArgumentConfig {
    63  	switch argumentType {
    64  	case Get:
    65  		return arg.GetArgumentsFunction(className)
    66  	case Aggregate:
    67  		return arg.AggregateArgumentsFunction(className)
    68  	case Explore:
    69  		return arg.ExploreArgumentsFunction()
    70  	default:
    71  		panic(fmt.Sprintf("Unknown argument type: %v", argumentType))
    72  	}
    73  }
    74  
    75  func GetGenericAdditionalProperty(name, className string) *modulecapabilities.AdditionalProperty {
    76  	switch name {
    77  	case "featureProjection":
    78  		fp := additional.NewText2VecProvider().AdditionalProperties()["featureProjection"]
    79  		return &fp
    80  	default:
    81  		return nil
    82  	}
    83  }