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

Function TestBulkLoadVectorIndex

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

Source from the content-addressed store, hash-verified

87}
88
89func TestBulkLoadVectorIndex(t *testing.T) {
90 // Step 1: Create a source cluster and load vectors into it
91 sourceConf := dgraphtest.NewClusterConfig().
92 WithNumAlphas(1).
93 WithNumZeros(1).
94 WithReplicas(1).
95 WithACL(time.Hour)
96 sourceCluster, err := dgraphtest.NewLocalCluster(sourceConf)
97 require.NoError(t, err)
98 defer func() { sourceCluster.Cleanup(t.Failed()) }()
99 require.NoError(t, sourceCluster.Start())
100
101 gc, cleanup, err := sourceCluster.Client()
102 require.NoError(t, err)
103 defer cleanup()
104 require.NoError(t, gc.LoginIntoNamespace(context.Background(),
105 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace))
106
107 hc, err := sourceCluster.HTTPClient()
108 require.NoError(t, err)
109 require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
110 dgraphapi.DefaultPassword, x.RootNamespace))
111
112 // Set up vector schema and load vectors
113 require.NoError(t, gc.SetupSchema(testSchema))
114
115 numVectors := 1000
116 pred := "project_description_v"
117 rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 10, pred)
118
119 mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
120 _, err = gc.Mutate(mu)
121 require.NoError(t, err)
122
123 // Verify vectors are loaded and queryable in source cluster
124 for _, vector := range vectors[:5] { // Test first 5 vectors
125 similarVectors, err := gc.QueryMultipleVectorsUsingSimilarTo(vector, pred, 5)
126 require.NoError(t, err)
127 require.GreaterOrEqual(t, len(similarVectors), 3, "similar_to query should return results")
128 }
129
130 // Step 2: Export the data from source cluster
131 require.NoError(t, hc.Export(dgraphtest.DefaultExportDir, "rdf", -1))
132
133 // Step 3: Set up a cluster for bulk loading and run bulk load on exported data
134 bulkOutDir := t.TempDir()
135 bulkConf := dgraphtest.NewClusterConfig().
136 WithNumAlphas(1).
137 WithNumZeros(1).
138 WithReplicas(1).
139 WithACL(time.Hour).
140 WithBulkLoadOutDir(bulkOutDir)
141
142 bulkCluster, err := dgraphtest.NewLocalCluster(bulkConf)
143 require.NoError(t, err)
144 defer func() { bulkCluster.Cleanup(t.Failed()) }()
145
146 // Start only Zero for bulk loading

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
GenerateRandomVectorsFunction · 0.92
cleanupFunction · 0.85

Tested by

no test coverage detected