github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearText/graphql_argument.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 "fmt" 16 17 "github.com/tailor-inc/graphql" 18 "github.com/weaviate/weaviate/adapters/handlers/graphql/descriptions" 19 ) 20 21 func (g *GraphQLArgumentsProvider) getNearTextArgumentFn(classname string) *graphql.ArgumentConfig { 22 return g.nearTextArgument("GetObjects", classname) 23 } 24 25 func (g *GraphQLArgumentsProvider) aggregateNearTextArgumentFn(classname string) *graphql.ArgumentConfig { 26 return g.nearTextArgument("Aggregate", classname) 27 } 28 29 func (g *GraphQLArgumentsProvider) exploreNearTextArgumentFn() *graphql.ArgumentConfig { 30 return g.nearTextArgument("Explore", "") 31 } 32 33 func (g *GraphQLArgumentsProvider) nearTextArgument(prefix, className string) *graphql.ArgumentConfig { 34 prefixName := fmt.Sprintf("%s%s", prefix, className) 35 return &graphql.ArgumentConfig{ 36 Type: graphql.NewInputObject( 37 graphql.InputObjectConfig{ 38 Name: fmt.Sprintf("%sNearTextInpObj", prefixName), 39 Fields: g.nearTextFields(prefixName), 40 Description: descriptions.GetWhereInpObj, 41 }, 42 ), 43 } 44 } 45 46 func (g *GraphQLArgumentsProvider) nearTextFields(prefix string) graphql.InputObjectConfigFieldMap { 47 nearTextFields := graphql.InputObjectConfigFieldMap{ 48 "concepts": &graphql.InputObjectFieldConfig{ 49 // Description: descriptions.Concepts, 50 Type: graphql.NewNonNull(graphql.NewList(graphql.String)), 51 }, 52 "moveTo": &graphql.InputObjectFieldConfig{ 53 Description: descriptions.VectorMovement, 54 Type: graphql.NewInputObject( 55 graphql.InputObjectConfig{ 56 Name: fmt.Sprintf("%sMoveTo", prefix), 57 Fields: g.movementInp(fmt.Sprintf("%sMoveTo", prefix)), 58 }), 59 }, 60 "certainty": &graphql.InputObjectFieldConfig{ 61 Description: descriptions.Certainty, 62 Type: graphql.Float, 63 }, 64 "distance": &graphql.InputObjectFieldConfig{ 65 Description: descriptions.Distance, 66 Type: graphql.Float, 67 }, 68 "moveAwayFrom": &graphql.InputObjectFieldConfig{ 69 Description: descriptions.VectorMovement, 70 Type: graphql.NewInputObject( 71 graphql.InputObjectConfig{ 72 Name: fmt.Sprintf("%sMoveAwayFrom", prefix), 73 Fields: g.movementInp(fmt.Sprintf("%sMoveAwayFrom", prefix)), 74 }), 75 }, 76 "targetVectors": &graphql.InputObjectFieldConfig{ 77 Description: "Target vectors", 78 Type: graphql.NewList(graphql.String), 79 }, 80 } 81 if g.nearTextTransformer != nil { 82 nearTextFields["autocorrect"] = &graphql.InputObjectFieldConfig{ 83 Description: "Autocorrect input text values", 84 Type: graphql.Boolean, 85 } 86 } 87 return nearTextFields 88 } 89 90 func (g *GraphQLArgumentsProvider) movementInp(prefix string) graphql.InputObjectConfigFieldMap { 91 return graphql.InputObjectConfigFieldMap{ 92 "concepts": &graphql.InputObjectFieldConfig{ 93 Description: descriptions.Keywords, 94 Type: graphql.NewList(graphql.String), 95 }, 96 "objects": &graphql.InputObjectFieldConfig{ 97 Description: "objects", 98 Type: graphql.NewList(g.objectsInpObj(prefix)), 99 }, 100 "force": &graphql.InputObjectFieldConfig{ 101 Description: descriptions.Force, 102 Type: graphql.NewNonNull(graphql.Float), 103 }, 104 } 105 } 106 107 func (g *GraphQLArgumentsProvider) objectsInpObj(prefix string) *graphql.InputObject { 108 return graphql.NewInputObject( 109 graphql.InputObjectConfig{ 110 Name: fmt.Sprintf("%sMovementObjectsInpObj", prefix), 111 Fields: graphql.InputObjectConfigFieldMap{ 112 "id": &graphql.InputObjectFieldConfig{ 113 Type: graphql.String, 114 Description: "id of an object", 115 }, 116 "beacon": &graphql.InputObjectFieldConfig{ 117 Type: graphql.String, 118 Description: descriptions.Beacon, 119 }, 120 }, 121 Description: "Movement Object", 122 }, 123 ) 124 }