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

Function TestSimilarToOptionsIntegration

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

Source from the content-addressed store, hash-verified

418}
419
420func TestSimilarToOptionsIntegration(t *testing.T) {
421 const pred = "voptions"
422 dropPredicate(pred)
423 t.Cleanup(func() { dropPredicate(pred) })
424
425 setSchema(fmt.Sprintf(vectorSchemaWithIndex, pred, "4", "euclidean"))
426
427 rdf := `<0x1> <voptions> "[0,0]" .
428 <0x2> <voptions> "[1,0]" .
429 <0x3> <voptions> "[2,0]" .
430 <0x4> <voptions> "[5,0]" .`
431 require.NoError(t, addTriplesToCluster(rdf))
432
433 t.Run("ef_override_named_param", func(t *testing.T) {
434 query := `{
435 results(func: similar_to(voptions, 3, "[0,0]", ef: 2)) {
436 uid
437 }
438 }`
439 resp := processQueryNoErr(t, query)
440
441 var result struct {
442 Data struct {
443 Results []struct {
444 UID string `json:"uid"`
445 } `json:"results"`
446 } `json:"data"`
447 }
448 require.NoError(t, json.Unmarshal([]byte(resp), &result))
449 require.Len(t, result.Data.Results, 3)
450
451 expected := map[string]struct{}{"0x1": {}, "0x2": {}, "0x3": {}}
452 for _, r := range result.Data.Results {
453 _, ok := expected[r.UID]
454 require.Truef(t, ok, "unexpected uid %s", r.UID)
455 delete(expected, r.UID)
456 }
457 require.Empty(t, expected)
458 })
459
460 t.Run("distance_threshold_named_param", func(t *testing.T) {
461 query := `{
462 results(func: similar_to(voptions, 4, "[0,0]", distance_threshold: 1.5)) {
463 uid
464 }
465 }`
466 resp := processQueryNoErr(t, query)
467
468 var result struct {
469 Data struct {
470 Results []struct {
471 UID string `json:"uid"`
472 } `json:"results"`
473 } `json:"data"`
474 }
475 require.NoError(t, json.Unmarshal([]byte(resp), &result))
476 require.Len(t, result.Data.Results, 2)
477

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.80
dropPredicateFunction · 0.70
setSchemaFunction · 0.70
addTriplesToClusterFunction · 0.70
processQueryNoErrFunction · 0.70
LenMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected