github.com/weaviate/weaviate@v1.24.6/adapters/handlers/graphql/local/get/hybrid_search.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 get
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  
    18  	"github.com/tailor-inc/graphql"
    19  	"github.com/weaviate/weaviate/adapters/handlers/graphql/descriptions"
    20  	"github.com/weaviate/weaviate/entities/models"
    21  )
    22  
    23  func hybridArgument(classObject *graphql.Object,
    24  	class *models.Class, modulesProvider ModulesProvider, fusionEnum *graphql.Enum,
    25  ) *graphql.ArgumentConfig {
    26  	prefix := fmt.Sprintf("GetObjects%s", class.Class)
    27  	return &graphql.ArgumentConfig{
    28  		Type: graphql.NewInputObject(
    29  			graphql.InputObjectConfig{
    30  				Name:        fmt.Sprintf("%sHybridInpObj", prefix),
    31  				Fields:      hybridOperands(classObject, class, modulesProvider, fusionEnum),
    32  				Description: "Hybrid search",
    33  			},
    34  		),
    35  	}
    36  }
    37  
    38  func hybridOperands(classObject *graphql.Object,
    39  	class *models.Class, modulesProvider ModulesProvider, fusionEnum *graphql.Enum,
    40  ) graphql.InputObjectConfigFieldMap {
    41  	ss := graphql.NewInputObject(graphql.InputObjectConfig{
    42  		Name:   class.Class + "SubSearch",
    43  		Fields: hybridSubSearch(classObject, class, modulesProvider),
    44  	})
    45  
    46  	fieldMap := graphql.InputObjectConfigFieldMap{
    47  		"query": &graphql.InputObjectFieldConfig{
    48  			Description: "Query string",
    49  			Type:        graphql.String,
    50  		},
    51  		"alpha": &graphql.InputObjectFieldConfig{
    52  			Description: "Search weight",
    53  			Type:        graphql.Float,
    54  		},
    55  		"vector": &graphql.InputObjectFieldConfig{
    56  			Description: "Vector search",
    57  			Type:        graphql.NewList(graphql.Float),
    58  		},
    59  		"properties": &graphql.InputObjectFieldConfig{
    60  			Description: "Which properties should be included in the sparse search",
    61  			Type:        graphql.NewList(graphql.String),
    62  		},
    63  		"fusionType": &graphql.InputObjectFieldConfig{
    64  			Description: "Algorithm used for fusing results from vector and keyword search",
    65  			Type:        fusionEnum,
    66  		},
    67  		"targetVectors": &graphql.InputObjectFieldConfig{
    68  			Description: "Target vectors",
    69  			Type:        graphql.NewList(graphql.String),
    70  		},
    71  	}
    72  
    73  	if os.Getenv("ENABLE_EXPERIMENTAL_HYBRID_OPERANDS") != "" {
    74  		fieldMap["operands"] = &graphql.InputObjectFieldConfig{
    75  			Description: "Subsearch list",
    76  			Type:        graphql.NewList(ss),
    77  		}
    78  	}
    79  
    80  	return fieldMap
    81  }
    82  
    83  func hybridSubSearch(classObject *graphql.Object,
    84  	class *models.Class, modulesProvider ModulesProvider,
    85  ) graphql.InputObjectConfigFieldMap {
    86  	prefixName := class.Class + "SubSearch"
    87  
    88  	return graphql.InputObjectConfigFieldMap{
    89  		"weight": &graphql.InputObjectFieldConfig{
    90  			Description: "weight, 0 to 1",
    91  			Type:        graphql.Float,
    92  		},
    93  		"sparseSearch": &graphql.InputObjectFieldConfig{
    94  			Description: "Sparse Search",
    95  			Type: graphql.NewInputObject(
    96  				graphql.InputObjectConfig{
    97  					Name:        fmt.Sprintf("%sHybridGetBM25InpObj", prefixName),
    98  					Fields:      bm25Fields(prefixName),
    99  					Description: "BM25f search",
   100  				},
   101  			),
   102  		},
   103  
   104  		"nearText": &graphql.InputObjectFieldConfig{
   105  			Description: "nearText element",
   106  
   107  			Type: graphql.NewInputObject(
   108  				graphql.InputObjectConfig{
   109  					Name:        fmt.Sprintf("%sNearTextInpObj", prefixName),
   110  					Fields:      nearTextFields(prefixName),
   111  					Description: descriptions.GetWhereInpObj,
   112  				},
   113  			),
   114  		},
   115  	}
   116  }