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

Add vector type to Dgraph #9050

Merged
merged 13 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chunker/json_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func handleBasicType(k string, v interface{}, op int, nq *api.NQuad) error {
return nil
}

if vf, err := types.ParseVFloat(v); err == nil {
nq.ObjectValue = &api.Value{Val: &api.Value_Vfloat32Val{Vfloat32Val: types.FloatArrayAsBytes(vf)}}
return nil
}

// Handle the uid function in upsert block
s := stripSpaces(v)
if strings.HasPrefix(s, "uid(") || strings.HasPrefix(s, "val(") {
Expand Down
5 changes: 5 additions & 0 deletions dql/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func TypeValFrom(val *api.Value) types.Val {
return types.Val{Tid: types.DateTimeID, Value: val.GetDatetimeVal()}
case *api.Value_PasswordVal:
return types.Val{Tid: types.PasswordID, Value: val.GetPasswordVal()}
case *api.Value_Vfloat32Val:
return types.Val{
Tid: types.VFloatID,
Value: types.BytesAsFloatArray(val.GetVfloat32Val()),
}
case *api.Value_DefaultVal:
return types.Val{Tid: types.DefaultID, Value: val.GetDefaultVal()}
}
Expand Down
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/Masterminds/semver/v3 v3.1.0
github.com/blevesearch/bleve/v2 v2.3.10
github.com/dgraph-io/badger/v4 v4.2.0
github.com/dgraph-io/dgo/v230 v230.0.1
github.com/dgraph-io/dgo/v230 v230.0.2-0.20240314155021-7b8d289e37f3
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.2.1
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15
Expand All @@ -31,12 +31,12 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
github.com/golang/glog v1.1.0
github.com/golang/protobuf v1.5.3
github.com/golang/glog v1.2.0
github.com/golang/protobuf v1.5.4
github.com/golang/snappy v0.0.4
github.com/google/codesearch v1.0.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.4.2
github.com/graph-gophers/graphql-go v1.3.0
github.com/hashicorp/vault/api v1.0.4
Expand All @@ -51,21 +51,20 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/twpayne/go-geom v1.0.5
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
go.etcd.io/etcd/raft/v3 v3.5.9
go.opencensus.io v0.24.0
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.19.0
golang.org/x/net v0.21.0
golang.org/x/crypto v0.21.0
golang.org/x/net v0.22.0
golang.org/x/sync v0.6.0
golang.org/x/sys v0.17.0
golang.org/x/term v0.17.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.18.0
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.33.0
google.golang.org/grpc v1.62.1
gopkg.in/square/go-jose.v2 v2.3.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -141,13 +140,13 @@ require (
github.com/xdg/stringprep v1.0.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/api v0.122.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc/examples v0.0.0-20230821201920-d51b3f41716d // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/DataDog/dd-trace-go.v1 v1.22.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
58 changes: 30 additions & 28 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions graphql/e2e/common/error_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
gqlvariables: |
{ "filter": "type was wrong" }
errors:
[ { "message": "Variable type provided AuthorFiltarzzz! is incompatible with expected
type AuthorFilter",
"locations": [{ "line": 2, "column": 23}]},
[
{ "message": "Variable \"$filter\" of type \"AuthorFiltarzzz!\" used in position
expecting type \"AuthorFilter\".",
"locations": [ { "line": 2, "column": 23 } ] },
{ "message": "Variable type provided AuthorFiltarzzz! is incompatible with expected
type AuthorFilter",
"locations": [{ "line": 2, "column": 23}]},
{ "message": "Unknown type \"AuthorFiltarzzz\".",
"locations": [ { "line": 1, "column": 1 } ] } ]

Expand Down
6 changes: 3 additions & 3 deletions graphql/resolve/validate_mutation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
explanation: "Add mutation expects an array instead of an object"
validationerror:
{ "message":
"input:2: Variable type provided AddAuthorInput! is incompatible with expected type
[AddAuthorInput!]!\ninput:2: Variable \"$auth\" of type \"AddAuthorInput!\" used in
position expecting type \"[AddAuthorInput!]!\".\n" }
"input:2: Variable \"$auth\" of type \"AddAuthorInput!\" used in
position expecting type \"[AddAuthorInput!]!\".\ninput:2: Variable type provided AddAuthorInput! is incompatible with expected type
[AddAuthorInput!]!\n" }


-
Expand Down
19 changes: 19 additions & 0 deletions protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ message Result {
repeated FacetsList facet_matrix = 5;
repeated LangList lang_matrix = 6;
bool list = 7;
map<string, uint64> vector_metrics = 8;
}

message Order {
Expand Down Expand Up @@ -377,6 +378,10 @@ message Posting {
PASSWORD = 8;
STRING = 9;
OBJECT = 10;
// RESERVE 11 for BIGFLOAT, should we desire to pull
// that in at a later date. (There is a pending PR
// that uses this).
VFLOAT = 12; // Float64 Vector
}
ValType val_type = 3;
enum PostingType {
Expand Down Expand Up @@ -514,6 +519,20 @@ message SchemaUpdate {
// Deleted field:
reserved 7;
reserved "explicit";

repeated VectorIndexSpec index_specs = 15;
}

message VectorIndexSpec {
// This names the kind of Vector Index, e.g.,
// hnsw, lsh, hypertree, ...
string name = 1;
harshil-goel marked this conversation as resolved.
Show resolved Hide resolved
repeated OptionPair options = 2;
}

message OptionPair {
string key = 1;
string value = 2;
}

message TypeUpdate {
Expand Down
Loading
Loading