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

Function TestBulkLoadVectorIndexMultipleGroups

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

Source from the content-addressed store, hash-verified

204}
205
206func TestBulkLoadVectorIndexMultipleGroups(t *testing.T) {
207 // Define 3 different vector predicates - each will potentially go to different shards
208 predicates := []string{"vec_pred_alpha", "vec_pred_beta", "vec_pred_gamma"}
209 numVectorsPerPred := 1000
210 vectorDim := 10
211 numShards := 3
212
213 // Schema with 3 vector predicates
214 multiPredSchema := `
215 vec_pred_alpha: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
216 vec_pred_beta: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
217 vec_pred_gamma: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
218 `
219
220 // Step 1: Create a source cluster and load vectors into it
221 sourceConf := dgraphtest.NewClusterConfig().
222 WithNumAlphas(1).
223 WithNumZeros(1).
224 WithReplicas(1).
225 WithACL(time.Hour)
226 sourceCluster, err := dgraphtest.NewLocalCluster(sourceConf)
227 require.NoError(t, err)
228 defer func() { sourceCluster.Cleanup(t.Failed()) }()
229 require.NoError(t, sourceCluster.Start())
230
231 gc, cleanup, err := sourceCluster.Client()
232 require.NoError(t, err)
233 defer cleanup()
234 require.NoError(t, gc.LoginIntoNamespace(context.Background(),
235 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace))
236
237 hc, err := sourceCluster.HTTPClient()
238 require.NoError(t, err)
239 require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
240 dgraphapi.DefaultPassword, x.RootNamespace))
241
242 // Set up schema with multiple vector predicates
243 require.NoError(t, gc.SetupSchema(multiPredSchema))
244
245 // Generate and load vectors for each predicate
246 allVectors := make(map[string][][]float32)
247 for _, pred := range predicates {
248 rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectorsPerPred, vectorDim, pred)
249 allVectors[pred] = vectors
250
251 mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
252 _, err = gc.Mutate(mu)
253 require.NoError(t, err)
254 }
255
256 // Verify vectors are loaded and queryable in source cluster
257 for _, pred := range predicates {
258 vectors := allVectors[pred]
259 similarVectors, err := gc.QueryMultipleVectorsUsingSimilarTo(vectors[0], pred, 5)
260 require.NoError(t, err)
261 require.GreaterOrEqual(t, len(similarVectors), 3, "similar_to query should return results for %s", pred)
262 }
263

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