github.com/weaviate/weaviate@v1.24.6/adapters/handlers/graphql/local/aggregate/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 aggregate
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  
    18  	"github.com/tailor-inc/graphql"
    19  	"github.com/weaviate/weaviate/entities/models"
    20  )
    21  
    22  func hybridArgument(classObject *graphql.Object,
    23  	class *models.Class, modulesProvider ModulesProvider,
    24  ) *graphql.ArgumentConfig {
    25  	prefix := fmt.Sprintf("AggregateObjects%s", class.Class)
    26  	return &graphql.ArgumentConfig{
    27  		Type: graphql.NewInputObject(
    28  			graphql.InputObjectConfig{
    29  				Name:        fmt.Sprintf("%sHybridInpObj", prefix),
    30  				Fields:      hybridOperands(classObject, class, modulesProvider),
    31  				Description: "Hybrid search",
    32  			},
    33  		),
    34  	}
    35  }
    36  
    37  func hybridOperands(classObject *graphql.Object,
    38  	class *models.Class, modulesProvider ModulesProvider,
    39  ) graphql.InputObjectConfigFieldMap {
    40  	ss := graphql.NewInputObject(graphql.InputObjectConfig{
    41  		Name:   class.Class + "HybridSubSearch",
    42  		Fields: hybridSubSearch(classObject, class, modulesProvider),
    43  	})
    44  	fieldMap := graphql.InputObjectConfigFieldMap{
    45  		"query": &graphql.InputObjectFieldConfig{
    46  			Description: "Query string",
    47  			Type:        graphql.String,
    48  		},
    49  		"alpha": &graphql.InputObjectFieldConfig{
    50  			Description: "Search weight",
    51  			Type:        graphql.Float,
    52  		},
    53  		"vector": &graphql.InputObjectFieldConfig{
    54  			Description: "Vector search",
    55  			Type:        graphql.NewList(graphql.Float),
    56  		},
    57  		"targetVectors": &graphql.InputObjectFieldConfig{
    58  			Description: "Target vectors",
    59  			Type:        graphql.NewList(graphql.String),
    60  		},
    61  		"properties": &graphql.InputObjectFieldConfig{
    62  			Description: "Target vectors",
    63  			Type:        graphql.NewList(graphql.String),
    64  		},
    65  	}
    66  
    67  	if os.Getenv("ENABLE_EXPERIMENTAL_HYBRID_OPERANDS") != "" {
    68  		fieldMap["operands"] = &graphql.InputObjectFieldConfig{
    69  			Description: "Subsearch list",
    70  			Type:        graphql.NewList(ss),
    71  		}
    72  	}
    73  
    74  	return fieldMap
    75  }
    76  
    77  func hybridSubSearch(classObject *graphql.Object,
    78  	class *models.Class, modulesProvider ModulesProvider,
    79  ) graphql.InputObjectConfigFieldMap {
    80  	prefixName := class.Class + "SubSearch"
    81  
    82  	return graphql.InputObjectConfigFieldMap{
    83  		"weight": &graphql.InputObjectFieldConfig{
    84  			Description: "weight, 0 to 1",
    85  			Type:        graphql.Float,
    86  		},
    87  		"sparseSearch": &graphql.InputObjectFieldConfig{
    88  			Description: "Sparse Search",
    89  			Type: graphql.NewInputObject(
    90  				graphql.InputObjectConfig{
    91  					Name:        fmt.Sprintf("%sHybridAggregateBM25InpObj", prefixName),
    92  					Fields:      bm25Fields(prefixName),
    93  					Description: "BM25f search",
    94  				},
    95  			),
    96  		},
    97  	}
    98  }