MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestDotProductWithConstantVector

Function TestDotProductWithConstantVector

query/vector/vector_test.go:887–915  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

885}
886
887func TestDotProductWithConstantVector(t *testing.T) {
888 setSchema("vec452 : float32vector .")
889
890 rdfs := `
891 <1> <vec452> "[1.0, 1.0, 2.0, 2.0]" .
892 <2> <vec452> "[2.0, 1.0, 2.0, 2.0]" .`
893 require.NoError(t, addTriplesToCluster(rdfs))
894
895 query := `query q($vec: float32vector) {
896 q(func: has(vec452)) {
897 v1 as vec452
898 distance: Math(v1 dot $vec)
899 }
900 }`
901 js, err := processQueryWithVars(t, query, map[string]string{"$vec": "[1.0, 1.0, 2.0, 2.0]"})
902 require.NoError(t, err)
903 k := `{"data":{"q":[{"vec452":[1,1,2,2],"distance":10},{"vec452":[2,1,2,2],"distance":11}]}}`
904 require.JSONEq(t, k, js)
905
906 query = `{
907 q(func: has(vec452)) {
908 v1 as vec452
909 distance: Math(v1 dot v1)
910 }
911 }`
912 require.JSONEq(t,
913 `{"data":{"q":[{"vec452":[1,1,2,2],"distance":10},{"vec452":[2,1,2,2],"distance":13}]} }`,
914 processQueryNoErr(t, query))
915}

Callers

nothing calls this directly

Calls 4

setSchemaFunction · 0.70
addTriplesToClusterFunction · 0.70
processQueryWithVarsFunction · 0.70
processQueryNoErrFunction · 0.70

Tested by

no test coverage detected