MCPcopy
hub / github.com/dgraph-io/dgraph / TestBulkLoadVectorEdgeCases

Function TestBulkLoadVectorEdgeCases

systest/vector/load_test.go:631–784  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

629}
630
631func TestBulkLoadVectorEdgeCases(t *testing.T) {
632 // Schema with multiple vector predicates - some will have data, some won't
633 schema := `
634 vec_with_data: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
635 vec_single: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
636 vec_empty: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
637 name: string @index(exact) .
638 `
639
640 vectorDim := 10
641
642 // Step 1: Create source cluster
643 sourceConf := dgraphtest.NewClusterConfig().
644 WithNumAlphas(1).
645 WithNumZeros(1).
646 WithReplicas(1).
647 WithACL(time.Hour)
648 sourceCluster, err := dgraphtest.NewLocalCluster(sourceConf)
649 require.NoError(t, err)
650 defer func() { sourceCluster.Cleanup(t.Failed()) }()
651 require.NoError(t, sourceCluster.Start())
652
653 gc, cleanup, err := sourceCluster.Client()
654 require.NoError(t, err)
655 defer cleanup()
656 require.NoError(t, gc.LoginIntoNamespace(context.Background(),
657 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace))
658
659 hc, err := sourceCluster.HTTPClient()
660 require.NoError(t, err)
661 require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
662 dgraphapi.DefaultPassword, x.RootNamespace))
663
664 require.NoError(t, gc.SetupSchema(schema))
665
666 // Generate data:
667 // - vec_with_data: 100 vectors
668 // - vec_single: 1 vector
669 // - vec_empty: 0 vectors (schema only)
670
671 var rdfBuilder strings.Builder
672 var vectorsWithData [][]float32
673
674 // Add 100 vectors to vec_with_data
675 for i := 0; i < 100; i++ {
676 vec := dgraphapi.GenerateRandomVector(vectorDim)
677 vectorsWithData = append(vectorsWithData, vec)
678 vecStr := fmt.Sprintf(`"[%s]"`, strings.Trim(strings.Join(strings.Fields(fmt.Sprint(vec)), ", "), "[]"))
679 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <vec_with_data> %s .\n", i+10, vecStr))
680 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <name> \"entity_%d\" .\n", i+10, i))
681 }
682
683 // Add single vector to vec_single
684 singleVec := dgraphapi.GenerateRandomVector(vectorDim)
685 singleVecStr := fmt.Sprintf(`"[%s]"`, strings.Trim(strings.Join(strings.Fields(fmt.Sprint(singleVec)), ", "), "[]"))
686 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <vec_single> %s .\n", 1000, singleVecStr))
687 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <name> \"single_entity\" .\n", 1000))
688

Callers

nothing calls this directly

Calls 15

CleanupMethod · 0.95
StartMethod · 0.95
ClientMethod · 0.95
HTTPClientMethod · 0.95
StartZeroMethod · 0.95
HealthCheckMethod · 0.95
CopyExportToHostMethod · 0.95
BulkLoadMethod · 0.95
NewClusterConfigFunction · 0.92
NewLocalClusterFunction · 0.92
GenerateRandomVectorFunction · 0.92
cleanupFunction · 0.85

Tested by

no test coverage detected