Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(graphql): Add vector support to graphql #9074

Merged
merged 20 commits into from
Apr 18, 2024

Conversation

harshil-goel
Copy link
Contributor

@harshil-goel harshil-goel commented Apr 17, 2024

Adds support for vector predicate in GraphQL. Introduced new queries like similar_to() in graphql

sunilmujumdar and others added 8 commits April 17, 2024 17:46
…ch based on vector indexes (#48)

- [Float] data type with an @Embedding directive in GraphQL is mapped to
"VFLOAT" data type in dgraph
- @Embedding directive is allowed only for [Float] data type
- Add querySimilar<Type> query that performs similarity search based on
HNSW (vector) indexes for types with fields having @Embedding directive
- querySimilar<Type> accepts 3 arguments

1. id - unique id for the object to run similarity search on.
2. <predicate> - An enum of embedding predicates defined in the type to
base the search on
3. <topK> - number of nearest neighbors to return
…62)

Description: 

If topK argument in querySimilar* queries is a graphql variable dgraph
reported a panic as topK was explicitly cast as int.

The fix instead uses fmt.Sprintf("%v", topK) where topK is of type
interface{}. This works for when topK is passed as an int literal or a
graphql variable.

Fixes: HYP-328
… searches (#60)

Description: If the vector parameter in a similar_to function call is a
variable that evaluates to NULL then we report it as a parsing (syntax)
error.

The fix, instead of reporting a parsing error,  returns an empty result.

Closes: HYP-302

---------

Co-authored-by: Bill Province <billprovince@gmail.com>
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
…69)

Description: This PR adds support for specifying @search directive with
search options (vector index options)
The fix is not backward compatible. Earlier searchArgs in @search
directive were expected to be Enum of index types.
Arguments are expected to be strings now of the following form.
      `@search(by: [String!])`
where each string element in the array is of the form
      `<searchArg> := <searchType> [  ( <searchOptions> ) ]`
searchOptions are optional.
       ```
```
<searchOptions> :=  <searchOption> , <searchOption>, ...
       <searchOption> :=  <optionName><COLON><SPACE><optionValue>
```

```
For example:

`product_vector: [Float!] @hm_embedding @search(by: ["hnsw(metric: euclidian, exponent: 6)"])`

Fixes: HYP-313
…_distance field was getting clobbered (#77)

Description: 

```
querySimilar<Type> queries defined a new derived type "<Type>WithDistance" with a new field hm_distance.

However, if <Type> had any lists, hm_distance was getting clobbered by an "<ListFieldName>Aggregate" being added to <Type>

The fix essentially does away with the derived type <Type>WithDistance as the resultType for querySimilar<Type> queries. Instead, we add <embeddingFieldName>Distance field for each embedding in the <Type> definition itself. This would make it easy to add support for filters on embeddings.
```

Fixes: HYP-447
…ch-filter (#79)

This change adds filter agrument to querySimilarById &
querySimilarByEmbedding queries.

The filter argument is used as a "post-vector-serach-filter" to filter
out nodes returned by the vector search.

Fixes: HYP-334
…#82)

Description: 

Computes hm_distance based on the HNSW index metric ('euclidian',
'dotproduct', 'cosine')

Euclidian -  (v1 - v2) dot (v1 - v2)
Dot product - v1 dot v2
Cosine -    (v1 dot v2) / ((v1 dot v1) * (v2 dot v2))

Fixes: HYP-477
@harshil-goel harshil-goel requested a review from a team as a code owner April 17, 2024 13:02
@CLAassistant
Copy link

CLAassistant commented Apr 17, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ harshil-goel
✅ shivaji-dgraph
❌ sunilmujumdar
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@dgraph-bot dgraph-bot added area/testing Testing related issues area/graphql Issues related to GraphQL support on Dgraph. area/core internal mechanisms go Pull requests that update Go code labels Apr 17, 2024
@harshil-goel harshil-goel changed the title Add vector support to graphql Feat(graphql): Add vector support to graphql Apr 18, 2024
@harshil-goel harshil-goel merged commit 041ba15 into main Apr 18, 2024
11 of 12 checks passed
@harshil-goel harshil-goel deleted the harshil-goel/vectorGraphql branch April 18, 2024 11:06
@iyinoluwaayoola
Copy link

iyinoluwaayoola commented Apr 22, 2024

@harshil-goel Defining a field in graphql type as the bellow doesn't work:

embedding: [Float!] @embedding @search(by: ["hnsw(exponent: 4, metric: euclidian)"])
{"errors":[{"message":"resolving updateGQLSchema failed because while validating GraphQL schema: input:8475: Undefined type HNSWSearchFilter. (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core internal mechanisms area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues go Pull requests that update Go code
Development

Successfully merging this pull request may close these issues.

6 participants