Skip to content

Commit

Permalink
Bug(GraphQL): Fixed HYP-336 (#70)
Browse files Browse the repository at this point in the history
Description: Made the embedding parameeter, by, to be NonNull for
`querySimilar<Type>ById `& `querySimilar<Type>ByEmbedding ` queries.
This fixes the backend panic.

However, the postman client fails to show the dropdown as in the input
for the parameter. It shows it as a simple text input box. The client,
while editing the query text in the editor pane shows valid enum values
as part of the autocomplete feature.

Fixes: HYP-336
  • Loading branch information
sunilmujumdar authored and harshil-goel committed Apr 17, 2024
1 parent db980de commit 1c3c897
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions graphql/resolve/resolver_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ type Author {
postsNullableListRequired: [Post]!
}
type Product {
id: String! @id
description: String
title: String
imageUrl: String
productVector: [Float] @hm_embedding
}
type Post {
id: ID!
title: String!
Expand Down
10 changes: 9 additions & 1 deletion graphql/resolve/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,12 @@ type CricketTeam implements Team {
type LibraryManager {
name: String! @id
manages: [LibraryMember]
}
}

type Product {
id: String! @id
description: String
title: String
imageUrl: String
productVector: [Float] @hm_embedding
}
5 changes: 3 additions & 2 deletions graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ func addSimilarByEmbeddingQuery(schema *ast.Schema, defn *ast.Definition) {
//Accept the name of embedding field
qry.Arguments = append(qry.Arguments, &ast.ArgumentDefinition{
Name: SimilarByArgName,
Type: &ast.Type{NamedType: enumName},
Type: &ast.Type{NamedType: enumName, NonNull: true},
})

// Accept the topK, number of nearest neighbors to
Expand All @@ -2100,6 +2100,7 @@ func addSimilarByEmbeddingQuery(schema *ast.Schema, defn *ast.Definition) {
NamedType: "Float",
NonNull: true,
},
NonNull: true,
},
})

Expand Down Expand Up @@ -2220,7 +2221,7 @@ func addSimilarByIdQuery(schema *ast.Schema, defn *ast.Definition,
// Accept the name of the embedding field.
qry.Arguments = append(qry.Arguments, &ast.ArgumentDefinition{
Name: SimilarByArgName,
Type: &ast.Type{NamedType: enumName},
Type: &ast.Type{NamedType: enumName, NonNull: true},
})

// Accept the topK, number of nearest neighbors to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,15 @@ input UserRef {

type Query {
getProduct(id: String!): Product
querySimilarProductById(id: String!, by: ProductEmbedding, topK: Int!): [ProductWithDistance]
querySimilarProductByEmbedding(by: ProductEmbedding, topK: Int!, vector: [Float!]): [ProductWithDistance]
querySimilarProductById(id: String!, by: ProductEmbedding!, topK: Int!): [ProductWithDistance]
querySimilarProductByEmbedding(by: ProductEmbedding!, topK: Int!, vector: [Float!]!): [ProductWithDistance]
queryProduct(filter: ProductFilter, order: ProductOrder, first: Int, offset: Int): [Product]
aggregateProduct(filter: ProductFilter): ProductAggregateResult
queryPurchase(filter: PurchaseFilter, order: PurchaseOrder, first: Int, offset: Int): [Purchase]
aggregatePurchase(filter: PurchaseFilter): PurchaseAggregateResult
getUser(email: String!): User
querySimilarUserById(email: String!, by: UserEmbedding, topK: Int!): [UserWithDistance]
querySimilarUserByEmbedding(by: UserEmbedding, topK: Int!, vector: [Float!]): [UserWithDistance]
querySimilarUserById(email: String!, by: UserEmbedding!, topK: Int!): [UserWithDistance]
querySimilarUserByEmbedding(by: UserEmbedding!, topK: Int!, vector: [Float!]!): [UserWithDistance]
queryUser(filter: UserFilter, order: UserOrder, first: Int, offset: Int): [User]
aggregateUser(filter: UserFilter): UserAggregateResult
}
Expand Down

0 comments on commit 1c3c897

Please sign in to comment.