ADAPT-Chase commited on
Commit
c7d8ce7
·
verified ·
1 Parent(s): 30dac3e

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_aggregate.go +113 -0
  2. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_batch.go +323 -0
  3. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_byov_with_vectorizer.go +113 -0
  4. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_colbert.go +788 -0
  5. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_generative.go +123 -0
  6. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_hybrid.go +201 -0
  7. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects.go +297 -0
  8. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_mixed.go +265 -0
  9. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_none_vectorizer.go +236 -0
  10. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_properties.go +231 -0
  11. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_ref_props.go +288 -0
  12. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_restart.go +123 -0
  13. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_schema.go +240 -0
  14. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_schema_validation.go +276 -0
  15. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_test_data.go +373 -0
  16. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_vector_index_types.go +290 -0
  17. platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/__init__.py +0 -0
  18. platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/test_multi_tenant.py +0 -0
  19. platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/test_named_vectors.py +58 -0
  20. platform/dbops/binaries/weaviate-src/test/acceptance_with_python/rbac/__init__.py +0 -0
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_aggregate.go ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+ "time"
18
+
19
+ "github.com/stretchr/testify/assert"
20
+ "github.com/stretchr/testify/require"
21
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
22
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/entities/schema"
25
+ )
26
+
27
+ const (
28
+ UUID1 = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
29
+ UUID2 = "f47ac10b-58cc-0372-8567-0e02b2c3d480"
30
+ )
31
+
32
+ func testAggregate(host string) func(t *testing.T) {
33
+ return func(t *testing.T) {
34
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
35
+ require.Nil(t, err)
36
+ ctx := context.Background()
37
+
38
+ classAggregate := "NamedAggregateTest"
39
+
40
+ // delete class if exists and cleanup after test
41
+ err = client.Schema().ClassDeleter().WithClassName(classAggregate).Do(ctx)
42
+ require.Nil(t, err)
43
+
44
+ defer client.Schema().ClassDeleter().WithClassName(classAggregate).Do(ctx)
45
+
46
+ // create class and objects
47
+ class := &models.Class{
48
+ Class: classAggregate,
49
+ Properties: []*models.Property{
50
+ {
51
+ Name: "first", DataType: []string{schema.DataTypeText.String()},
52
+ },
53
+ {
54
+ Name: "second", DataType: []string{schema.DataTypeText.String()},
55
+ },
56
+ {
57
+ Name: "number", DataType: []string{schema.DataTypeInt.String()},
58
+ },
59
+ },
60
+ VectorConfig: map[string]models.VectorConfig{
61
+ "first": {
62
+ Vectorizer: map[string]interface{}{
63
+ "text2vec-model2vec": map[string]interface{}{
64
+ "vectorizeClassName": false,
65
+ "properties": []string{"first"},
66
+ },
67
+ },
68
+ VectorIndexType: "hnsw",
69
+ },
70
+ "second": {
71
+ Vectorizer: map[string]interface{}{
72
+ "text2vec-model2vec": map[string]interface{}{
73
+ "vectorizeClassName": false,
74
+ "properties": []string{"second"},
75
+ },
76
+ },
77
+ VectorIndexType: "hnsw",
78
+ },
79
+ },
80
+ }
81
+ require.Nil(t, client.Schema().ClassCreator().WithClass(class).Do(ctx))
82
+
83
+ creator := client.Data().Creator()
84
+ _, err = creator.WithClassName(classAggregate).WithProperties(
85
+ map[string]interface{}{"first": "Hello", "second": "World", "number": 1}).WithID(UUID1).Do(ctx)
86
+ require.Nil(t, err)
87
+ _, err = creator.WithClassName(classAggregate).WithProperties(
88
+ map[string]interface{}{"first": "World", "second": "Hello", "number": 2}).WithID(UUID2).Do(ctx)
89
+ require.Nil(t, err)
90
+
91
+ // aggregate
92
+ no := &graphql.NearObjectArgumentBuilder{}
93
+ no.WithTargetVectors("first").WithID(UUID1).WithCertainty(0.9)
94
+
95
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
96
+ agg, err := client.GraphQL().Aggregate().WithClassName(classAggregate).WithNearObject(no).WithFields(graphql.Field{Name: "number", Fields: []graphql.Field{{Name: "maximum"}}}).Do(ctx)
97
+ require.Nil(ct, err)
98
+
99
+ assert.NotNil(ct, agg)
100
+ assert.Nil(ct, agg.Errors)
101
+ assert.NotNil(ct, agg.Data)
102
+ assert.Equal(ct, agg.Data["Aggregate"].(map[string]interface{})[classAggregate].([]interface{})[0].(map[string]interface{})["number"].(map[string]interface{})["maximum"], float64(1))
103
+
104
+ // aggregate without needed a target vector
105
+ agg, err = client.GraphQL().Aggregate().WithClassName(classAggregate).WithFields(graphql.Field{Name: "meta", Fields: []graphql.Field{{Name: "count"}}}).Do(ctx)
106
+ assert.Nil(ct, err)
107
+ assert.NotNil(ct, agg)
108
+ assert.Nil(ct, agg.Errors)
109
+ assert.NotNil(ct, agg.Data)
110
+ assert.Equal(ct, agg.Data["Aggregate"].(map[string]interface{})[classAggregate].([]interface{})[0].(map[string]interface{})["meta"].(map[string]interface{})["count"], float64(2))
111
+ }, 15*time.Second, 500*time.Millisecond)
112
+ }
113
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_batch.go ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
24
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/entities/schema"
27
+ )
28
+
29
+ func testBatchObject(host string) func(t *testing.T) {
30
+ return func(t *testing.T) {
31
+ ctx := context.Background()
32
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
33
+ require.Nil(t, err)
34
+
35
+ cleanup := func() {
36
+ err := client.Schema().AllDeleter().Do(context.Background())
37
+ require.Nil(t, err)
38
+ }
39
+
40
+ idsToDelete := []string{id1, id2}
41
+ hasBeenDeleted := func(id string) bool {
42
+ for _, deletedId := range idsToDelete {
43
+ if deletedId == id {
44
+ return true
45
+ }
46
+ }
47
+ return false
48
+ }
49
+
50
+ t.Run("multiple named vectors", func(t *testing.T) {
51
+ cleanup()
52
+
53
+ t.Run("create schema", func(t *testing.T) {
54
+ createNamedVectorsClass(t, client)
55
+ })
56
+
57
+ t.Run("batch create objects", func(t *testing.T) {
58
+ objs := []*models.Object{}
59
+ for id, book := range fixtures.Books() {
60
+ obj := &models.Object{
61
+ Class: className,
62
+ ID: strfmt.UUID(id),
63
+ Properties: map[string]interface{}{
64
+ "text": book.Description,
65
+ },
66
+ }
67
+ objs = append(objs, obj)
68
+ }
69
+
70
+ resp, err := client.Batch().ObjectsBatcher().
71
+ WithObjects(objs...).
72
+ Do(ctx)
73
+ require.NoError(t, err)
74
+ require.NotNil(t, resp)
75
+ })
76
+
77
+ t.Run("check existence", func(t *testing.T) {
78
+ for id := range fixtures.Books() {
79
+ exists, err := client.Data().Checker().
80
+ WithID(id).
81
+ WithClassName(className).
82
+ Do(ctx)
83
+ require.NoError(t, err)
84
+ require.True(t, exists)
85
+ }
86
+ })
87
+
88
+ t.Run("check if all objects have been indexed", func(t *testing.T) {
89
+ testAllObjectsIndexed(t, client, className)
90
+ })
91
+
92
+ t.Run("GraphQL get vectors", func(t *testing.T) {
93
+ for id := range fixtures.Books() {
94
+ resultVectors := getVectors(t, client, className, id, targetVectors...)
95
+ checkTargetVectors(t, resultVectors)
96
+ }
97
+ })
98
+
99
+ t.Run("GraphQL near<Media> check", func(t *testing.T) {
100
+ for id, book := range fixtures.Books() {
101
+ for _, targetVector := range targetVectors {
102
+ nearText := client.GraphQL().NearTextArgBuilder().
103
+ WithConcepts([]string{book.Title}).
104
+ WithTargetVectors(targetVector)
105
+ resultVectors := getVectorsWithNearText(t, client, className, id, nearText, targetVectors...)
106
+ checkTargetVectors(t, resultVectors)
107
+ }
108
+ }
109
+ })
110
+
111
+ t.Run("batch delete objects", func(t *testing.T) {
112
+ where := filters.Where().
113
+ WithPath([]string{"id"}).
114
+ WithOperator(filters.ContainsAny).
115
+ WithValueText(idsToDelete...)
116
+ resp, err := client.Batch().ObjectsBatchDeleter().
117
+ WithClassName(className).
118
+ WithDryRun(true).
119
+ WithOutput("verbose").
120
+ WithWhere(where).
121
+ Do(ctx)
122
+ require.NoError(t, err)
123
+ require.NotNil(t, resp)
124
+ require.NotNil(t, resp.Results)
125
+ require.Len(t, resp.Results.Objects, 2)
126
+ for _, res := range resp.Results.Objects {
127
+ require.Nil(t, res.Errors)
128
+ require.NotNil(t, res.Status)
129
+ assert.Equal(t, models.BatchDeleteResponseResultsObjectsItems0StatusDRYRUN, *res.Status)
130
+ }
131
+
132
+ resp, err = client.Batch().ObjectsBatchDeleter().
133
+ WithClassName(className).
134
+ WithDryRun(false).
135
+ WithOutput("verbose").
136
+ WithWhere(where).
137
+ Do(ctx)
138
+ require.NoError(t, err)
139
+ require.NotNil(t, resp)
140
+ require.NotNil(t, resp.Results)
141
+ require.Len(t, resp.Results.Objects, 2)
142
+ for _, res := range resp.Results.Objects {
143
+ require.Nil(t, res.Errors)
144
+ require.NotNil(t, res.Status)
145
+ assert.Equal(t, models.BatchDeleteResponseResultsObjectsItems0StatusSUCCESS, *res.Status)
146
+ }
147
+
148
+ for id := range fixtures.Books() {
149
+ exists, err := client.Data().Checker().
150
+ WithID(id).
151
+ WithClassName(className).
152
+ Do(ctx)
153
+ require.NoError(t, err)
154
+ isDeleted := false
155
+ for _, deletedID := range idsToDelete {
156
+ if id == deletedID {
157
+ isDeleted = true
158
+ break
159
+ }
160
+ }
161
+ require.Equal(t, !isDeleted, exists)
162
+ }
163
+ })
164
+
165
+ t.Run("batch update objects and check if vectors changed", func(t *testing.T) {
166
+ existingIds := []string{}
167
+ for id := range fixtures.Books() {
168
+ if !hasBeenDeleted(id) {
169
+ existingIds = append(existingIds, id)
170
+ }
171
+ }
172
+ beforeUpdateVectorsMap := map[string]map[string][]float32{}
173
+ for _, id := range existingIds {
174
+ beforeUpdateVectors := getVectors(t, client, className, id, targetVectors...)
175
+ checkTargetVectors(t, beforeUpdateVectors)
176
+ }
177
+
178
+ objs := []*models.Object{}
179
+ for id, book := range fixtures.Books() {
180
+ obj := &models.Object{
181
+ Class: className,
182
+ ID: strfmt.UUID(id),
183
+ Properties: map[string]interface{}{
184
+ "text": book.Title,
185
+ },
186
+ }
187
+ objs = append(objs, obj)
188
+ }
189
+ resp, err := client.Batch().ObjectsBatcher().
190
+ WithObjects(objs...).
191
+ Do(ctx)
192
+ require.NoError(t, err)
193
+ require.NotNil(t, resp)
194
+
195
+ for _, id := range existingIds {
196
+ afterUpdateVectors := getVectors(t, client, className, id, targetVectors...)
197
+ checkTargetVectors(t, afterUpdateVectors)
198
+ beforeUpdateVectors := beforeUpdateVectorsMap[id]
199
+ for _, targetVector := range targetVectors {
200
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
201
+ }
202
+ }
203
+ })
204
+ })
205
+
206
+ t.Run("bring your own vectors", func(t *testing.T) {
207
+ cleanup()
208
+ tests := []struct {
209
+ name string
210
+ className string
211
+ vectorConfig map[string]models.VectorConfig
212
+ vectors models.Vectors
213
+ generatedTargetVectors []string
214
+ }{
215
+ {
216
+ name: "with 2 none vectorizers",
217
+ className: "OnlyNoneVectorizers",
218
+ vectorConfig: map[string]models.VectorConfig{
219
+ "none1": {
220
+ Vectorizer: map[string]interface{}{
221
+ "none": nil,
222
+ },
223
+ VectorIndexType: "hnsw",
224
+ },
225
+ "none2": {
226
+ Vectorizer: map[string]interface{}{
227
+ "none": nil,
228
+ },
229
+ VectorIndexType: "flat",
230
+ },
231
+ },
232
+ vectors: models.Vectors{
233
+ "none1": []float32{1, 2},
234
+ "none2": []float32{0.11, 0.22, 0.33},
235
+ },
236
+ },
237
+ {
238
+ name: "with 2 none vectorizers and 2 generated vectors",
239
+ className: "NoneAndGeneratedVectorizers",
240
+ vectorConfig: map[string]models.VectorConfig{
241
+ "none1": {
242
+ Vectorizer: map[string]interface{}{
243
+ "none": nil,
244
+ },
245
+ VectorIndexType: "hnsw",
246
+ },
247
+ "none2": {
248
+ Vectorizer: map[string]interface{}{
249
+ "none": nil,
250
+ },
251
+ VectorIndexType: "flat",
252
+ },
253
+ m2vec: {
254
+ Vectorizer: map[string]interface{}{
255
+ text2vecModel2Vec: map[string]interface{}{
256
+ "vectorizeClassName": false,
257
+ },
258
+ },
259
+ VectorIndexType: "hnsw",
260
+ },
261
+ transformers_flat: {
262
+ Vectorizer: map[string]interface{}{
263
+ text2vecTransformers: map[string]interface{}{
264
+ "vectorizeClassName": false,
265
+ },
266
+ },
267
+ VectorIndexType: "flat",
268
+ },
269
+ },
270
+ vectors: models.Vectors{
271
+ "none1": []float32{1, 2},
272
+ "none2": []float32{0.11, 0.22, 0.33},
273
+ },
274
+ generatedTargetVectors: []string{m2vec, transformers_flat},
275
+ },
276
+ }
277
+ for _, tt := range tests {
278
+ class := &models.Class{
279
+ Class: tt.className,
280
+ Properties: []*models.Property{
281
+ {
282
+ Name: "name",
283
+ DataType: []string{schema.DataTypeText.String()},
284
+ },
285
+ },
286
+ VectorConfig: tt.vectorConfig,
287
+ }
288
+ err = client.Schema().ClassCreator().WithClass(class).Do(ctx)
289
+ require.NoError(t, err)
290
+ // perform batch import
291
+ id := strfmt.UUID("00000000-0000-0000-0000-000000000001")
292
+ vectors := tt.vectors
293
+ object := &models.Object{
294
+ ID: id,
295
+ Class: tt.className,
296
+ Properties: map[string]interface{}{
297
+ "name": "some name",
298
+ },
299
+ Vectors: vectors,
300
+ }
301
+ batchResponse, err := client.Batch().ObjectsBatcher().WithObjects(object).Do(ctx)
302
+ require.NoError(t, err)
303
+ assert.NotNil(t, batchResponse)
304
+ assert.Equal(t, 1, len(batchResponse))
305
+ // get object
306
+ objs, err := client.Data().ObjectsGetter().
307
+ WithClassName(tt.className).WithID(id.String()).WithVector().
308
+ Do(ctx)
309
+ require.NoError(t, err)
310
+ require.NotEmpty(t, objs)
311
+ require.Len(t, objs, 1)
312
+ assert.Equal(t, id, objs[0].ID)
313
+ require.Len(t, objs[0].Vectors, len(tt.vectors)+len(tt.generatedTargetVectors))
314
+ for targetVector, vector := range objs[0].Vectors {
315
+ assert.Equal(t, vector, objs[0].Vectors[targetVector])
316
+ }
317
+ for _, generatedTargetVector := range tt.generatedTargetVectors {
318
+ assert.NotEmpty(t, objs[0].Vectors[generatedTargetVector])
319
+ }
320
+ }
321
+ })
322
+ }
323
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_byov_with_vectorizer.go ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "github.com/stretchr/testify/require"
19
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
20
+ "github.com/weaviate/weaviate/entities/models"
21
+ "github.com/weaviate/weaviate/entities/schema"
22
+ )
23
+
24
+ const (
25
+ UUID3 = "00000000-0000-0000-0000-000000000001"
26
+ UUID4 = "00000000-0000-0000-0000-000000000002"
27
+ )
28
+
29
+ func testCreateSchemaWithVectorizerAndBYOV(host string) func(t *testing.T) {
30
+ return func(t *testing.T) {
31
+ ctx := context.Background()
32
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
33
+ require.Nil(t, err)
34
+ require.Nil(t, client.Schema().AllDeleter().Do(context.Background()))
35
+
36
+ cleanup := func() {
37
+ err := client.Schema().AllDeleter().Do(context.Background())
38
+ require.Nil(t, err)
39
+ }
40
+
41
+ defer cleanup()
42
+
43
+ className := "BYOVwithVectorizer"
44
+
45
+ class := &models.Class{
46
+ Class: className,
47
+ Properties: []*models.Property{
48
+ {
49
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
50
+ },
51
+ },
52
+ VectorConfig: map[string]models.VectorConfig{
53
+ "byov": {
54
+ Vectorizer: map[string]interface{}{
55
+ "text2vec-model2vec": map[string]interface{}{
56
+ "vectorizeClassName": false,
57
+ },
58
+ },
59
+ VectorIndexType: "hnsw",
60
+ },
61
+ "generate": {
62
+ Vectorizer: map[string]interface{}{
63
+ "text2vec-model2vec": map[string]interface{}{
64
+ "vectorizeClassName": false,
65
+ },
66
+ },
67
+ VectorIndexType: "hnsw",
68
+ },
69
+ },
70
+ }
71
+
72
+ require.NoError(t, client.Schema().ClassCreator().WithClass(class).Do(ctx))
73
+
74
+ _, err = client.Data().Creator().
75
+ WithClassName(className).
76
+ WithID(UUID3).
77
+ WithProperties(map[string]interface{}{
78
+ "text": "banana",
79
+ }).
80
+ Do(ctx)
81
+ require.NoError(t, err)
82
+
83
+ objWithoutVector, err := client.Data().ObjectsGetter().
84
+ WithClassName(className).
85
+ WithID(UUID3).
86
+ WithVector().
87
+ Do(ctx)
88
+ require.NoError(t, err)
89
+ require.Len(t, objWithoutVector, 1)
90
+ require.Len(t, objWithoutVector[0].Vectors["byov"], 512)
91
+
92
+ // add an object with the same vector but different properties
93
+ _, err = client.Data().Creator().
94
+ WithClassName(className).
95
+ WithID(UUID4).
96
+ WithProperties(map[string]interface{}{
97
+ "text": "apple",
98
+ }).WithVectors(models.Vectors{"byov": objWithoutVector[0].Vectors["byov"]}).
99
+ Do(ctx)
100
+
101
+ // vector "byov" must be the same as the same vector was explicitly given to the second object
102
+ // vector "generated" must be different because it gets generated on different data for both objects
103
+ objWithVector, err := client.Data().ObjectsGetter().
104
+ WithClassName(className).
105
+ WithID(UUID4).
106
+ WithVector().
107
+ Do(ctx)
108
+ require.NoError(t, err)
109
+ require.Len(t, objWithoutVector, 1)
110
+ require.Equal(t, objWithVector[0].Vectors["byov"], objWithoutVector[0].Vectors["byov"])
111
+ require.NotEqual(t, objWithVector[0].Vectors["generate"], objWithoutVector[0].Vectors["generate"])
112
+ }
113
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_colbert.go ADDED
@@ -0,0 +1,788 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ acceptance_with_go_client "acceptance_tests_with_client"
21
+ "acceptance_tests_with_client/fixtures"
22
+
23
+ "github.com/go-openapi/strfmt"
24
+ "github.com/stretchr/testify/assert"
25
+ "github.com/stretchr/testify/require"
26
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
27
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
28
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
29
+ "github.com/weaviate/weaviate/entities/models"
30
+ "github.com/weaviate/weaviate/entities/schema"
31
+ )
32
+
33
+ func testColBERT(host string, asyncIndexingEnabled bool) func(t *testing.T) {
34
+ return func(t *testing.T) {
35
+ ctx := context.Background()
36
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
37
+ require.Nil(t, err)
38
+
39
+ cleanup := func() {
40
+ err := client.Schema().AllDeleter().Do(context.Background())
41
+ require.Nil(t, err)
42
+ }
43
+
44
+ t.Run("bring your own multivector", func(t *testing.T) {
45
+ cleanup()
46
+
47
+ className := fixtures.BringYourOwnColBERTClassName
48
+ objects := fixtures.BringYourOwnColBERTObjects
49
+ byoc := fixtures.BringYourOwnColBERTNamedVectorName
50
+ normalVector2dName := fixtures.NormalVector2dName
51
+ multiVector1dName := fixtures.MultiVector1dName
52
+ multiVector2dName := fixtures.MultiVector2dName
53
+ multiVector3dName := fixtures.MultiVector3dName
54
+ multiVector1dFromMultiVector2d := func(mv [][]float32) [][]float32 {
55
+ multiVector1d := make([][]float32, len(mv))
56
+ for i, v := range mv {
57
+ multiVector1d[i] = []float32{v[0]}
58
+ }
59
+ return multiVector1d
60
+ }
61
+ multiVector3dFromMultiVector2d := func(mv [][]float32) [][]float32 {
62
+ multiVector3d := make([][]float32, len(mv))
63
+ for i, v := range mv {
64
+ multiVector3d[i] = []float32{v[0], v[1], v[1]}
65
+ }
66
+ return multiVector3d
67
+ }
68
+
69
+ _additional_byoc := graphql.Field{
70
+ Name: "_additional",
71
+ Fields: []graphql.Field{
72
+ {Name: "id"},
73
+ {Name: fmt.Sprintf("vectors{%s}", byoc)},
74
+ },
75
+ }
76
+
77
+ performNearVector := func(t *testing.T, ct *assert.CollectT, client *wvt.Client, className string) {
78
+ nearVector := client.GraphQL().NearVectorArgBuilder().
79
+ WithVector([][]float32{{-0.000001, -0.000001}, {-0.000001, -0.000001}, {-0.000001, -0.000001}}).
80
+ WithTargetVectors(byoc)
81
+ resp, err := client.GraphQL().Get().
82
+ WithClassName(className).
83
+ WithNearVector(nearVector).
84
+ WithFields(_additional_byoc).
85
+ Do(ctx)
86
+ require.NoError(t, err)
87
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
88
+ require.NotEmpty(t, ids)
89
+ if ct != nil {
90
+ // adds ability to be used with assert.EventuallyWithT(...)
91
+ assert.Len(ct, ids, len(objects))
92
+ } else {
93
+ assert.Len(t, ids, len(objects))
94
+ }
95
+ }
96
+
97
+ performNearObject := func(t *testing.T, ct *assert.CollectT, client *wvt.Client, className string) {
98
+ nearObject := client.GraphQL().NearObjectArgBuilder().
99
+ WithID(objects[0].ID).
100
+ WithTargetVectors(byoc)
101
+ resp, err := client.GraphQL().Get().
102
+ WithClassName(className).
103
+ WithNearObject(nearObject).
104
+ WithFields(_additional_byoc).
105
+ Do(ctx)
106
+ require.NoError(t, err)
107
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
108
+ require.NotEmpty(t, ids)
109
+ if ct != nil {
110
+ // adds ability to be used with assert.EventuallyWithT(...)
111
+ assert.Len(ct, ids, len(objects))
112
+ } else {
113
+ assert.Len(t, ids, len(objects))
114
+ }
115
+ }
116
+
117
+ t.Run("create schema", func(t *testing.T) {
118
+ class := fixtures.BringYourOwnColBERTClass(className)
119
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
120
+ require.NoError(t, err)
121
+ })
122
+
123
+ t.Run("batch create objects", func(t *testing.T) {
124
+ objs := []*models.Object{}
125
+ for _, o := range objects {
126
+ obj := &models.Object{
127
+ Class: className,
128
+ ID: strfmt.UUID(o.ID),
129
+ Properties: map[string]interface{}{
130
+ "name": o.Name,
131
+ },
132
+ Vectors: models.Vectors{
133
+ byoc: o.Vector,
134
+ normalVector2dName: o.Vector[0],
135
+ multiVector1dName: multiVector1dFromMultiVector2d(o.Vector),
136
+ multiVector2dName: o.Vector,
137
+ multiVector3dName: multiVector3dFromMultiVector2d(o.Vector),
138
+ },
139
+ }
140
+ objs = append(objs, obj)
141
+ }
142
+
143
+ resp, err := client.Batch().ObjectsBatcher().
144
+ WithObjects(objs...).
145
+ Do(ctx)
146
+ require.NoError(t, err)
147
+ require.NotNil(t, resp)
148
+ for _, r := range resp {
149
+ require.Equal(t, "SUCCESS", *r.Result.Status)
150
+ }
151
+ })
152
+
153
+ t.Run("checks objects indexed", func(t *testing.T) {
154
+ testAllObjectsIndexed(t, client, className)
155
+ })
156
+
157
+ t.Run("vector search after insert", func(t *testing.T) {
158
+ performNearVector(t, nil, client, className)
159
+ performNearObject(t, nil, client, className)
160
+ })
161
+
162
+ t.Run("check existence", func(t *testing.T) {
163
+ for _, obj := range objects {
164
+ exists, err := client.Data().Checker().
165
+ WithID(obj.ID).
166
+ WithClassName(className).
167
+ Do(ctx)
168
+ require.NoError(t, err)
169
+ require.True(t, exists)
170
+ }
171
+ })
172
+
173
+ t.Run("get objects with vector", func(t *testing.T) {
174
+ for _, o := range objects {
175
+ objs, err := client.Data().ObjectsGetter().WithID(o.ID).WithClassName(className).WithVector().Do(ctx)
176
+ require.NoError(t, err)
177
+ require.Len(t, objs, 1)
178
+ require.Len(t, objs[0].Vectors, 5)
179
+ assert.IsType(t, [][]float32{}, objs[0].Vectors[byoc])
180
+ assert.Equal(t, o.Vector, objs[0].Vectors[byoc])
181
+ }
182
+ })
183
+
184
+ t.Run("GraphQL get object with vector", func(t *testing.T) {
185
+ for _, o := range objects {
186
+ resp, err := client.GraphQL().Get().
187
+ WithClassName(className).
188
+ WithWhere(filters.Where().WithPath([]string{"id"}).WithOperator(filters.Equal).WithValueText(o.ID)).
189
+ WithFields(_additional_byoc).
190
+ Do(ctx)
191
+ require.NoError(t, err)
192
+ vectors := acceptance_with_go_client.GetVectors(t, resp, className, false, byoc)
193
+ require.Len(t, vectors, 1)
194
+ require.IsType(t, [][]float32{}, vectors[byoc])
195
+ assert.Equal(t, o.Vector, vectors[byoc])
196
+ }
197
+ })
198
+
199
+ t.Run("update vector", func(t *testing.T) {
200
+ tests := []struct {
201
+ name string
202
+ obj struct {
203
+ ID string
204
+ Name string
205
+ Vector [][]float32
206
+ }
207
+ withMerge bool
208
+ vector [][]float32
209
+ }{
210
+ {
211
+ name: "update",
212
+ obj: objects[0],
213
+ vector: [][]float32{{-0.11111111, -0.12222222}, {-0.13, -0.14}, {-0.15, -0.16}},
214
+ },
215
+ {
216
+ name: "merge",
217
+ obj: objects[1],
218
+ withMerge: true,
219
+ vector: [][]float32{{-0.000001, -0.000001}, {-0.000001, -0.000001}, {-0.000001, -0.000001}},
220
+ },
221
+ }
222
+ for _, tt := range tests {
223
+ t.Run(tt.name, func(t *testing.T) {
224
+ firstObj := tt.obj
225
+ updateVectors := models.Vectors{
226
+ byoc: tt.vector,
227
+ normalVector2dName: tt.vector[0],
228
+ multiVector1dName: multiVector1dFromMultiVector2d(tt.vector),
229
+ multiVector2dName: tt.vector,
230
+ multiVector3dName: multiVector3dFromMultiVector2d(tt.vector),
231
+ }
232
+ objs, err := client.Data().ObjectsGetter().
233
+ WithClassName(className).WithID(firstObj.ID).WithVector().Do(ctx)
234
+ require.NoError(t, err)
235
+ require.NotEmpty(t, objs)
236
+ require.Len(t, objs[0].Vectors, 5)
237
+ assert.Equal(t, firstObj.Vector, objs[0].Vectors[byoc])
238
+ updater := client.Data().Updater().
239
+ WithClassName(className).WithID(firstObj.ID).WithVectors(updateVectors)
240
+ if tt.withMerge {
241
+ err = updater.WithMerge().Do(ctx)
242
+ } else {
243
+ err = updater.Do(ctx)
244
+ }
245
+ require.NoError(t, err)
246
+ objs, err = client.Data().ObjectsGetter().
247
+ WithClassName(className).WithID(firstObj.ID).WithVector().Do(ctx)
248
+ require.NoError(t, err)
249
+ require.NotEmpty(t, objs)
250
+ require.Len(t, objs[0].Vectors, 5)
251
+ assert.Equal(t, updateVectors[byoc], objs[0].Vectors[byoc])
252
+ resp, err := client.GraphQL().Get().
253
+ WithClassName(className).
254
+ WithWhere(filters.Where().WithPath([]string{"id"}).WithOperator(filters.Equal).WithValueText(firstObj.ID)).
255
+ WithFields(_additional_byoc).
256
+ Do(ctx)
257
+ require.NoError(t, err)
258
+ vectors := acceptance_with_go_client.GetVectors(t, resp, className, false, byoc)
259
+ require.Len(t, vectors, 1)
260
+ require.IsType(t, [][]float32{}, vectors[byoc])
261
+ assert.Equal(t, updateVectors[byoc], vectors[byoc])
262
+ })
263
+ }
264
+ })
265
+
266
+ t.Run("checks objects indexed", func(t *testing.T) {
267
+ testAllObjectsIndexed(t, client, className)
268
+ })
269
+
270
+ t.Run("vector search after partial update", func(t *testing.T) {
271
+ performNearVector(t, nil, client, className)
272
+ performNearObject(t, nil, client, className)
273
+ })
274
+
275
+ t.Run("update all objects", func(t *testing.T) {
276
+ for _, obj := range objects {
277
+ err = client.Data().Updater().
278
+ WithClassName(className).WithID(obj.ID).WithVectors(models.Vectors{
279
+ byoc: obj.Vector,
280
+ normalVector2dName: obj.Vector[0],
281
+ multiVector1dName: multiVector1dFromMultiVector2d(obj.Vector),
282
+ multiVector2dName: obj.Vector,
283
+ multiVector3dName: multiVector3dFromMultiVector2d(obj.Vector),
284
+ }).Do(ctx)
285
+ require.NoError(t, err)
286
+ }
287
+ })
288
+
289
+ t.Run("checks objects indexed", func(t *testing.T) {
290
+ testAllObjectsIndexed(t, client, className)
291
+ })
292
+
293
+ t.Run("vector search after update of all objects", func(t *testing.T) {
294
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
295
+ performNearVector(t, ct, client, className)
296
+ performNearObject(t, ct, client, className)
297
+ }, 5*time.Second, 1*time.Second)
298
+ })
299
+
300
+ t.Run("WithVector[s]PerTarget searches", func(t *testing.T) {
301
+ withVectorPerTargetTests := []struct {
302
+ name string
303
+ nearVector *graphql.NearVectorArgumentBuilder
304
+ }{
305
+ {
306
+ name: "NormalVector_dim2",
307
+ nearVector: client.GraphQL().NearVectorArgBuilder().
308
+ WithVectorPerTarget(map[string]models.Vector{
309
+ normalVector2dName: []float32{0.1, 0.1},
310
+ }).
311
+ WithTargetVectors(normalVector2dName),
312
+ },
313
+ {
314
+ name: "NormalVectors_dim3x2",
315
+ nearVector: client.GraphQL().NearVectorArgBuilder().
316
+ WithVectorsPerTarget(map[string][]models.Vector{
317
+ normalVector2dName: {[]float32{0.1, 0.1}, []float32{0.1, 0.1}, []float32{0.1, 0.1}},
318
+ }).
319
+ WithTargetVectors(normalVector2dName),
320
+ },
321
+ {
322
+ name: "MultiVector_dim3x2",
323
+ nearVector: client.GraphQL().NearVectorArgBuilder().
324
+ WithVectorPerTarget(map[string]models.Vector{
325
+ multiVector2dName: [][]float32{{0.1, 0.1}, {0.1, 0.1}, {0.1, 0.1}},
326
+ }).
327
+ WithTargetVectors(multiVector2dName),
328
+ },
329
+ {
330
+ name: "MultiVectors_dim1x3x2",
331
+ nearVector: client.GraphQL().NearVectorArgBuilder().
332
+ WithVectorsPerTarget(map[string][]models.Vector{
333
+ multiVector2dName: {
334
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}, {0.1, 0.1}},
335
+ },
336
+ }).
337
+ WithTargetVectors(multiVector2dName),
338
+ },
339
+ {
340
+ name: "MultiVectors_dim2x3x2",
341
+ nearVector: client.GraphQL().NearVectorArgBuilder().
342
+ WithVectorsPerTarget(map[string][]models.Vector{
343
+ multiVector2dName: {
344
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}, {0.1, 0.1}},
345
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}, {0.1, 0.1}},
346
+ },
347
+ }).
348
+ WithTargetVectors(multiVector2dName),
349
+ },
350
+ {
351
+ name: "MultiVector_1d2d3d",
352
+ nearVector: client.GraphQL().NearVectorArgBuilder().
353
+ WithVectorPerTarget(map[string]models.Vector{
354
+ multiVector1dName: [][]float32{{0.1}, {0.1}},
355
+ multiVector2dName: [][]float32{{0.1, 0.1}, {0.1, 0.1}},
356
+ multiVector3dName: [][]float32{{0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}},
357
+ }).
358
+ WithTargetVectors(multiVector2dName),
359
+ },
360
+ {
361
+ name: "MultiVectors_1d2d3d",
362
+ nearVector: client.GraphQL().NearVectorArgBuilder().
363
+ WithVectorsPerTarget(map[string][]models.Vector{
364
+ multiVector1dName: {
365
+ [][]float32{{0.1}, {0.1}},
366
+ [][]float32{{0.1}, {0.1}},
367
+ [][]float32{{0.1}, {0.1}},
368
+ },
369
+ multiVector2dName: {
370
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}},
371
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}},
372
+ },
373
+ multiVector3dName: {
374
+ [][]float32{{0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}},
375
+ },
376
+ }).
377
+ WithTargetVectors(multiVector2dName),
378
+ },
379
+ {
380
+ name: "MultiVector_all",
381
+ nearVector: client.GraphQL().NearVectorArgBuilder().
382
+ WithVectorPerTarget(map[string]models.Vector{
383
+ normalVector2dName: []float32{0.1, 0.1},
384
+ multiVector1dName: [][]float32{{0.1}, {0.1}},
385
+ multiVector2dName: [][]float32{{0.1, 0.1}, {0.1, 0.1}},
386
+ multiVector3dName: [][]float32{{0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}},
387
+ }).
388
+ WithTargetVectors(multiVector2dName),
389
+ },
390
+ {
391
+ name: "MultiVectors_all",
392
+ nearVector: client.GraphQL().NearVectorArgBuilder().
393
+ WithVectorsPerTarget(map[string][]models.Vector{
394
+ normalVector2dName: {
395
+ []float32{0.1, 0.1},
396
+ []float32{0.1, 0.1},
397
+ },
398
+ multiVector1dName: {
399
+ [][]float32{{0.1}, {0.1}},
400
+ [][]float32{{0.1}, {0.1}},
401
+ },
402
+ multiVector2dName: {
403
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}},
404
+ [][]float32{{0.1, 0.1}, {0.1, 0.1}},
405
+ },
406
+ multiVector3dName: {
407
+ [][]float32{{0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}},
408
+ [][]float32{{0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}},
409
+ },
410
+ }).
411
+ WithTargetVectors(multiVector2dName),
412
+ },
413
+ }
414
+ for _, tt := range withVectorPerTargetTests {
415
+ t.Run(tt.name, func(t *testing.T) {
416
+ resp, err := client.GraphQL().Get().
417
+ WithClassName(className).
418
+ WithNearVector(tt.nearVector).
419
+ WithFields(_additional_byoc).
420
+ Do(ctx)
421
+ require.NoError(t, err)
422
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
423
+ require.NotEmpty(t, ids)
424
+ assert.Len(t, ids, len(objects))
425
+ })
426
+ }
427
+ })
428
+ })
429
+
430
+ t.Run("multi vector validation", func(t *testing.T) {
431
+ t.Run("multi vector vectorizer", func(t *testing.T) {
432
+ cleanup()
433
+ class := &models.Class{
434
+ Class: "MultiVectorLegacyVectorizer",
435
+ Properties: []*models.Property{
436
+ {
437
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
438
+ },
439
+ },
440
+ VectorIndexType: "hnsw",
441
+ Vectorizer: "text2multivec-jinaai",
442
+ }
443
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
444
+ require.Error(t, err)
445
+ assert.ErrorContains(t, err, `multi vector vectorizer: \"text2multivec-jinaai\" is only allowed to be defined using named vector configuration`)
446
+ })
447
+ t.Run("multi vector vectorizer with module config", func(t *testing.T) {
448
+ cleanup()
449
+ class := &models.Class{
450
+ Class: "MultiVectorLegacyVectorizerWithModuleConfig",
451
+ Properties: []*models.Property{
452
+ {
453
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
454
+ },
455
+ },
456
+ ModuleConfig: map[string]interface{}{
457
+ "text2multivec-jinaai": map[string]interface{}{
458
+ "skip": true,
459
+ },
460
+ },
461
+ VectorIndexType: "hnsw",
462
+ Vectorizer: "text2multivec-jinaai",
463
+ }
464
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
465
+ require.Error(t, err)
466
+ assert.ErrorContains(t, err, `multi vector vectorizer: \"text2multivec-jinaai\" is only allowed to be defined using named vector configuration`)
467
+ })
468
+ t.Run("colbert vectorizer with multi vector index", func(t *testing.T) {
469
+ cleanup()
470
+ class := &models.Class{
471
+ Class: "LegacyColbertVectorizerWithMultiVectorIndex",
472
+ Properties: []*models.Property{
473
+ {
474
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
475
+ },
476
+ },
477
+ VectorIndexType: "hnsw",
478
+ VectorIndexConfig: map[string]interface{}{
479
+ "multivector": map[string]interface{}{
480
+ "enabled": true,
481
+ },
482
+ },
483
+ Vectorizer: "text2multivec-jinaai",
484
+ }
485
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
486
+ require.Error(t, err)
487
+ assert.ErrorContains(t, err, `class.VectorIndexConfig multi vector type index type is only configurable using named vectors`)
488
+ })
489
+ t.Run("regular vectorizer with multi vector index", func(t *testing.T) {
490
+ cleanup()
491
+ class := &models.Class{
492
+ Class: "LegacyOpenAIVectorizerWithMultiVectorIndex",
493
+ Properties: []*models.Property{
494
+ {
495
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
496
+ },
497
+ },
498
+ VectorIndexType: "hnsw",
499
+ VectorIndexConfig: map[string]interface{}{
500
+ "multivector": map[string]interface{}{
501
+ "enabled": true,
502
+ },
503
+ },
504
+ Vectorizer: "text2vec-openai",
505
+ }
506
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
507
+ require.Error(t, err)
508
+ assert.ErrorContains(t, err, `class.VectorIndexConfig multi vector type index type is only configurable using named vectors`)
509
+ })
510
+ t.Run("legacy none vectorizer with multi vector index", func(t *testing.T) {
511
+ cleanup()
512
+ class := &models.Class{
513
+ Class: "LegacyNoneVectorizerWithMultiVectorIndex",
514
+ Properties: []*models.Property{
515
+ {
516
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
517
+ },
518
+ },
519
+ VectorIndexType: "hnsw",
520
+ VectorIndexConfig: map[string]interface{}{
521
+ "multivector": map[string]interface{}{
522
+ "enabled": true,
523
+ },
524
+ },
525
+ Vectorizer: "none",
526
+ }
527
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
528
+ require.Error(t, err)
529
+ assert.ErrorContains(t, err, `class.VectorIndexConfig multi vector type index type is only configurable using named vectors`)
530
+ })
531
+ t.Run("named vector regular vectorizer with multi vector index", func(t *testing.T) {
532
+ cleanup()
533
+ class := &models.Class{
534
+ Class: "NamedVectorVectorizerWithMultiVectorIndex",
535
+ Properties: []*models.Property{
536
+ {
537
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
538
+ },
539
+ },
540
+ VectorConfig: map[string]models.VectorConfig{
541
+ m2vec: {
542
+ Vectorizer: map[string]interface{}{
543
+ text2vecModel2Vec: map[string]interface{}{
544
+ "vectorizeClassName": false,
545
+ },
546
+ },
547
+ VectorIndexConfig: map[string]interface{}{
548
+ "multivector": map[string]interface{}{
549
+ "enabled": true,
550
+ },
551
+ },
552
+ VectorIndexType: "hnsw",
553
+ },
554
+ },
555
+ }
556
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
557
+ require.Error(t, err)
558
+ assert.ErrorContains(t, err, `parse vector config for m2vec: multi vector index configured but vectorizer: \"text2vec-model2vec\" doesn't support multi vectors`)
559
+ })
560
+ t.Run("named vector is colbert vectorizer with regular vector index", func(t *testing.T) {
561
+ cleanup()
562
+ class := &models.Class{
563
+ Class: "NamedVectorVectorizerWithMultiVectorIndex",
564
+ Properties: []*models.Property{
565
+ {
566
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
567
+ },
568
+ },
569
+ VectorConfig: map[string]models.VectorConfig{
570
+ "colbert": {
571
+ Vectorizer: map[string]interface{}{
572
+ "text2multivec-jinaai": map[string]interface{}{
573
+ "vectorizeClassName": false,
574
+ },
575
+ },
576
+ VectorIndexConfig: map[string]interface{}{
577
+ "multivector": map[string]interface{}{
578
+ "enabled": false,
579
+ },
580
+ },
581
+ VectorIndexType: "hnsw",
582
+ },
583
+ },
584
+ }
585
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
586
+ // Weaviate overrides the multivector setting if it finds that someone has enabled
587
+ // multi vector vectorizer
588
+ require.NoError(t, err)
589
+ })
590
+ t.Run("named vector is colbert vectorizer with empty vector index", func(t *testing.T) {
591
+ cleanup()
592
+ class := &models.Class{
593
+ Class: "NamedVectorVectorizerWithMultiVectorIndex",
594
+ Properties: []*models.Property{
595
+ {
596
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
597
+ },
598
+ },
599
+ VectorConfig: map[string]models.VectorConfig{
600
+ "colbert": {
601
+ Vectorizer: map[string]interface{}{
602
+ "text2multivec-jinaai": map[string]interface{}{
603
+ "vectorizeClassName": false,
604
+ },
605
+ },
606
+ VectorIndexType: "hnsw",
607
+ },
608
+ },
609
+ }
610
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
611
+ // Weaviate overrides the multivector setting if it finds that someone has enabled
612
+ // multi vector vectorizer
613
+ require.NoError(t, err)
614
+ cls, err := client.Schema().ClassGetter().WithClassName(class.Class).Do(ctx)
615
+ require.NoError(t, err)
616
+ require.NotNil(t, cls.VectorConfig["colbert"])
617
+ vc := cls.VectorConfig["colbert"].VectorIndexConfig
618
+ require.NotNil(t, vc)
619
+ vsAsMap, ok := vc.(map[string]interface{})
620
+ require.True(t, ok)
621
+ mv, ok := vsAsMap["multivector"].(map[string]interface{})
622
+ require.True(t, ok)
623
+ assert.True(t, mv["enabled"].(bool))
624
+ })
625
+ t.Run("multi vector index with flat vector index type", func(t *testing.T) {
626
+ cleanup()
627
+ class := &models.Class{
628
+ Class: "NamedVectorVectorizerWithMultiVectorIndex",
629
+ Properties: []*models.Property{
630
+ {
631
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
632
+ },
633
+ },
634
+ VectorConfig: map[string]models.VectorConfig{
635
+ "colbert": {
636
+ Vectorizer: map[string]interface{}{
637
+ "text2multivec-jinaai": map[string]interface{}{
638
+ "vectorizeClassName": false,
639
+ },
640
+ },
641
+ VectorIndexType: "flat",
642
+ },
643
+ },
644
+ }
645
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
646
+ // Weaviate overrides the multivector setting if it finds that someone has enabled
647
+ // multi vector vectorizer
648
+ require.Error(t, err)
649
+ assert.ErrorContains(t, err, `parse vector index config: multi vector index is not supported for vector index type: \"flat\", only supported type is hnsw`)
650
+ })
651
+ t.Run("multi vector index with dynamic vector index type", func(t *testing.T) {
652
+ cleanup()
653
+ class := &models.Class{
654
+ Class: "NamedVectorVectorizerWithMultiVectorIndex",
655
+ Properties: []*models.Property{
656
+ {
657
+ Name: "name", DataType: []string{schema.DataTypeText.String()},
658
+ },
659
+ },
660
+ VectorConfig: map[string]models.VectorConfig{
661
+ "colbert": {
662
+ Vectorizer: map[string]interface{}{
663
+ "text2multivec-jinaai": map[string]interface{}{
664
+ "vectorizeClassName": false,
665
+ },
666
+ },
667
+ VectorIndexType: "dynamic",
668
+ },
669
+ },
670
+ }
671
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
672
+ // Weaviate overrides the multivector setting if it finds that someone has enabled
673
+ // multi vector vectorizer
674
+ require.Error(t, err)
675
+
676
+ if asyncIndexingEnabled {
677
+ assert.ErrorContains(t, err, `parse vector index config: multi vector index is not supported for vector index type: \"dynamic\", only supported type is hnsw`)
678
+ } else {
679
+ assert.ErrorContains(t, err, `the dynamic index can only be created under async indexing environment`)
680
+ }
681
+ })
682
+ })
683
+
684
+ t.Run("validate multi vector dimensions", func(t *testing.T) {
685
+ className := fixtures.BringYourOwnColBERTClassName
686
+ objects := fixtures.BringYourOwnColBERTObjects
687
+ byoc := fixtures.BringYourOwnColBERTNamedVectorName
688
+
689
+ t.Run("batch create", func(t *testing.T) {
690
+ cleanup()
691
+
692
+ t.Run("create schema", func(t *testing.T) {
693
+ class := fixtures.BringYourOwnColBERTClass(className)
694
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
695
+ require.NoError(t, err)
696
+ })
697
+
698
+ t.Run("batch create objects", func(t *testing.T) {
699
+ obj1 := &models.Object{
700
+ Class: className,
701
+ ID: strfmt.UUID(objects[0].ID),
702
+ Properties: map[string]interface{}{
703
+ "name": objects[0].Name,
704
+ },
705
+ Vectors: models.Vectors{
706
+ byoc: objects[0].Vector,
707
+ },
708
+ }
709
+ objWrongDimensions := &models.Object{
710
+ Class: className,
711
+ ID: strfmt.UUID(objects[1].ID),
712
+ Properties: map[string]interface{}{
713
+ "name": objects[1].Name,
714
+ },
715
+ Vectors: models.Vectors{
716
+ byoc: [][]float32{{0.12, 0.12}, {0.11}},
717
+ },
718
+ }
719
+ resp, err := client.Batch().ObjectsBatcher().
720
+ WithObjects(obj1, objWrongDimensions).
721
+ Do(ctx)
722
+ require.NoError(t, err)
723
+ require.NotNil(t, resp)
724
+ success, failed := false, false
725
+ for i := range resp {
726
+ if *resp[i].Result.Status == "SUCCESS" {
727
+ success = true
728
+ }
729
+ if *resp[i].Result.Status == "FAILED" {
730
+ failed = true
731
+ }
732
+ }
733
+ assert.True(t, success)
734
+ assert.True(t, failed)
735
+ })
736
+ })
737
+
738
+ t.Run("insert", func(t *testing.T) {
739
+ cleanup()
740
+
741
+ t.Run("create schema", func(t *testing.T) {
742
+ class := fixtures.BringYourOwnColBERTClass(className)
743
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
744
+ require.NoError(t, err)
745
+ })
746
+
747
+ t.Run("batch create objects", func(t *testing.T) {
748
+ obj1 := &models.Object{
749
+ Class: className,
750
+ ID: strfmt.UUID(objects[0].ID),
751
+ Properties: map[string]interface{}{
752
+ "name": objects[0].Name,
753
+ },
754
+ Vectors: models.Vectors{
755
+ byoc: objects[0].Vector,
756
+ },
757
+ }
758
+ resp, err := client.Batch().ObjectsBatcher().
759
+ WithObjects(obj1).
760
+ Do(ctx)
761
+ require.NoError(t, err)
762
+ require.NotNil(t, resp)
763
+ require.Equal(t, "SUCCESS", *resp[0].Result.Status)
764
+ })
765
+
766
+ t.Run("insert additional object", func(t *testing.T) {
767
+ objWrongDimensions := &models.Object{
768
+ Class: className,
769
+ ID: strfmt.UUID(objects[1].ID),
770
+ Properties: map[string]interface{}{
771
+ "name": objects[1].Name,
772
+ },
773
+ Vectors: models.Vectors{
774
+ byoc: [][]float32{{0.12, 0.12}, {0.11}},
775
+ },
776
+ }
777
+ _, err := client.Data().Creator().
778
+ WithClassName(objWrongDimensions.Class).
779
+ WithID(objWrongDimensions.ID.String()).
780
+ WithProperties(objWrongDimensions.Properties).
781
+ WithVectors(objWrongDimensions.Vectors).
782
+ Do(ctx)
783
+ require.Error(t, err)
784
+ })
785
+ })
786
+ })
787
+ }
788
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_generative.go ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/schema"
26
+ )
27
+
28
+ func testNamedVectorsWithGenerativeModules(host string) func(t *testing.T) {
29
+ return func(t *testing.T) {
30
+ ctx := context.Background()
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ t.Run("named vectors with generative module", func(t *testing.T) {
40
+ cleanup()
41
+ // Define class
42
+ className := "BooksGenerativeTest"
43
+ class := &models.Class{
44
+ Class: className,
45
+ Properties: []*models.Property{
46
+ {
47
+ Name: "title", DataType: []string{schema.DataTypeText.String()},
48
+ },
49
+ {
50
+ Name: "description", DataType: []string{schema.DataTypeText.String()},
51
+ },
52
+ },
53
+ VectorConfig: map[string]models.VectorConfig{
54
+ "title": {
55
+ Vectorizer: map[string]interface{}{
56
+ "text2vec-model2vec": map[string]interface{}{
57
+ "properties": []interface{}{"title"},
58
+ "vectorizeClassName": false,
59
+ },
60
+ },
61
+ VectorIndexType: "flat",
62
+ },
63
+ "description": {
64
+ Vectorizer: map[string]interface{}{
65
+ "text2vec-transformers": map[string]interface{}{
66
+ "properties": []interface{}{"description"},
67
+ "vectorizeClassName": false,
68
+ },
69
+ },
70
+ VectorIndexType: "flat",
71
+ },
72
+ },
73
+ ModuleConfig: map[string]interface{}{
74
+ "generative-openai": map[string]interface{}{
75
+ "model": "gpt-4",
76
+ },
77
+ },
78
+ }
79
+
80
+ t.Run("create schema", func(t *testing.T) {
81
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
82
+ require.NoError(t, err)
83
+ })
84
+
85
+ t.Run("batch create objects", func(t *testing.T) {
86
+ objs := []*models.Object{}
87
+ for id, book := range fixtures.Books() {
88
+ obj := &models.Object{
89
+ Class: className,
90
+ ID: strfmt.UUID(id),
91
+ Properties: map[string]interface{}{
92
+ "title": book.Title,
93
+ "description": book.Description,
94
+ },
95
+ }
96
+ objs = append(objs, obj)
97
+ }
98
+
99
+ resp, err := client.Batch().ObjectsBatcher().
100
+ WithObjects(objs...).
101
+ Do(ctx)
102
+ require.NoError(t, err)
103
+ require.NotNil(t, resp)
104
+ })
105
+
106
+ t.Run("check existence", func(t *testing.T) {
107
+ for id := range fixtures.Books() {
108
+ objs, err := client.Data().ObjectsGetter().
109
+ WithID(id).
110
+ WithClassName(className).
111
+ WithVector().
112
+ Do(ctx)
113
+ require.NoError(t, err)
114
+ require.Len(t, objs, 1)
115
+ require.NotNil(t, objs[0])
116
+ require.Len(t, objs[0].Vectors, 2)
117
+ assert.NotEmpty(t, objs[0].Vectors["title"])
118
+ assert.NotEmpty(t, objs[0].Vectors["description"])
119
+ }
120
+ })
121
+ })
122
+ }
123
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_hybrid.go ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+ "time"
18
+
19
+ acceptance_with_go_client "acceptance_tests_with_client"
20
+
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
24
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/entities/schema"
27
+ )
28
+
29
+ func testHybrid(host string) func(t *testing.T) {
30
+ return func(t *testing.T) {
31
+ ctx := context.Background()
32
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
33
+ require.Nil(t, err)
34
+
35
+ class := &models.Class{
36
+ Class: "TestClass",
37
+ Properties: []*models.Property{
38
+ {
39
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
40
+ },
41
+ {
42
+ Name: "text2", DataType: []string{schema.DataTypeText.String()},
43
+ },
44
+ },
45
+ VectorConfig: map[string]models.VectorConfig{
46
+ transformers: {
47
+ Vectorizer: map[string]interface{}{
48
+ text2vecTransformers: map[string]interface{}{
49
+ "vectorizeClassName": false,
50
+ "sourceProperties": []string{"text"},
51
+ },
52
+ },
53
+ VectorIndexType: "flat",
54
+ },
55
+ model2vec: {
56
+ Vectorizer: map[string]interface{}{
57
+ text2vecModel2Vec: map[string]interface{}{
58
+ "vectorizeClassName": false,
59
+ "sourceProperties": []string{"text2"},
60
+ },
61
+ },
62
+ VectorIndexType: "flat",
63
+ },
64
+ },
65
+ }
66
+
67
+ cleanup := func() {
68
+ err := client.Schema().ClassDeleter().WithClassName(class.Class).Do(context.Background())
69
+ require.Nil(t, err)
70
+ }
71
+
72
+ field := graphql.Field{
73
+ Name: "_additional",
74
+ Fields: []graphql.Field{
75
+ {Name: "id"},
76
+ },
77
+ }
78
+ id := "1aa6fbff-461b-4ca5-9ff7-47ccd6d07519"
79
+ id2 := "1aa6fbff-463b-4ca5-9ff7-47ccd6d07519"
80
+
81
+ t.Run("hybrid with 1 vectorizer", func(t *testing.T) {
82
+ // create class
83
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
84
+ defer cleanup()
85
+ require.NoError(t, err)
86
+ // insert object
87
+ objWrapper, err := client.Data().Creator().
88
+ WithClassName(class.Class).
89
+ WithID(id).
90
+ WithProperties(map[string]interface{}{
91
+ "text": "Some text goes here",
92
+ }).
93
+ Do(ctx)
94
+ require.NoError(t, err)
95
+ require.NotNil(t, objWrapper)
96
+ assert.Len(t, objWrapper.Object.Vectors, 2)
97
+
98
+ resp, err := client.GraphQL().Get().
99
+ WithClassName(class.Class).
100
+ WithHybrid(client.GraphQL().
101
+ HybridArgumentBuilder().
102
+ WithQuery("Some text goes here").
103
+ WithAlpha(0.5).WithTargetVectors(transformers)).
104
+ WithFields(field).
105
+ Do(ctx)
106
+ require.NoError(t, err)
107
+ ids := acceptance_with_go_client.GetIds(t, resp, class.Class)
108
+ require.ElementsMatch(t, ids, []string{id})
109
+ })
110
+
111
+ t.Run("hybrid with 2 vectorizers", func(t *testing.T) {
112
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
113
+ defer cleanup()
114
+ require.NoError(t, err)
115
+ // insert object
116
+ objWrapper, err := client.Data().Creator().
117
+ WithClassName(class.Class).
118
+ WithID(id).
119
+ WithProperties(map[string]interface{}{
120
+ "text": "apple",
121
+ "text2": "mountain",
122
+ }).
123
+ Do(ctx)
124
+ require.NoError(t, err)
125
+ require.NotNil(t, objWrapper)
126
+ assert.Len(t, objWrapper.Object.Vectors, 2)
127
+
128
+ _, err = client.Data().Creator().
129
+ WithClassName(class.Class).
130
+ WithID(id2).
131
+ WithProperties(map[string]interface{}{
132
+ "text": "mountain",
133
+ "text2": "apple",
134
+ }).
135
+ Do(ctx)
136
+ require.NoError(t, err)
137
+
138
+ var ids []string
139
+ require.Eventually(t, func() bool {
140
+ resp, err := client.GraphQL().Get().
141
+ WithClassName(class.Class).
142
+ WithHybrid(client.GraphQL().
143
+ HybridArgumentBuilder().
144
+ WithQuery("apple").
145
+ WithAlpha(1).WithTargetVectors(transformers, model2vec)).
146
+ WithFields(field).
147
+ Do(ctx)
148
+ require.NoError(t, err)
149
+ ids = acceptance_with_go_client.GetIds(t, resp, class.Class)
150
+ return len(ids) == 2
151
+ }, 5*time.Second, 1*time.Second)
152
+
153
+ require.ElementsMatch(t, ids, []string{id, id2})
154
+ })
155
+
156
+ t.Run("default vector chosen", func(t *testing.T) {
157
+ singleVecClass := &models.Class{
158
+ Class: "TestClass",
159
+ Properties: []*models.Property{
160
+ {
161
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
162
+ },
163
+ },
164
+ VectorConfig: map[string]models.VectorConfig{
165
+ model2vec: {
166
+ Vectorizer: map[string]interface{}{
167
+ text2vecModel2Vec: map[string]interface{}{},
168
+ },
169
+ VectorIndexType: "flat",
170
+ },
171
+ },
172
+ }
173
+
174
+ require.NoError(t, client.Schema().ClassCreator().WithClass(singleVecClass).Do(ctx))
175
+ defer cleanup()
176
+
177
+ _, err = client.Data().Creator().
178
+ WithClassName(class.Class).
179
+ WithID(id).
180
+ WithProperties(map[string]interface{}{
181
+ "text": "Some text goes here",
182
+ }).
183
+ Do(ctx)
184
+ require.NoError(t, err)
185
+
186
+ // query without providing target vector
187
+ resp, err := client.GraphQL().Get().
188
+ WithClassName(class.Class).
189
+ WithHybrid(client.GraphQL().
190
+ HybridArgumentBuilder().
191
+ WithQuery("Some text goes here").
192
+ WithAlpha(0.5)).
193
+ WithFields(field).
194
+ Do(ctx)
195
+ require.NoError(t, err)
196
+
197
+ ids := acceptance_with_go_client.GetIds(t, resp, class.Class)
198
+ require.ElementsMatch(t, ids, []string{id})
199
+ })
200
+ }
201
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects.go ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ acceptance_with_go_client "acceptance_tests_with_client"
19
+
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/schema"
26
+ )
27
+
28
+ func testCreateObject(host string) func(t *testing.T) {
29
+ return func(t *testing.T) {
30
+ ctx := context.Background()
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ t.Run("multiple named vectors", func(t *testing.T) {
40
+ cleanup()
41
+
42
+ t.Run("create schema", func(t *testing.T) {
43
+ createNamedVectorsClass(t, client)
44
+ })
45
+
46
+ t.Run("create objects", func(t *testing.T) {
47
+ objects := []struct {
48
+ id string
49
+ text string
50
+ }{
51
+ {id: id1, text: "I like reading books"},
52
+ {id: id2, text: "I like programming"},
53
+ }
54
+ for _, object := range objects {
55
+ objWrapper, err := client.Data().Creator().
56
+ WithClassName(className).
57
+ WithID(object.id).
58
+ WithProperties(map[string]interface{}{
59
+ "text": object.text,
60
+ }).
61
+ Do(ctx)
62
+ require.NoError(t, err)
63
+ require.NotNil(t, objWrapper)
64
+ assert.Len(t, objWrapper.Object.Vectors, len(targetVectors))
65
+
66
+ objs, err := client.Data().ObjectsGetter().
67
+ WithClassName(className).
68
+ WithID(object.id).
69
+ WithVector().
70
+ Do(ctx)
71
+ require.NoError(t, err)
72
+ require.Len(t, objs, 1)
73
+ require.NotNil(t, objs[0])
74
+ assert.Len(t, objs[0].Vectors, len(targetVectors))
75
+ properties, ok := objs[0].Properties.(map[string]interface{})
76
+ require.True(t, ok)
77
+ assert.Equal(t, object.text, properties["text"])
78
+ }
79
+ })
80
+
81
+ t.Run("check existence", func(t *testing.T) {
82
+ for _, id := range []string{id1, id2} {
83
+ exists, err := client.Data().Checker().
84
+ WithID(id).
85
+ WithClassName(className).
86
+ Do(ctx)
87
+ require.NoError(t, err)
88
+ require.True(t, exists)
89
+ }
90
+ })
91
+
92
+ t.Run("GraphQL get vectors", func(t *testing.T) {
93
+ resultVectors := getVectors(t, client, className, id1, targetVectors...)
94
+ checkTargetVectors(t, resultVectors)
95
+ })
96
+
97
+ t.Run("GraphQL near<Media> check", func(t *testing.T) {
98
+ for _, targetVector := range targetVectors {
99
+ nearText := client.GraphQL().NearTextArgBuilder().
100
+ WithConcepts([]string{"book"}).
101
+ WithTargetVectors(targetVector)
102
+ resultVectors := getVectorsWithNearText(t, client, className, id1, nearText, targetVectors...)
103
+ checkTargetVectors(t, resultVectors)
104
+ }
105
+ })
106
+
107
+ t.Run("certainty checks", func(t *testing.T) {
108
+ var vectorM2Vec []float32
109
+ t.Run("nearText", func(t *testing.T) {
110
+ nearText := client.GraphQL().NearTextArgBuilder().
111
+ WithConcepts([]string{"book"}).
112
+ WithTargetVectors(m2vec)
113
+ resultVectors := getVectorsWithNearTextWithCertainty(t, client, className, id1, nearText, m2vec)
114
+ require.NotEmpty(t, resultVectors[m2vec])
115
+ require.IsType(t, []float32{}, resultVectors[m2vec])
116
+ vectorM2Vec = resultVectors[m2vec].([]float32)
117
+ })
118
+
119
+ t.Run("nearVector", func(t *testing.T) {
120
+ nearVector := client.GraphQL().NearVectorArgBuilder().
121
+ WithVector(vectorM2Vec).
122
+ WithTargetVectors(m2vec)
123
+ resultVectors := getVectorsWithNearVectorWithCertainty(t, client, className, id1, nearVector, m2vec)
124
+ require.NotEmpty(t, resultVectors[m2vec])
125
+ })
126
+
127
+ t.Run("nearObject", func(t *testing.T) {
128
+ nearObject := client.GraphQL().NearObjectArgBuilder().
129
+ WithID(id1).
130
+ WithTargetVectors(m2vec)
131
+ resultVectors := getVectorsWithNearObjectWithCertainty(t, client, className, id1, nearObject, m2vec)
132
+ require.NotEmpty(t, resultVectors[m2vec])
133
+ })
134
+ })
135
+
136
+ t.Run("nearText with certainty limit", func(t *testing.T) {
137
+ nearText := client.GraphQL().NearTextArgBuilder().
138
+ WithTargetVectors(m2vec).
139
+ WithConcepts([]string{"book"}).
140
+ WithCertainty(0.7)
141
+
142
+ res, err := client.GraphQL().Get().
143
+ WithClassName(className).
144
+ WithNearText(nearText).
145
+ WithFields(graphql.Field{
146
+ Name: "_additional",
147
+ Fields: []graphql.Field{{Name: "id"}},
148
+ }).
149
+ Do(ctx)
150
+ require.NoError(t, err)
151
+ require.Equal(t, []string{id1}, acceptance_with_go_client.GetIds(t, res, className))
152
+ })
153
+
154
+ t.Run("delete 1 object", func(t *testing.T) {
155
+ err := client.Data().Deleter().
156
+ WithClassName(className).
157
+ WithID(id2).
158
+ Do(ctx)
159
+ require.NoError(t, err)
160
+
161
+ exists, err := client.Data().Checker().
162
+ WithID(id2).
163
+ WithClassName(className).
164
+ Do(ctx)
165
+ require.NoError(t, err)
166
+ require.False(t, exists)
167
+
168
+ objs, err := client.Data().ObjectsGetter().
169
+ WithClassName(className).
170
+ WithID(id1).
171
+ WithVector().
172
+ Do(ctx)
173
+ require.NoError(t, err)
174
+ require.Len(t, objs, 1)
175
+ require.NotNil(t, objs[0])
176
+ assert.Len(t, objs[0].Vectors, len(targetVectors))
177
+ properties, ok := objs[0].Properties.(map[string]interface{})
178
+ require.True(t, ok)
179
+ assert.NotNil(t, properties["text"])
180
+ })
181
+
182
+ t.Run("update object and check if vectors changed", func(t *testing.T) {
183
+ beforeUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
184
+ checkTargetVectors(t, beforeUpdateVectors)
185
+
186
+ err := client.Data().Updater().
187
+ WithClassName(className).
188
+ WithID(id1).
189
+ WithProperties(map[string]interface{}{
190
+ "text": "I like reading science-fiction books",
191
+ }).
192
+ Do(ctx)
193
+ require.NoError(t, err)
194
+ afterUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
195
+ checkTargetVectors(t, afterUpdateVectors)
196
+ for _, targetVector := range targetVectors {
197
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
198
+ }
199
+ })
200
+
201
+ t.Run("merge object and check if vectors changed", func(t *testing.T) {
202
+ beforeUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
203
+ checkTargetVectors(t, beforeUpdateVectors)
204
+
205
+ err := client.Data().Updater().
206
+ WithMerge().
207
+ WithClassName(className).
208
+ WithID(id1).
209
+ WithProperties(map[string]interface{}{
210
+ "text": "This is a new property value that should be merged",
211
+ }).
212
+ Do(ctx)
213
+ require.NoError(t, err)
214
+ afterUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
215
+ checkTargetVectors(t, afterUpdateVectors)
216
+ for _, targetVector := range targetVectors {
217
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
218
+ }
219
+ })
220
+
221
+ t.Run("add new property", func(t *testing.T) {
222
+ property := &models.Property{
223
+ Name: "dont_vectorize_property",
224
+ DataType: []string{schema.DataTypeText.String()},
225
+ ModuleConfig: map[string]interface{}{
226
+ text2vecModel2Vec: map[string]interface{}{
227
+ "skip": true,
228
+ "vectorizePropertyName": "false",
229
+ },
230
+ text2vecTransformers: map[string]interface{}{
231
+ "skip": true,
232
+ "vectorizePropertyName": "false",
233
+ },
234
+ },
235
+ }
236
+
237
+ err = client.Schema().PropertyCreator().WithClassName(className).WithProperty(property).Do(ctx)
238
+ require.NoError(t, err)
239
+
240
+ class, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
241
+ require.NoError(t, err)
242
+ require.NotNil(t, class)
243
+ require.Len(t, class.Properties, 2)
244
+
245
+ beforeUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
246
+ checkTargetVectors(t, beforeUpdateVectors)
247
+
248
+ err = client.Data().Updater().
249
+ WithMerge().
250
+ WithClassName(className).
251
+ WithID(id1).
252
+ WithProperties(map[string]interface{}{
253
+ "dont_vectorize_property": "This change should not change vector",
254
+ }).
255
+ Do(ctx)
256
+ require.NoError(t, err)
257
+ afterUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
258
+ checkTargetVectors(t, afterUpdateVectors)
259
+ for _, targetVector := range targetVectors {
260
+ assert.Equal(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
261
+ }
262
+ })
263
+
264
+ // note that vectors are different afterwards and you cant use checkTargetVectors anymore
265
+ t.Run("Update with a vector - use the given vector and dont revectorize", func(t *testing.T) {
266
+ targetVecUpdate := targetVectors[0]
267
+ beforeUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
268
+ checkTargetVectors(t, beforeUpdateVectors)
269
+ require.IsType(t, []float32{}, beforeUpdateVectors[targetVecUpdate])
270
+ vecForNewObject := make([]float32, len(beforeUpdateVectors[targetVecUpdate].([]float32)))
271
+ copy(vecForNewObject, beforeUpdateVectors[targetVecUpdate].([]float32))
272
+ vecForNewObject[0] = vecForNewObject[0] + 0.1
273
+
274
+ require.NoError(t, client.Data().Updater().
275
+ WithMerge().
276
+ WithClassName(className).
277
+ WithID(id1).
278
+ WithProperties(map[string]interface{}{
279
+ "text": "Apple",
280
+ }).WithVectors(models.Vectors{targetVecUpdate: vecForNewObject}).
281
+ Do(ctx))
282
+
283
+ // vector from update should be used and it should be different from before
284
+ afterUpdateVectors := getVectors(t, client, className, id1, targetVectors...)
285
+ assert.NotEqual(t, beforeUpdateVectors[targetVecUpdate], afterUpdateVectors[targetVecUpdate])
286
+
287
+ // no vectorization
288
+ assert.Equal(t, vecForNewObject, afterUpdateVectors[targetVecUpdate])
289
+
290
+ // vectorization for vectors that have not been sent with the update
291
+ for _, targetVector := range targetVectors[1:] {
292
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
293
+ }
294
+ })
295
+ })
296
+ }
297
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_mixed.go ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "github.com/pkg/errors"
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/fault"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/schema"
26
+ )
27
+
28
+ func testCreateSchemaWithMixedVectorizers(host string) func(t *testing.T) {
29
+ return func(t *testing.T) {
30
+ ctx := context.Background()
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ t.Run("none vectorizer", func(t *testing.T) {
40
+ cleanup()
41
+
42
+ className := "BringYourOwnVector"
43
+ none1 := "none1"
44
+ none2 := "none2"
45
+ mixedTargetVectors := []string{none1, none2, m2vec, transformers_bq}
46
+ vector1a := []float32{0.1, 0.2, 0.3}
47
+ vector2a := []float32{-0.1001, 0.2002, -0.3003, -0.4, -0.5}
48
+ vector1b := []float32{0.1111, 0.4, 0.3}
49
+ vector2b := []float32{-0.11, 0.11111, -0.2222, -0.4, -0.5}
50
+ class := &models.Class{
51
+ Class: className,
52
+ Properties: []*models.Property{
53
+ {
54
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
55
+ },
56
+ },
57
+ VectorConfig: map[string]models.VectorConfig{
58
+ none1: {
59
+ Vectorizer: map[string]interface{}{
60
+ "none": nil,
61
+ },
62
+ VectorIndexType: "hnsw",
63
+ },
64
+ none2: {
65
+ Vectorizer: map[string]interface{}{
66
+ "none": nil,
67
+ },
68
+ VectorIndexType: "flat",
69
+ },
70
+ m2vec: {
71
+ Vectorizer: map[string]interface{}{
72
+ text2vecModel2Vec: map[string]interface{}{
73
+ "vectorizeClassName": false,
74
+ },
75
+ },
76
+ VectorIndexType: "hnsw",
77
+ },
78
+ transformers_bq: {
79
+ Vectorizer: map[string]interface{}{
80
+ text2vecTransformers: map[string]interface{}{
81
+ "vectorizeClassName": false,
82
+ },
83
+ },
84
+ VectorIndexType: "flat",
85
+ VectorIndexConfig: bqFlatIndexConfig(),
86
+ },
87
+ },
88
+ }
89
+
90
+ t.Run("create schema", func(t *testing.T) {
91
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
92
+ require.NoError(t, err)
93
+
94
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
95
+ require.NoError(t, err)
96
+ assert.Equal(t, class.Class, cls.Class)
97
+ require.NotEmpty(t, cls.VectorConfig)
98
+ require.Len(t, cls.VectorConfig, len(mixedTargetVectors))
99
+ for _, targetVector := range mixedTargetVectors {
100
+ require.NotEmpty(t, cls.VectorConfig[targetVector])
101
+ assert.NotEmpty(t, cls.VectorConfig[targetVector].VectorIndexType)
102
+ vectorizerConfig, ok := cls.VectorConfig[targetVector].Vectorizer.(map[string]interface{})
103
+ require.True(t, ok)
104
+ assert.Len(t, vectorizerConfig, 1)
105
+ }
106
+ })
107
+
108
+ t.Run("add objects", func(t *testing.T) {
109
+ objects := []struct {
110
+ id string
111
+ text string
112
+ vectors models.Vectors
113
+ }{
114
+ {
115
+ id: id1,
116
+ text: "bring your own first vector",
117
+ vectors: models.Vectors{
118
+ none1: vector1a,
119
+ none2: vector2a,
120
+ },
121
+ },
122
+ {
123
+ id: id2,
124
+ text: "bring your own second vector",
125
+ vectors: models.Vectors{
126
+ none1: vector1b,
127
+ none2: vector2b,
128
+ },
129
+ },
130
+ }
131
+ for _, tt := range objects {
132
+ objWrapper, err := client.Data().Creator().
133
+ WithClassName(className).
134
+ WithID(tt.id).
135
+ WithProperties(map[string]interface{}{
136
+ "text": tt.text,
137
+ }).
138
+ WithVectors(tt.vectors).
139
+ Do(ctx)
140
+ require.NoError(t, err)
141
+ require.NotNil(t, objWrapper)
142
+ assert.Len(t, objWrapper.Object.Vectors, 4)
143
+
144
+ objs, err := client.Data().ObjectsGetter().
145
+ WithClassName(className).
146
+ WithID(tt.id).
147
+ WithVector().
148
+ Do(ctx)
149
+ require.NoError(t, err)
150
+ require.Len(t, objs, 1)
151
+ require.NotNil(t, objs[0])
152
+ properties, ok := objs[0].Properties.(map[string]interface{})
153
+ require.True(t, ok)
154
+ assert.Equal(t, tt.text, properties["text"])
155
+ assert.Nil(t, objs[0].Vector)
156
+ assert.Len(t, objs[0].Vectors, len(mixedTargetVectors))
157
+ for targetVector, vector := range tt.vectors {
158
+ require.NotNil(t, objs[0].Vectors[targetVector])
159
+ assert.Equal(t, vector, objs[0].Vectors[targetVector])
160
+ }
161
+ }
162
+ })
163
+
164
+ t.Run("update vectors", func(t *testing.T) {
165
+ beforeUpdateVectors := getVectors(t, client, className, id1, mixedTargetVectors...)
166
+
167
+ updatedVector1 := []float32{0.11111111111, 0.2222222222, 0.3333333333}
168
+ updatedVector2 := []float32{0.1, 0.2, 0.3, 0.4, 0.5}
169
+ updatedVectors := models.Vectors{
170
+ none1: updatedVector1,
171
+ none2: updatedVector2,
172
+ }
173
+
174
+ err := client.Data().Updater().
175
+ WithClassName(className).
176
+ WithID(id1).
177
+ WithVectors(updatedVectors).
178
+ Do(ctx)
179
+ require.NoError(t, err)
180
+ afterUpdateVectors := getVectors(t, client, className, id1, mixedTargetVectors...)
181
+ for targetVector, vector := range updatedVectors {
182
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
183
+ assert.Equal(t, vector, models.Vector(afterUpdateVectors[targetVector]))
184
+ }
185
+ })
186
+
187
+ t.Run("update vectors with merge", func(t *testing.T) {
188
+ beforeUpdateVectors := getVectors(t, client, className, id1, mixedTargetVectors...)
189
+
190
+ updatedVector1 := []float32{0.00001, 0.0002, 0.00003}
191
+ updatedVector2 := []float32{1.1, 1.2, 1.3, 1.4, 1.5}
192
+ updatedVectors := models.Vectors{
193
+ none1: updatedVector1,
194
+ none2: updatedVector2,
195
+ }
196
+
197
+ err := client.Data().Updater().
198
+ WithMerge().
199
+ WithClassName(className).
200
+ WithID(id1).
201
+ WithProperties(map[string]interface{}{
202
+ "text": "This change should change vector",
203
+ }).
204
+ WithVectors(updatedVectors).
205
+ Do(ctx)
206
+ require.NoError(t, err)
207
+ afterUpdateVectors := getVectors(t, client, className, id1, mixedTargetVectors...)
208
+ for _, targetVector := range mixedTargetVectors {
209
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
210
+ }
211
+ for targetVector, vector := range updatedVectors {
212
+ assert.Equal(t, vector, models.Vector(afterUpdateVectors[targetVector]))
213
+ }
214
+ })
215
+
216
+ t.Run("check BYOV vector names for existence when inserting", func(t *testing.T) {
217
+ _, err = client.Data().Creator().
218
+ WithClassName(className).
219
+ WithID(id3).
220
+ WithProperties(map[string]interface{}{
221
+ "text": "Lorem ipsum dolor sit amet",
222
+ }).
223
+ WithVectors(models.Vectors{
224
+ "non_existent_vector": []float32{0.1, 0.2, 0.3},
225
+ }).
226
+ Do(ctx)
227
+ require.Error(t, err)
228
+ var clientError *fault.WeaviateClientError
229
+ require.True(t, errors.As(err, &clientError))
230
+ require.Equal(t, 422, clientError.StatusCode)
231
+ require.Contains(t, clientError.Msg, fmt.Sprintf("collection %s does not have configuration for vector non_existent_vector", className))
232
+ })
233
+
234
+ t.Run("check BYOV vector names for existence when updating", func(t *testing.T) {
235
+ err = client.Data().Updater().
236
+ WithClassName(className).
237
+ WithID(id1).
238
+ WithVectors(models.Vectors{
239
+ "non_existent_vector": []float32{0.1, 0.2, 0.3},
240
+ }).
241
+ Do(ctx)
242
+ require.Error(t, err)
243
+ var clientError *fault.WeaviateClientError
244
+ require.True(t, errors.As(err, &clientError))
245
+ require.Equal(t, 422, clientError.StatusCode)
246
+ require.Contains(t, clientError.Msg, fmt.Sprintf("collection %s does not have configuration for vector non_existent_vector", className))
247
+ })
248
+
249
+ t.Run("check BYOV vector names for existence when merge updating", func(t *testing.T) {
250
+ err = client.Data().Updater().WithMerge().
251
+ WithClassName(className).
252
+ WithID(id1).
253
+ WithVectors(models.Vectors{
254
+ "non_existent_vector": []float32{0.1, 0.2, 0.3},
255
+ }).
256
+ Do(ctx)
257
+ require.Error(t, err)
258
+ var clientError *fault.WeaviateClientError
259
+ require.True(t, errors.As(err, &clientError))
260
+ require.Equal(t, 422, clientError.StatusCode)
261
+ require.Contains(t, clientError.Msg, fmt.Sprintf("collection %s does not have configuration for vector non_existent_vector", className))
262
+ })
263
+ })
264
+ }
265
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_none_vectorizer.go ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "github.com/stretchr/testify/assert"
19
+ "github.com/stretchr/testify/require"
20
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
21
+ "github.com/weaviate/weaviate/entities/models"
22
+ "github.com/weaviate/weaviate/entities/schema"
23
+ )
24
+
25
+ func testCreateSchemaWithNoneVectorizer(host string) func(t *testing.T) {
26
+ return func(t *testing.T) {
27
+ ctx := context.Background()
28
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
29
+ require.Nil(t, err)
30
+
31
+ cleanup := func() {
32
+ err := client.Schema().AllDeleter().Do(context.Background())
33
+ require.Nil(t, err)
34
+ }
35
+
36
+ t.Run("none vectorizer", func(t *testing.T) {
37
+ cleanup()
38
+
39
+ className := "BringYourOwnVector"
40
+ none1 := "none1"
41
+ none2 := "none2"
42
+ bringYourTargetVectors := []string{none1, none2}
43
+ vector1a := []float32{0.1, 0.2, 0.3}
44
+ vector2a := []float32{-0.1001, 0.2002, -0.3003, -0.4, -0.5}
45
+ vector1b := []float32{0.1111, 0.4, 0.3}
46
+ vector2b := []float32{-0.11, 0.11111, -0.2222, -0.4, -0.5}
47
+ class := &models.Class{
48
+ Class: className,
49
+ Properties: []*models.Property{
50
+ {
51
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
52
+ },
53
+ },
54
+ VectorConfig: map[string]models.VectorConfig{
55
+ none1: {
56
+ Vectorizer: map[string]interface{}{
57
+ "none": nil,
58
+ },
59
+ VectorIndexType: "hnsw",
60
+ },
61
+ none2: {
62
+ Vectorizer: map[string]interface{}{
63
+ "none": nil,
64
+ },
65
+ VectorIndexType: "flat",
66
+ },
67
+ },
68
+ }
69
+
70
+ t.Run("create schema", func(t *testing.T) {
71
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
72
+ require.NoError(t, err)
73
+
74
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
75
+ require.NoError(t, err)
76
+ assert.Equal(t, class.Class, cls.Class)
77
+ require.NotEmpty(t, cls.VectorConfig)
78
+ require.Len(t, cls.VectorConfig, 2)
79
+ for _, targetVector := range []string{none1, none2} {
80
+ require.NotEmpty(t, cls.VectorConfig[targetVector])
81
+ assert.NotEmpty(t, cls.VectorConfig[targetVector].VectorIndexType)
82
+ vectorizerConfig, ok := cls.VectorConfig[targetVector].Vectorizer.(map[string]interface{})
83
+ require.True(t, ok)
84
+ assert.Len(t, vectorizerConfig, 1)
85
+ }
86
+ })
87
+
88
+ t.Run("add objects", func(t *testing.T) {
89
+ objects := []struct {
90
+ id string
91
+ text string
92
+ vectors models.Vectors
93
+ }{
94
+ {
95
+ id: id1,
96
+ text: "bring your own first vector",
97
+ vectors: models.Vectors{
98
+ none1: vector1a,
99
+ none2: vector2a,
100
+ },
101
+ },
102
+ {
103
+ id: id2,
104
+ text: "bring your own second vector",
105
+ vectors: models.Vectors{
106
+ none1: vector1b,
107
+ none2: vector2b,
108
+ },
109
+ },
110
+ }
111
+ for _, tt := range objects {
112
+ objWrapper, err := client.Data().Creator().
113
+ WithClassName(className).
114
+ WithID(tt.id).
115
+ WithProperties(map[string]interface{}{
116
+ "text": tt.text,
117
+ }).
118
+ WithVectors(tt.vectors).
119
+ Do(ctx)
120
+ require.NoError(t, err)
121
+ require.NotNil(t, objWrapper)
122
+ assert.Len(t, objWrapper.Object.Vectors, 2)
123
+
124
+ objs, err := client.Data().ObjectsGetter().
125
+ WithClassName(className).
126
+ WithID(tt.id).
127
+ WithVector().
128
+ Do(ctx)
129
+ require.NoError(t, err)
130
+ require.Len(t, objs, 1)
131
+ require.NotNil(t, objs[0])
132
+ properties, ok := objs[0].Properties.(map[string]interface{})
133
+ require.True(t, ok)
134
+ assert.Equal(t, tt.text, properties["text"])
135
+ assert.Nil(t, objs[0].Vector)
136
+ assert.Len(t, objs[0].Vectors, 2)
137
+ for targetVector, vector := range tt.vectors {
138
+ require.NotNil(t, objs[0].Vectors[targetVector])
139
+ assert.Equal(t, vector, objs[0].Vectors[targetVector])
140
+ }
141
+ }
142
+ })
143
+
144
+ t.Run("update vectors", func(t *testing.T) {
145
+ beforeUpdateVectors := getVectors(t, client, className, id1, bringYourTargetVectors...)
146
+
147
+ updatedVector1 := []float32{0.11111111111, 0.2222222222, 0.3333333333}
148
+ updatedVector2 := []float32{0.1, 0.2, 0.3, 0.4, 0.5}
149
+ updatedVectors := models.Vectors{
150
+ none1: updatedVector1,
151
+ none2: updatedVector2,
152
+ }
153
+
154
+ err := client.Data().Updater().
155
+ WithClassName(className).
156
+ WithID(id1).
157
+ WithVectors(updatedVectors).
158
+ Do(ctx)
159
+ require.NoError(t, err)
160
+ afterUpdateVectors := getVectors(t, client, className, id1, bringYourTargetVectors...)
161
+ for targetVector, vector := range updatedVectors {
162
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
163
+ assert.Equal(t, vector, models.Vector(afterUpdateVectors[targetVector]))
164
+ }
165
+ })
166
+
167
+ t.Run("update vectors with merge", func(t *testing.T) {
168
+ beforeUpdateVectors := getVectors(t, client, className, id1, bringYourTargetVectors...)
169
+
170
+ updatedVector1 := []float32{0.00001, 0.0002, 0.00003}
171
+ updatedVector2 := []float32{1.1, 1.2, 1.3, 1.4, 1.5}
172
+ updatedVectors := models.Vectors{
173
+ none1: updatedVector1,
174
+ none2: updatedVector2,
175
+ }
176
+
177
+ err := client.Data().Updater().
178
+ WithMerge().
179
+ WithClassName(className).
180
+ WithID(id1).
181
+ WithProperties(map[string]interface{}{
182
+ "text": "This change should change vector",
183
+ }).
184
+ WithVectors(updatedVectors).
185
+ Do(ctx)
186
+ require.NoError(t, err)
187
+ afterUpdateVectors := getVectors(t, client, className, id1, bringYourTargetVectors...)
188
+ for targetVector, vector := range updatedVectors {
189
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
190
+ assert.Equal(t, vector, models.Vector(afterUpdateVectors[targetVector]))
191
+ }
192
+ })
193
+
194
+ t.Run("GraphQL nearVector check", func(t *testing.T) {
195
+ tests := []struct {
196
+ targetVector string
197
+ vector []float32
198
+ }{
199
+ {
200
+ targetVector: none1,
201
+ vector: []float32{0.00001, 0.0002, 0.00003},
202
+ },
203
+ {
204
+ targetVector: none2,
205
+ vector: []float32{0.1, 0.2, 0.3, 0.4, 0.5},
206
+ },
207
+ }
208
+ for _, tt := range tests {
209
+ nearVector := client.GraphQL().NearVectorArgBuilder().
210
+ WithVector(tt.vector).
211
+ WithTargetVectors(tt.targetVector)
212
+ resultVectors := getVectorsWithNearVector(t, client, className, id1, nearVector, bringYourTargetVectors...)
213
+ for _, targetVector := range bringYourTargetVectors {
214
+ assert.NotEmpty(t, resultVectors[targetVector])
215
+ }
216
+ }
217
+ })
218
+
219
+ t.Run("update without vector", func(t *testing.T) {
220
+ beforeUpdateVectors := getVectors(t, client, className, id1, none1)
221
+
222
+ err := client.Data().Updater().
223
+ WithMerge().
224
+ WithClassName(className).
225
+ WithID(id1).
226
+ WithProperties(map[string]interface{}{
227
+ "text": "No vectorizer => Update should reuse old vector",
228
+ }).
229
+ Do(ctx)
230
+ require.NoError(t, err)
231
+ afterUpdateVectors := getVectors(t, client, className, id1, none1)
232
+ assert.Equal(t, beforeUpdateVectors[none1], afterUpdateVectors[none1])
233
+ })
234
+ })
235
+ }
236
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_objects_properties.go ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "acceptance_tests_with_client/fixtures"
20
+
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/schema"
26
+ )
27
+
28
+ func testCreateWithModulePropertiesObject(host string) func(t *testing.T) {
29
+ return func(t *testing.T) {
30
+ ctx := context.Background()
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ author := "author"
40
+ title := "title"
41
+ description := "description"
42
+ genre := "genre"
43
+
44
+ targetVectorsWithProperties := []string{
45
+ author, title, description, genre,
46
+ }
47
+
48
+ t.Run("multiple named vectors", func(t *testing.T) {
49
+ cleanup()
50
+
51
+ t.Run("create schema", func(t *testing.T) {
52
+ ctx := context.Background()
53
+ class := &models.Class{
54
+ Class: className,
55
+ Properties: []*models.Property{
56
+ {
57
+ Name: author, DataType: []string{schema.DataTypeText.String()},
58
+ },
59
+ {
60
+ Name: title, DataType: []string{schema.DataTypeText.String()},
61
+ },
62
+ {
63
+ Name: description, DataType: []string{schema.DataTypeText.String()},
64
+ },
65
+ {
66
+ Name: genre, DataType: []string{schema.DataTypeText.String()},
67
+ },
68
+ },
69
+ VectorConfig: map[string]models.VectorConfig{
70
+ author: {
71
+ Vectorizer: map[string]interface{}{
72
+ text2vecModel2Vec: map[string]interface{}{
73
+ "vectorizeClassName": false,
74
+ "properties": []interface{}{"author"},
75
+ },
76
+ },
77
+ VectorIndexType: "hnsw",
78
+ },
79
+ title: {
80
+ Vectorizer: map[string]interface{}{
81
+ text2vecModel2Vec: map[string]interface{}{
82
+ "vectorizeClassName": false,
83
+ "properties": []interface{}{"title"},
84
+ },
85
+ },
86
+ VectorIndexType: "flat",
87
+ },
88
+ description: {
89
+ Vectorizer: map[string]interface{}{
90
+ text2vecModel2Vec: map[string]interface{}{
91
+ "vectorizeClassName": false,
92
+ "properties": []interface{}{"description"},
93
+ },
94
+ },
95
+ VectorIndexType: "hnsw",
96
+ VectorIndexConfig: pqVectorIndexConfig(),
97
+ },
98
+ genre: {
99
+ Vectorizer: map[string]interface{}{
100
+ text2vecModel2Vec: map[string]interface{}{
101
+ "vectorizeClassName": false,
102
+ "properties": []interface{}{"genre"},
103
+ },
104
+ },
105
+ VectorIndexType: "flat",
106
+ VectorIndexConfig: bqFlatIndexConfig(),
107
+ },
108
+ },
109
+ }
110
+
111
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
112
+ require.NoError(t, err)
113
+
114
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
115
+ require.NoError(t, err)
116
+ assert.Equal(t, class.Class, cls.Class)
117
+ require.NotEmpty(t, cls.VectorConfig)
118
+ require.Len(t, cls.VectorConfig, 4)
119
+
120
+ for _, name := range targetVectorsWithProperties {
121
+ require.NotEmpty(t, cls.VectorConfig[name])
122
+ assert.Equal(t, class.VectorConfig[name].VectorIndexType, cls.VectorConfig[name].VectorIndexType)
123
+ vectorizerConfig, ok := cls.VectorConfig[name].Vectorizer.(map[string]interface{})
124
+ require.True(t, ok)
125
+ require.NotEmpty(t, vectorizerConfig)
126
+ }
127
+ })
128
+
129
+ t.Run("create objects", func(t *testing.T) {
130
+ for id, book := range fixtures.Books() {
131
+ objWrapper, err := client.Data().Creator().
132
+ WithClassName(className).
133
+ WithID(id).
134
+ WithProperties(map[string]interface{}{
135
+ author: book.Author,
136
+ title: book.Title,
137
+ description: book.Description,
138
+ genre: book.Genre,
139
+ }).
140
+ Do(ctx)
141
+ require.NoError(t, err)
142
+ require.NotNil(t, objWrapper)
143
+ assert.Len(t, objWrapper.Object.Vectors, 4)
144
+
145
+ objs, err := client.Data().ObjectsGetter().
146
+ WithClassName(className).
147
+ WithID(id).
148
+ WithVector().
149
+ Do(ctx)
150
+ require.NoError(t, err)
151
+ require.Len(t, objs, 1)
152
+ require.NotNil(t, objs[0])
153
+ assert.Len(t, objs[0].Vectors, 4)
154
+ properties, ok := objs[0].Properties.(map[string]interface{})
155
+ require.True(t, ok)
156
+ assert.Equal(t, book.Author, properties["author"])
157
+ assert.Equal(t, book.Title, properties["title"])
158
+ assert.Equal(t, book.Description, properties["description"])
159
+ assert.Equal(t, book.Genre, properties["genre"])
160
+ }
161
+ })
162
+
163
+ t.Run("check if all objects have been indexed", func(t *testing.T) {
164
+ testAllObjectsIndexed(t, client, className)
165
+ })
166
+
167
+ t.Run("GraphQL get vectors", func(t *testing.T) {
168
+ for id := range fixtures.Books() {
169
+ resultVectors := getVectors(t, client, className, id, targetVectorsWithProperties...)
170
+ for _, targetVector := range targetVectorsWithProperties {
171
+ assert.NotEmpty(t, resultVectors[targetVector])
172
+ }
173
+ }
174
+ })
175
+
176
+ t.Run("GraphQL near<Media> check", func(t *testing.T) {
177
+ for id, book := range fixtures.Books() {
178
+ for _, targetVector := range targetVectorsWithProperties {
179
+ nearText := client.GraphQL().NearTextArgBuilder().
180
+ WithConcepts([]string{book.Title}).
181
+ WithTargetVectors(targetVector)
182
+ resultVectors := getVectorsWithNearText(t, client, className, id, nearText, targetVectorsWithProperties...)
183
+ for _, targetVector := range targetVectorsWithProperties {
184
+ assert.NotEmpty(t, resultVectors[targetVector])
185
+ }
186
+ }
187
+ }
188
+ })
189
+
190
+ t.Run("GraphQL hybrid check", func(t *testing.T) {
191
+ for _, book := range fixtures.Books() {
192
+ raw := client.GraphQL().Raw()
193
+ res, err := raw.WithQuery(fmt.Sprintf(""+
194
+ "{Get {%s (hybrid: {query: %q targetVectors: %q}){title _additional{id}}}}", className, book.Title, "title")).Do(ctx)
195
+ require.Nil(t, err)
196
+ require.NotNil(t, res)
197
+ require.Nil(t, res.Errors)
198
+ require.NotNil(t, res.Data)
199
+ titleHybrid := res.Data["Get"].(map[string]interface{})[className].([]interface{})[0].(map[string]interface{})["title"].(string)
200
+ require.Equal(t, titleHybrid, book.Title)
201
+ }
202
+ })
203
+ t.Run("merge object and check if vectors changed", func(t *testing.T) {
204
+ for id, book := range fixtures.Books() {
205
+ beforeUpdateVectors := getVectors(t, client, className, id, targetVectorsWithProperties...)
206
+ // change only genre property
207
+ err := client.Data().Updater().
208
+ WithMerge().
209
+ WithClassName(className).
210
+ WithID(id).
211
+ WithProperties(map[string]interface{}{
212
+ author: book.Author,
213
+ title: book.Title,
214
+ description: book.Description,
215
+ genre: fmt.Sprintf("change only in %s genre", book.Genre),
216
+ }).
217
+ Do(ctx)
218
+ require.NoError(t, err)
219
+ afterUpdateVectors := getVectors(t, client, className, id, targetVectorsWithProperties...)
220
+ for _, targetVector := range targetVectors {
221
+ if targetVector == genre {
222
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
223
+ } else {
224
+ assert.Equal(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
225
+ }
226
+ }
227
+ }
228
+ })
229
+ })
230
+ }
231
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_ref_props.go ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "strings"
18
+ "testing"
19
+
20
+ "acceptance_tests_with_client/fixtures"
21
+
22
+ "github.com/go-openapi/strfmt"
23
+ "github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
25
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
26
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
27
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
28
+ "github.com/weaviate/weaviate/entities/models"
29
+ "github.com/weaviate/weaviate/entities/schema"
30
+ "github.com/weaviate/weaviate/usecases/config"
31
+ )
32
+
33
+ func testReferenceProperties(host string) func(t *testing.T) {
34
+ return func(t *testing.T) {
35
+ ctx := context.Background()
36
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
37
+ require.Nil(t, err)
38
+
39
+ cleanup := func() {
40
+ err := client.Schema().AllDeleter().Do(context.Background())
41
+ require.Nil(t, err)
42
+ }
43
+ cleanup()
44
+
45
+ classBookshelf := "Bookshelf"
46
+ classBook := "Book"
47
+ author := "author"
48
+ title := "title"
49
+ description := "description"
50
+ genre := "genre"
51
+ ofBookshelf := "ofBookshelf"
52
+ transformers_bookshelf_name := "transformers_bookshelf_name"
53
+ m2vec_bookshelf_name := "m2vec_bookshelf_name"
54
+
55
+ bookshelfIDs := []string{
56
+ "00000000-0000-0000-0000-00000000000a",
57
+ "00000000-0000-0000-0000-00000000000b",
58
+ "00000000-0000-0000-0000-00000000000c",
59
+ "00000000-0000-0000-0000-00000000000d",
60
+ }
61
+
62
+ t.Run("create schema", func(t *testing.T) {
63
+ bookshelf := &models.Class{
64
+ Class: classBookshelf,
65
+ Properties: []*models.Property{
66
+ {
67
+ Name: "name",
68
+ DataType: []string{"text"},
69
+ },
70
+ },
71
+ InvertedIndexConfig: &models.InvertedIndexConfig{IndexTimestamps: true, UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND},
72
+ VectorConfig: map[string]models.VectorConfig{
73
+ m2vec_bookshelf_name: {
74
+ Vectorizer: map[string]interface{}{
75
+ text2vecModel2Vec: map[string]interface{}{
76
+ "vectorizeClassName": false,
77
+ "properties": []interface{}{"name"},
78
+ },
79
+ },
80
+ VectorIndexType: "hnsw",
81
+ },
82
+ transformers_bookshelf_name: {
83
+ Vectorizer: map[string]interface{}{
84
+ text2vecModel2Vec: map[string]interface{}{
85
+ "vectorizeClassName": false,
86
+ "properties": []interface{}{"name"},
87
+ },
88
+ },
89
+ VectorIndexType: "flat",
90
+ },
91
+ },
92
+ }
93
+ book := &models.Class{
94
+ Class: classBook,
95
+ Properties: []*models.Property{
96
+ {
97
+ Name: author, DataType: []string{schema.DataTypeText.String()},
98
+ },
99
+ {
100
+ Name: title, DataType: []string{schema.DataTypeText.String()},
101
+ },
102
+ {
103
+ Name: description, DataType: []string{schema.DataTypeText.String()},
104
+ },
105
+ {
106
+ Name: genre, DataType: []string{schema.DataTypeText.String()},
107
+ },
108
+ {
109
+ Name: ofBookshelf, DataType: []string{classBookshelf},
110
+ },
111
+ },
112
+ VectorConfig: map[string]models.VectorConfig{
113
+ author: {
114
+ Vectorizer: map[string]interface{}{
115
+ text2vecModel2Vec: map[string]interface{}{
116
+ "vectorizeClassName": false,
117
+ "properties": []interface{}{author},
118
+ },
119
+ },
120
+ VectorIndexType: "hnsw",
121
+ },
122
+ title: {
123
+ Vectorizer: map[string]interface{}{
124
+ text2vecModel2Vec: map[string]interface{}{
125
+ "vectorizeClassName": false,
126
+ "properties": []interface{}{title},
127
+ },
128
+ },
129
+ VectorIndexType: "flat",
130
+ },
131
+ description: {
132
+ Vectorizer: map[string]interface{}{
133
+ text2vecTransformers: map[string]interface{}{
134
+ "vectorizeClassName": false,
135
+ "properties": []interface{}{description},
136
+ },
137
+ },
138
+ VectorIndexType: "hnsw",
139
+ VectorIndexConfig: pqVectorIndexConfig(),
140
+ },
141
+ genre: {
142
+ Vectorizer: map[string]interface{}{
143
+ text2vecTransformers: map[string]interface{}{
144
+ "vectorizeClassName": false,
145
+ "properties": []interface{}{genre},
146
+ },
147
+ },
148
+ VectorIndexType: "flat",
149
+ VectorIndexConfig: bqFlatIndexConfig(),
150
+ },
151
+ },
152
+ }
153
+ err := client.Schema().ClassCreator().WithClass(bookshelf).Do(ctx)
154
+ assert.NoError(t, err)
155
+ err = client.Schema().ClassCreator().WithClass(book).Do(ctx)
156
+ require.NoError(t, err)
157
+ })
158
+
159
+ t.Run("import data", func(t *testing.T) {
160
+ bookshelfs := make([]*models.Object, len(bookshelfIDs))
161
+ for i, id := range bookshelfIDs {
162
+ bookshelfs[i] = &models.Object{
163
+ ID: strfmt.UUID(id),
164
+ Class: classBookshelf,
165
+ Properties: map[string]interface{}{
166
+ "name": fmt.Sprintf("Name of the bookshelf number %v", i),
167
+ },
168
+ }
169
+ }
170
+ resp, err := client.Batch().ObjectsBatcher().
171
+ WithObjects(bookshelfs...).
172
+ Do(ctx)
173
+ require.NoError(t, err)
174
+ require.NotNil(t, resp)
175
+
176
+ books := []*models.Object{}
177
+ for id, book := range fixtures.Books() {
178
+ books = append(books, &models.Object{
179
+ ID: strfmt.UUID(id),
180
+ Class: classBook,
181
+ Properties: map[string]interface{}{
182
+ author: book.Author,
183
+ title: book.Title,
184
+ description: book.Description,
185
+ genre: book.Genre,
186
+ },
187
+ })
188
+ }
189
+ resp, err = client.Batch().ObjectsBatcher().
190
+ WithObjects(books...).
191
+ Do(ctx)
192
+ require.NoError(t, err)
193
+ require.NotNil(t, resp)
194
+
195
+ createReferences := func(t *testing.T, client *wvt.Client,
196
+ bookshelf *models.Object, books []*models.Object,
197
+ ) {
198
+ ref := client.Data().ReferencePayloadBuilder().
199
+ WithID(bookshelf.ID.String()).WithClassName(bookshelf.Class).Payload()
200
+ for _, book := range books {
201
+ err := client.Data().ReferenceCreator().
202
+ WithID(book.ID.String()).
203
+ WithClassName(book.Class).
204
+ WithReferenceProperty(ofBookshelf).
205
+ WithReference(ref).
206
+ Do(context.TODO())
207
+ assert.Nil(t, err)
208
+ }
209
+ }
210
+
211
+ createReferences(t, client, bookshelfs[0], books[:10])
212
+ createReferences(t, client, bookshelfs[1], books[10:])
213
+ })
214
+
215
+ t.Run("GrahQL check", func(t *testing.T) {
216
+ targetVectors := []string{transformers_bookshelf_name, m2vec_bookshelf_name}
217
+ where := filters.Where().
218
+ WithPath([]string{"id"}).
219
+ WithOperator(filters.Equal).
220
+ WithValueText(id1)
221
+ _additional := graphql.Field{
222
+ Name: "_additional",
223
+ Fields: []graphql.Field{
224
+ {Name: "id"},
225
+ {Name: fmt.Sprintf("vectors{%s}", strings.Join(targetVectors, " "))},
226
+ },
227
+ }
228
+ ofBookshelfField := graphql.Field{
229
+ Name: ofBookshelf,
230
+ Fields: []graphql.Field{
231
+ {
232
+ Name: "... on Bookshelf",
233
+ Fields: []graphql.Field{_additional},
234
+ },
235
+ },
236
+ }
237
+ resp, err := client.GraphQL().Get().
238
+ WithClassName(classBook).
239
+ WithWhere(where).
240
+ WithFields(ofBookshelfField).
241
+ Do(ctx)
242
+ require.NoError(t, err)
243
+ require.NotNil(t, resp)
244
+ require.NotNil(t, resp.Data)
245
+ require.Empty(t, resp.Errors)
246
+
247
+ classMap, ok := resp.Data["Get"].(map[string]interface{})
248
+ require.True(t, ok)
249
+
250
+ class, ok := classMap[classBook].([]interface{})
251
+ require.True(t, ok)
252
+
253
+ targetVectorsMap := make(map[string][]float32)
254
+ for i := range class {
255
+ resultMap, ok := class[i].(map[string]interface{})
256
+ require.True(t, ok)
257
+
258
+ refProp, ok := resultMap[ofBookshelf].([]interface{})
259
+ require.True(t, ok)
260
+ require.Len(t, refProp, 1)
261
+
262
+ aaa, ok := refProp[0].(map[string]interface{})
263
+ require.True(t, ok)
264
+
265
+ additional, ok := aaa["_additional"].(map[string]interface{})
266
+ require.True(t, ok)
267
+
268
+ vectors, ok := additional["vectors"].(map[string]interface{})
269
+ require.True(t, ok)
270
+
271
+ for _, targetVector := range targetVectors {
272
+ vector, ok := vectors[targetVector].([]interface{})
273
+ require.True(t, ok)
274
+
275
+ vec := make([]float32, len(vector))
276
+ for i := range vector {
277
+ vec[i] = float32(vector[i].(float64))
278
+ }
279
+
280
+ targetVectorsMap[targetVector] = vec
281
+ }
282
+ }
283
+ require.Len(t, targetVectorsMap, len(targetVectors))
284
+ assert.NotEmpty(t, targetVectorsMap[m2vec_bookshelf_name])
285
+ assert.NotEmpty(t, targetVectorsMap[transformers_bookshelf_name])
286
+ })
287
+ }
288
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_restart.go ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/test/docker"
25
+ )
26
+
27
+ func TestRestart(compose *docker.DockerCompose) func(t *testing.T) {
28
+ return func(t *testing.T) {
29
+ ctx := context.Background()
30
+ host := compose.GetWeaviate().URI()
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ t.Run("multiple named vectors", func(t *testing.T) {
40
+ cleanup()
41
+
42
+ t.Run("create schema", func(t *testing.T) {
43
+ createNamedVectorsClass(t, client)
44
+ })
45
+
46
+ t.Run("batch create objects", func(t *testing.T) {
47
+ objs := []*models.Object{}
48
+ for id, book := range fixtures.Books() {
49
+ obj := &models.Object{
50
+ Class: className,
51
+ ID: strfmt.UUID(id),
52
+ Properties: map[string]interface{}{
53
+ "text": book.Description,
54
+ },
55
+ }
56
+ objs = append(objs, obj)
57
+ }
58
+
59
+ resp, err := client.Batch().ObjectsBatcher().
60
+ WithObjects(objs...).
61
+ Do(ctx)
62
+ require.NoError(t, err)
63
+ require.NotNil(t, resp)
64
+ })
65
+
66
+ t.Run("check existence", func(t *testing.T) {
67
+ for id := range fixtures.Books() {
68
+ exists, err := client.Data().Checker().
69
+ WithID(id).
70
+ WithClassName(className).
71
+ Do(ctx)
72
+ require.NoError(t, err)
73
+ require.True(t, exists)
74
+ }
75
+ })
76
+
77
+ t.Run("check if all objects have been indexed", func(t *testing.T) {
78
+ testAllObjectsIndexed(t, client, className)
79
+ })
80
+
81
+ t.Run("GraphQL get vectors", func(t *testing.T) {
82
+ for id := range fixtures.Books() {
83
+ resultVectors := getVectors(t, client, className, id, targetVectors...)
84
+ checkTargetVectors(t, resultVectors)
85
+ }
86
+ })
87
+
88
+ t.Run("GraphQL near<Media> check", func(t *testing.T) {
89
+ for id, book := range fixtures.Books() {
90
+ for _, targetVector := range targetVectors {
91
+ nearText := client.GraphQL().NearTextArgBuilder().
92
+ WithConcepts([]string{book.Title}).
93
+ WithTargetVectors(targetVector)
94
+ resultVectors := getVectorsWithNearText(t, client, className, id, nearText, targetVectors...)
95
+ checkTargetVectors(t, resultVectors)
96
+ }
97
+ }
98
+ })
99
+
100
+ t.Run("GraphQL near<Media> check after restart", func(t *testing.T) {
101
+ err := compose.Stop(ctx, compose.GetWeaviate().Name(), nil)
102
+ require.NoError(t, err)
103
+
104
+ err = compose.Start(ctx, compose.GetWeaviate().Name())
105
+ require.NoError(t, err)
106
+
107
+ host := compose.GetWeaviate().URI()
108
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
109
+ require.Nil(t, err)
110
+
111
+ for id, book := range fixtures.Books() {
112
+ for _, targetVector := range targetVectors {
113
+ nearText := client.GraphQL().NearTextArgBuilder().
114
+ WithConcepts([]string{book.Title}).
115
+ WithTargetVectors(targetVector)
116
+ resultVectors := getVectorsWithNearText(t, client, className, id, nearText, targetVectors...)
117
+ checkTargetVectors(t, resultVectors)
118
+ }
119
+ }
120
+ })
121
+ })
122
+ }
123
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_schema.go ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "github.com/stretchr/testify/assert"
19
+ "github.com/stretchr/testify/require"
20
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
21
+ "github.com/weaviate/weaviate/entities/models"
22
+ "github.com/weaviate/weaviate/entities/schema"
23
+ )
24
+
25
+ func testCreateSchema(host string) func(t *testing.T) {
26
+ return func(t *testing.T) {
27
+ ctx := context.Background()
28
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
29
+ require.Nil(t, err)
30
+
31
+ cleanup := func() {
32
+ err := client.Schema().AllDeleter().Do(context.Background())
33
+ require.Nil(t, err)
34
+ }
35
+
36
+ t.Run("one named vector", func(t *testing.T) {
37
+ cleanup()
38
+ className := "NamedVector"
39
+ text2vecOpenAI := "text2vec-openai"
40
+ class := &models.Class{
41
+ Class: className,
42
+ Properties: []*models.Property{
43
+ {
44
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
45
+ },
46
+ },
47
+ VectorConfig: map[string]models.VectorConfig{
48
+ "openai": {
49
+ Vectorizer: map[string]interface{}{
50
+ text2vecOpenAI: map[string]interface{}{
51
+ "vectorizeClassName": false,
52
+ },
53
+ },
54
+ VectorIndexType: "hnsw",
55
+ },
56
+ },
57
+ }
58
+
59
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
60
+ require.NoError(t, err)
61
+
62
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
63
+ require.NoError(t, err)
64
+ assert.Equal(t, class.Class, cls.Class)
65
+ require.NotEmpty(t, cls.VectorConfig)
66
+ require.Len(t, cls.VectorConfig, 1)
67
+ require.NotEmpty(t, cls.VectorConfig["openai"])
68
+ assert.Equal(t, class.VectorConfig["openai"].VectorIndexType, cls.VectorConfig["openai"].VectorIndexType)
69
+ vectorizerConfig, ok := cls.VectorConfig["openai"].Vectorizer.(map[string]interface{})
70
+ require.True(t, ok)
71
+ require.NotEmpty(t, vectorizerConfig[text2vecOpenAI])
72
+ })
73
+
74
+ t.Run("multiple named vectors", func(t *testing.T) {
75
+ cleanup()
76
+ className := "NamedVectors"
77
+ name1 := "openai"
78
+ name2 := "cohere"
79
+ text2vecOpenAI := "text2vec-openai"
80
+ text2vecCohere := "text2vec-cohere"
81
+ class := &models.Class{
82
+ Class: className,
83
+ Properties: []*models.Property{
84
+ {
85
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
86
+ },
87
+ },
88
+ VectorConfig: map[string]models.VectorConfig{
89
+ name1: {
90
+ Vectorizer: map[string]interface{}{
91
+ text2vecOpenAI: map[string]interface{}{
92
+ "vectorizeClassName": false,
93
+ },
94
+ },
95
+ VectorIndexType: "hnsw",
96
+ },
97
+ name2: {
98
+ Vectorizer: map[string]interface{}{
99
+ text2vecCohere: map[string]interface{}{
100
+ "vectorizeClassName": false,
101
+ },
102
+ },
103
+ VectorIndexType: "flat",
104
+ },
105
+ },
106
+ }
107
+
108
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
109
+ require.NoError(t, err)
110
+
111
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
112
+ require.NoError(t, err)
113
+ assert.Equal(t, class.Class, cls.Class)
114
+ require.NotEmpty(t, cls.VectorConfig)
115
+ require.Len(t, cls.VectorConfig, 2)
116
+ for _, name := range []string{name1, name2} {
117
+ require.NotEmpty(t, cls.VectorConfig[name])
118
+ assert.Equal(t, class.VectorConfig[name].VectorIndexType, cls.VectorConfig[name].VectorIndexType)
119
+ vectorizerConfig, ok := cls.VectorConfig[name].Vectorizer.(map[string]interface{})
120
+ require.True(t, ok)
121
+ vectorizerName := text2vecOpenAI
122
+ if name == name2 {
123
+ vectorizerName = text2vecCohere
124
+ }
125
+ require.NotEmpty(t, vectorizerConfig[vectorizerName])
126
+ }
127
+ })
128
+
129
+ t.Run("defaults for vectorizer configs", func(t *testing.T) {
130
+ cleanup()
131
+
132
+ className := "NamedVectorsDefaults"
133
+ nameOpenAI := "openai"
134
+ nameCohere := "cohere"
135
+ text2vecOpenAI := "text2vec-openai"
136
+ text2vecCohere := "text2vec-cohere"
137
+
138
+ vectorizerConfigData := map[string]struct {
139
+ name string
140
+ classOptions []string
141
+ propOptions []string
142
+ }{
143
+ nameOpenAI: {
144
+ name: text2vecOpenAI,
145
+ classOptions: []string{"vectorizeClassName", "baseURL", "model"},
146
+ propOptions: []string{"vectorizePropertyName", "skip"},
147
+ },
148
+ nameCohere: {
149
+ name: text2vecCohere,
150
+ classOptions: []string{"vectorizeClassName", "baseUrl", "model", "truncate"},
151
+ propOptions: []string{"vectorizePropertyName", "skip"},
152
+ },
153
+ }
154
+
155
+ class := &models.Class{
156
+ Class: className,
157
+ Properties: []*models.Property{
158
+ {
159
+ Name: "text",
160
+ DataType: schema.DataTypeText.PropString(),
161
+ },
162
+ },
163
+ VectorConfig: map[string]models.VectorConfig{
164
+ nameOpenAI: {
165
+ VectorIndexType: "hnsw",
166
+ Vectorizer: map[string]interface{}{
167
+ text2vecOpenAI: map[string]interface{}{},
168
+ },
169
+ },
170
+ nameCohere: {
171
+ VectorIndexType: "flat",
172
+ Vectorizer: map[string]interface{}{
173
+ text2vecCohere: map[string]interface{}{},
174
+ },
175
+ },
176
+ },
177
+ }
178
+
179
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
180
+ require.NoError(t, err)
181
+
182
+ classCreated, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
183
+ require.NoError(t, err)
184
+ assert.Equal(t, class.Class, classCreated.Class)
185
+
186
+ // class defaults
187
+ require.NotNil(t, classCreated.VectorConfig)
188
+ require.Len(t, classCreated.VectorConfig, len(vectorizerConfigData))
189
+ for vectorName, vectorizer := range vectorizerConfigData {
190
+ require.Contains(t, classCreated.VectorConfig, vectorName)
191
+
192
+ vectorConfig := class.VectorConfig[vectorName]
193
+ vectorConfigCreated := classCreated.VectorConfig[vectorName]
194
+
195
+ require.NotNil(t, vectorConfigCreated)
196
+ assert.Equal(t, vectorConfig.VectorIndexType, vectorConfigCreated.VectorIndexType)
197
+ assert.NotEmpty(t, vectorConfigCreated.VectorIndexConfig)
198
+
199
+ require.NotNil(t, vectorConfigCreated.Vectorizer)
200
+ vectorizers, ok := vectorConfigCreated.Vectorizer.(map[string]interface{})
201
+ require.True(t, ok)
202
+ require.Len(t, vectorizers, 1)
203
+ require.Contains(t, vectorizers, vectorizer.name)
204
+ require.NotNil(t, vectorizers[vectorizer.name])
205
+
206
+ vectorizerConfig, ok := vectorizers[vectorizer.name].(map[string]interface{})
207
+ require.True(t, ok)
208
+ require.Len(t, vectorizerConfig, len(vectorizer.classOptions))
209
+ for _, classOption := range vectorizer.classOptions {
210
+ assert.Contains(t, vectorizerConfig, classOption)
211
+ }
212
+ }
213
+ assert.Nil(t, class.ModuleConfig)
214
+ assert.Empty(t, class.Vectorizer)
215
+ assert.Empty(t, class.VectorIndexType)
216
+ assert.Nil(t, class.VectorIndexConfig)
217
+
218
+ // props defaults
219
+ for _, prop := range classCreated.Properties {
220
+ require.NotNil(t, prop.ModuleConfig)
221
+
222
+ propModuleConfig, ok := prop.ModuleConfig.(map[string]interface{})
223
+ require.True(t, ok)
224
+ require.Len(t, propModuleConfig, len(vectorizerConfigData))
225
+
226
+ for _, vectorizer := range vectorizerConfigData {
227
+ require.Contains(t, propModuleConfig, vectorizer.name)
228
+ require.NotNil(t, propModuleConfig[vectorizer.name])
229
+
230
+ vectorizerConfig, ok := propModuleConfig[vectorizer.name].(map[string]interface{})
231
+ require.True(t, ok)
232
+ require.Len(t, vectorizerConfig, len(vectorizer.propOptions))
233
+ for _, propOption := range vectorizer.propOptions {
234
+ assert.Contains(t, vectorizerConfig, propOption)
235
+ }
236
+ }
237
+ }
238
+ })
239
+ }
240
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_schema_validation.go ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "github.com/stretchr/testify/assert"
20
+ "github.com/stretchr/testify/require"
21
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+ "github.com/weaviate/weaviate/entities/schema"
24
+ )
25
+
26
+ func testSchemaValidation(host string) func(t *testing.T) {
27
+ return func(t *testing.T) {
28
+ ctx := context.Background()
29
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
30
+ require.Nil(t, err)
31
+
32
+ cleanup := func() {
33
+ err := client.Schema().AllDeleter().Do(context.Background())
34
+ require.Nil(t, err)
35
+ }
36
+
37
+ t.Run("none existent name of the vectorizer module", func(t *testing.T) {
38
+ cleanup()
39
+ className := "NamedVector"
40
+ nonExistenVectorizer := "non_existent_vectorizer_module"
41
+ class := &models.Class{
42
+ Class: className,
43
+ Properties: []*models.Property{
44
+ {
45
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
46
+ },
47
+ },
48
+ VectorConfig: map[string]models.VectorConfig{
49
+ nonExistenVectorizer: {
50
+ Vectorizer: map[string]interface{}{
51
+ nonExistenVectorizer: map[string]interface{}{
52
+ "vectorizeClassName": false,
53
+ },
54
+ },
55
+ VectorIndexType: "hnsw",
56
+ },
57
+ },
58
+ }
59
+
60
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
61
+ require.Error(t, err)
62
+ assert.ErrorContains(t, err, "vectorizer: no module with name \\\"non_existent_vectorizer_module\\\" present")
63
+ })
64
+
65
+ t.Run("properties check", func(t *testing.T) {
66
+ cleanup()
67
+ className := "NamedVector"
68
+ class := &models.Class{
69
+ Class: className,
70
+ Properties: []*models.Property{
71
+ {
72
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
73
+ },
74
+ },
75
+ VectorConfig: map[string]models.VectorConfig{
76
+ m2vec: {
77
+ Vectorizer: map[string]interface{}{
78
+ text2vecModel2Vec: map[string]interface{}{
79
+ "vectorizeClassName": false,
80
+ "properties": []interface{}{"text", 1111},
81
+ },
82
+ },
83
+ VectorIndexType: "hnsw",
84
+ },
85
+ },
86
+ }
87
+
88
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
89
+ require.Error(t, err)
90
+ assert.ErrorContains(t, err, "properties field value: 1111 must be a string")
91
+ })
92
+
93
+ t.Run("very long target vector name", func(t *testing.T) {
94
+ tests := []struct {
95
+ targetVectorName string
96
+ validationErrorMsg string
97
+ }{
98
+ {
99
+ targetVectorName: fmt.Sprintf("%s1", transformers_bq_very_long_230_chars),
100
+ validationErrorMsg: "Target vector name should not be longer than 230 characters",
101
+ },
102
+ {
103
+ targetVectorName: "invalid-characters",
104
+ validationErrorMsg: "Weaviate target vector names are restricted to valid GraphQL names",
105
+ },
106
+ }
107
+ for _, tt := range tests {
108
+ cleanup()
109
+ class := &models.Class{
110
+ Class: className,
111
+ Properties: []*models.Property{
112
+ {
113
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
114
+ },
115
+ },
116
+ VectorConfig: map[string]models.VectorConfig{
117
+ tt.targetVectorName: {
118
+ Vectorizer: map[string]interface{}{
119
+ text2vecModel2Vec: map[string]interface{}{
120
+ "vectorizeClassName": false,
121
+ },
122
+ },
123
+ VectorIndexType: "flat",
124
+ VectorIndexConfig: bqFlatIndexConfig(),
125
+ },
126
+ },
127
+ }
128
+
129
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
130
+ require.Error(t, err)
131
+ assert.ErrorContains(t, err, tt.validationErrorMsg)
132
+ }
133
+ })
134
+
135
+ t.Run("default vector", func(t *testing.T) {
136
+ cleanup()
137
+ oneTargetVector := "oneTargetVector"
138
+ class := &models.Class{
139
+ Class: className,
140
+ Properties: []*models.Property{
141
+ {
142
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
143
+ },
144
+ },
145
+ VectorConfig: map[string]models.VectorConfig{
146
+ oneTargetVector: {
147
+ Vectorizer: map[string]interface{}{
148
+ text2vecModel2Vec: map[string]interface{}{
149
+ "vectorizeClassName": false,
150
+ },
151
+ },
152
+ VectorIndexType: "flat",
153
+ VectorIndexConfig: bqFlatIndexConfig(),
154
+ },
155
+ },
156
+ }
157
+
158
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
159
+ require.NoError(t, err)
160
+
161
+ objWrapper, err := client.Data().Creator().
162
+ WithClassName(className).
163
+ WithID(id1).
164
+ WithProperties(map[string]interface{}{
165
+ "text": "default target vector",
166
+ }).
167
+ Do(ctx)
168
+ require.NoError(t, err)
169
+ require.NotNil(t, objWrapper)
170
+ assert.Len(t, objWrapper.Object.Vectors, 1)
171
+
172
+ nearTextWithoutTargetVector := client.GraphQL().NearTextArgBuilder().
173
+ WithConcepts([]string{"book"})
174
+
175
+ resultVectors := getVectorsWithNearText(t, client, className, id1, nearTextWithoutTargetVector, oneTargetVector)
176
+ assert.Len(t, resultVectors, 1)
177
+ })
178
+
179
+ t.Run("generative module wrong configuration - legacy configuration", func(t *testing.T) {
180
+ class := &models.Class{
181
+ Class: "GenerativeOpenAIModuleLegacyValidation",
182
+ Properties: []*models.Property{
183
+ {
184
+ Name: "text",
185
+ DataType: []string{schema.DataTypeText.String()},
186
+ },
187
+ },
188
+ ModuleConfig: map[string]interface{}{
189
+ "generative-openai": map[string]interface{}{
190
+ "model": "wrong-model",
191
+ },
192
+ },
193
+ Vectorizer: text2vecModel2Vec,
194
+ VectorIndexType: "hnsw",
195
+ }
196
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
197
+ require.Error(t, err)
198
+ assert.ErrorContains(t, err, "wrong OpenAI model name")
199
+ })
200
+
201
+ t.Run("generative module wrong configuration - multiple vectors", func(t *testing.T) {
202
+ class := &models.Class{
203
+ Class: "GenerativeOpenAIModuleValidation",
204
+ Properties: []*models.Property{
205
+ {
206
+ Name: "text",
207
+ DataType: []string{schema.DataTypeText.String()},
208
+ },
209
+ },
210
+ VectorConfig: map[string]models.VectorConfig{
211
+ m2vec: {
212
+ Vectorizer: map[string]interface{}{
213
+ text2vecModel2Vec: map[string]interface{}{
214
+ "vectorizeClassName": false,
215
+ },
216
+ },
217
+ VectorIndexType: "hnsw",
218
+ },
219
+ transformers_flat: {
220
+ Vectorizer: map[string]interface{}{
221
+ text2vecTransformers: map[string]interface{}{
222
+ "vectorizeClassName": false,
223
+ },
224
+ },
225
+ VectorIndexType: "flat",
226
+ },
227
+ },
228
+ ModuleConfig: map[string]interface{}{
229
+ "generative-openai": map[string]interface{}{
230
+ "model": "wrong-model",
231
+ },
232
+ },
233
+ }
234
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
235
+ require.Error(t, err)
236
+ assert.ErrorContains(t, err, "wrong OpenAI model name")
237
+ })
238
+
239
+ t.Run("generative module proper configuration - multiple vectors", func(t *testing.T) {
240
+ class := &models.Class{
241
+ Class: "GenerativeOpenAIModuleValidationProperConfig",
242
+ Properties: []*models.Property{
243
+ {
244
+ Name: "text",
245
+ DataType: []string{schema.DataTypeText.String()},
246
+ },
247
+ },
248
+ VectorConfig: map[string]models.VectorConfig{
249
+ m2vec: {
250
+ Vectorizer: map[string]interface{}{
251
+ text2vecModel2Vec: map[string]interface{}{
252
+ "vectorizeClassName": false,
253
+ },
254
+ },
255
+ VectorIndexType: "hnsw",
256
+ },
257
+ transformers_flat: {
258
+ Vectorizer: map[string]interface{}{
259
+ text2vecTransformers: map[string]interface{}{
260
+ "vectorizeClassName": false,
261
+ },
262
+ },
263
+ VectorIndexType: "flat",
264
+ },
265
+ },
266
+ ModuleConfig: map[string]interface{}{
267
+ "generative-openai": map[string]interface{}{
268
+ "model": "gpt-4",
269
+ },
270
+ },
271
+ }
272
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
273
+ require.NoError(t, err)
274
+ })
275
+ }
276
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_test_data.go ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "strings"
18
+ "testing"
19
+ "time"
20
+
21
+ acceptance_with_go_client "acceptance_tests_with_client"
22
+
23
+ "github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
25
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
26
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
27
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
28
+ "github.com/weaviate/weaviate/entities/models"
29
+ "github.com/weaviate/weaviate/entities/schema"
30
+ "github.com/weaviate/weaviate/entities/vectorindex/hnsw"
31
+ )
32
+
33
+ var (
34
+ className = "NamedVectors"
35
+ m2vec = "m2vec"
36
+ m2vec_pq = "m2vec_pq"
37
+ m2vec_flat = "m2vec_flat"
38
+ m2vec_bq = "m2vec_bq"
39
+ m2vec_pq_very_long_230_chars = "m2vec_pq_____bq_b9mgu3N7rCUWufddpfCqaVvr4IUjB9xpMBrmiQFIqyuUxKx5s8wCTD7iWb5gPkwNhECumphBMWXD67G9gvN4CQkylG3bDrR8p9sK02RLOGvE96jcaSKjpZrIRvjJuQliGf8BMNmzXEqH39UWGGt4zPNnZNvdPP6pIzxWG5zNpymGmJJLCHk6yP1eO3QgSdXMt0arzfcrAA1L9uZNIVT7tM"
40
+ model2vec = "model2vec"
41
+ transformers = "transformers"
42
+ transformers_flat = "transformers_flat"
43
+ transformers_pq = "transformers_pq"
44
+ transformers_bq = "transformers_bq"
45
+ transformers_bq_very_long_230_chars = "transformers_bq_b9mgu3N7rCUWufddpfCqaVvr4IUjB9xpMBrmiQFIqyuUxKx5s8wCTD7iWb5gPkwNhECumphBMWXD67G9gvN4CQkylG3bDrR8p9sK02RLOGvE96jcaSKjpZrIRvjJuQliGf8BMNmzXEqH39UWGGt4zPNnZNvdPP6pIzxWG5zNpymGmJJLCHk6yP1eO3QgSdXMt0arzfcrAA1L9uZNIVT7tM"
46
+ text2vecModel2Vec = "text2vec-model2vec"
47
+ text2vecTransformers = "text2vec-transformers"
48
+ id1 = "00000000-0000-0000-0000-000000000001"
49
+ id2 = "00000000-0000-0000-0000-000000000002"
50
+ id3 = "00000000-0000-0000-0000-000000000003"
51
+ )
52
+
53
+ var targetVectors = []string{
54
+ m2vec, m2vec_flat, m2vec_pq, m2vec_bq,
55
+ transformers, transformers_flat, transformers_pq, transformers_bq,
56
+ transformers_bq_very_long_230_chars, m2vec_pq_very_long_230_chars,
57
+ }
58
+
59
+ func createNamedVectorsClass(t *testing.T, client *wvt.Client) {
60
+ ctx := context.Background()
61
+ class := &models.Class{
62
+ Class: className,
63
+ Properties: []*models.Property{
64
+ {
65
+ Name: "text", DataType: []string{schema.DataTypeText.String()},
66
+ },
67
+ },
68
+ VectorConfig: map[string]models.VectorConfig{
69
+ m2vec: {
70
+ Vectorizer: map[string]interface{}{
71
+ text2vecModel2Vec: map[string]interface{}{
72
+ "vectorizeClassName": false,
73
+ },
74
+ },
75
+ VectorIndexType: "hnsw",
76
+ },
77
+ m2vec_flat: {
78
+ Vectorizer: map[string]interface{}{
79
+ text2vecModel2Vec: map[string]interface{}{
80
+ "vectorizeClassName": false,
81
+ },
82
+ },
83
+ VectorIndexType: "flat",
84
+ },
85
+ m2vec_pq: {
86
+ Vectorizer: map[string]interface{}{
87
+ text2vecModel2Vec: map[string]interface{}{
88
+ "vectorizeClassName": false,
89
+ },
90
+ },
91
+ VectorIndexType: "hnsw",
92
+ VectorIndexConfig: pqVectorIndexConfig(),
93
+ },
94
+ m2vec_bq: {
95
+ Vectorizer: map[string]interface{}{
96
+ text2vecModel2Vec: map[string]interface{}{
97
+ "vectorizeClassName": false,
98
+ },
99
+ },
100
+ VectorIndexType: "flat",
101
+ VectorIndexConfig: bqFlatIndexConfig(),
102
+ },
103
+ m2vec_pq_very_long_230_chars: {
104
+ Vectorizer: map[string]interface{}{
105
+ text2vecModel2Vec: map[string]interface{}{
106
+ "vectorizeClassName": false,
107
+ },
108
+ },
109
+ VectorIndexType: "hnsw",
110
+ VectorIndexConfig: pqVectorIndexConfig(),
111
+ },
112
+ transformers: {
113
+ Vectorizer: map[string]interface{}{
114
+ text2vecTransformers: map[string]interface{}{
115
+ "vectorizeClassName": false,
116
+ },
117
+ },
118
+ VectorIndexType: "hnsw",
119
+ },
120
+ transformers_flat: {
121
+ Vectorizer: map[string]interface{}{
122
+ text2vecTransformers: map[string]interface{}{
123
+ "vectorizeClassName": false,
124
+ },
125
+ },
126
+ VectorIndexType: "flat",
127
+ },
128
+ transformers_pq: {
129
+ Vectorizer: map[string]interface{}{
130
+ text2vecTransformers: map[string]interface{}{
131
+ "vectorizeClassName": false,
132
+ },
133
+ },
134
+ VectorIndexType: "hnsw",
135
+ VectorIndexConfig: pqVectorIndexConfig(),
136
+ },
137
+ transformers_bq: {
138
+ Vectorizer: map[string]interface{}{
139
+ text2vecTransformers: map[string]interface{}{
140
+ "vectorizeClassName": false,
141
+ },
142
+ },
143
+ VectorIndexType: "flat",
144
+ VectorIndexConfig: bqFlatIndexConfig(),
145
+ },
146
+ transformers_bq_very_long_230_chars: {
147
+ Vectorizer: map[string]interface{}{
148
+ text2vecTransformers: map[string]interface{}{
149
+ "vectorizeClassName": false,
150
+ },
151
+ },
152
+ VectorIndexType: "flat",
153
+ VectorIndexConfig: bqFlatIndexConfig(),
154
+ },
155
+ },
156
+ }
157
+
158
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
159
+ require.NoError(t, err)
160
+
161
+ cls, err := client.Schema().ClassGetter().WithClassName(className).Do(ctx)
162
+ require.NoError(t, err)
163
+ assert.Equal(t, class.Class, cls.Class)
164
+ require.NotEmpty(t, cls.VectorConfig)
165
+ require.Len(t, cls.VectorConfig, len(targetVectors))
166
+ for _, name := range targetVectors {
167
+ require.NotEmpty(t, cls.VectorConfig[name])
168
+ assert.Equal(t, class.VectorConfig[name].VectorIndexType, cls.VectorConfig[name].VectorIndexType)
169
+ vectorizerConfig, ok := cls.VectorConfig[name].Vectorizer.(map[string]interface{})
170
+ require.True(t, ok)
171
+ vectorizerName := text2vecModel2Vec
172
+ if strings.HasPrefix(name, "transformers") {
173
+ vectorizerName = text2vecTransformers
174
+ }
175
+ require.NotEmpty(t, vectorizerConfig[vectorizerName])
176
+ }
177
+ }
178
+
179
+ func pqVectorIndexConfig() map[string]interface{} {
180
+ efConstruction := 64
181
+ ef := 32
182
+ maxNeighbors := 32
183
+ vectorCacheMaxObjects := 10e12
184
+
185
+ return map[string]interface{}{
186
+ "maxConnections": maxNeighbors,
187
+ "efConstruction": efConstruction,
188
+ "ef": ef,
189
+ "vectorCacheMaxObjects": vectorCacheMaxObjects,
190
+ "distance": "l2-squared",
191
+ "pq": map[string]interface{}{
192
+ "enabled": true,
193
+ "encoder": map[string]interface{}{
194
+ "distribution": hnsw.PQEncoderDistributionNormal,
195
+ "type": hnsw.PQEncoderTypeKMeans,
196
+ },
197
+ },
198
+ }
199
+ }
200
+
201
+ func bqFlatIndexConfig() map[string]interface{} {
202
+ return map[string]interface{}{
203
+ "bq": map[string]interface{}{
204
+ "enabled": true,
205
+ },
206
+ }
207
+ }
208
+
209
+ func sqVectorIndexConfig() map[string]interface{} {
210
+ return map[string]interface{}{
211
+ "sq": map[string]interface{}{
212
+ "enabled": true,
213
+ "rescoreLimit": -1,
214
+ "cache": true,
215
+ },
216
+ }
217
+ }
218
+
219
+ func getVectorsWithNearText(t *testing.T, client *wvt.Client,
220
+ className, id string, nearText *graphql.NearTextArgumentBuilder, targetVectors ...string,
221
+ ) map[string]models.Vector {
222
+ return getVectorsWithNearArgs(t, client, className, id, nearText, nil, nil, nil, false, targetVectors...)
223
+ }
224
+
225
+ func getVectorsWithNearTextWithCertainty(t *testing.T, client *wvt.Client,
226
+ className, id string, nearText *graphql.NearTextArgumentBuilder, targetVectors ...string,
227
+ ) map[string]models.Vector {
228
+ return getVectorsWithNearArgs(t, client, className, id, nearText, nil, nil, nil, true, targetVectors...)
229
+ }
230
+
231
+ func getVectorsWithNearVector(t *testing.T, client *wvt.Client,
232
+ className, id string, nearVector *graphql.NearVectorArgumentBuilder, targetVectors ...string,
233
+ ) map[string]models.Vector {
234
+ return getVectorsWithNearArgs(t, client, className, id, nil, nearVector, nil, nil, false, targetVectors...)
235
+ }
236
+
237
+ func getVectorsWithNearVectorWithCertainty(t *testing.T, client *wvt.Client,
238
+ className, id string, nearVector *graphql.NearVectorArgumentBuilder, targetVectors ...string,
239
+ ) map[string]models.Vector {
240
+ return getVectorsWithNearArgs(t, client, className, id, nil, nearVector, nil, nil, true, targetVectors...)
241
+ }
242
+
243
+ func getVectorsWithNearObjectWithCertainty(t *testing.T, client *wvt.Client,
244
+ className, id string, nearObject *graphql.NearObjectArgumentBuilder, targetVectors ...string,
245
+ ) map[string]models.Vector {
246
+ return getVectorsWithNearArgs(t, client, className, id, nil, nil, nearObject, nil, true, targetVectors...)
247
+ }
248
+
249
+ func getVectorsWithNearArgs(t *testing.T, client *wvt.Client,
250
+ className, id string,
251
+ nearText *graphql.NearTextArgumentBuilder,
252
+ nearVector *graphql.NearVectorArgumentBuilder,
253
+ nearObject *graphql.NearObjectArgumentBuilder,
254
+ hybrid *graphql.HybridArgumentBuilder,
255
+ withCertainty bool,
256
+ targetVectors ...string,
257
+ ) map[string]models.Vector {
258
+ where := filters.Where().
259
+ WithPath([]string{"id"}).
260
+ WithOperator(filters.Equal).
261
+ WithValueText(id)
262
+ field := graphql.Field{
263
+ Name: "_additional",
264
+ Fields: []graphql.Field{
265
+ {Name: "id"},
266
+ },
267
+ }
268
+
269
+ var (
270
+ requireLegacyVector bool
271
+ filteredTargetVectors []string
272
+ )
273
+ for _, targetVector := range targetVectors {
274
+ if targetVector == "" {
275
+ requireLegacyVector = true
276
+ } else {
277
+ filteredTargetVectors = append(filteredTargetVectors, targetVector)
278
+ }
279
+ }
280
+
281
+ if requireLegacyVector {
282
+ field.Fields = append(field.Fields, graphql.Field{Name: "vector"})
283
+ }
284
+
285
+ if len(filteredTargetVectors) > 0 {
286
+ vectors := fmt.Sprintf("vectors{%s}", strings.Join(filteredTargetVectors, " "))
287
+ field.Fields = append(field.Fields, graphql.Field{Name: vectors})
288
+ }
289
+
290
+ if withCertainty {
291
+ field.Fields = append(field.Fields, graphql.Field{Name: "certainty"})
292
+ }
293
+ get := client.GraphQL().Get().
294
+ WithClassName(className).
295
+ WithWhere(where).
296
+ WithNearText(nearText).
297
+ WithFields(field)
298
+
299
+ if nearText != nil {
300
+ get = get.WithNearText(nearText)
301
+ }
302
+ if nearVector != nil {
303
+ get = get.WithNearVector(nearVector)
304
+ }
305
+ if nearObject != nil {
306
+ get = get.WithNearObject(nearObject)
307
+ }
308
+ if hybrid != nil {
309
+ get = get.WithHybrid(hybrid)
310
+ }
311
+
312
+ var resp *models.GraphQLResponse
313
+ var err error
314
+
315
+ require.EventuallyWithT(t, func(ct *assert.CollectT) {
316
+ resp, err = get.Do(context.Background())
317
+ require.NoError(t, err)
318
+ require.NotNil(t, resp)
319
+ if len(resp.Data) == 0 {
320
+ return
321
+ }
322
+
323
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
324
+ assert.Contains(ct, ids, id)
325
+ }, 5*time.Second, 1*time.Millisecond)
326
+
327
+ return acceptance_with_go_client.GetVectors(t, resp, className, withCertainty, targetVectors...)
328
+ }
329
+
330
+ func getVectors(t *testing.T, client *wvt.Client,
331
+ className, id string, targetVectors ...string,
332
+ ) map[string]models.Vector {
333
+ return getVectorsWithNearText(t, client, className, id, nil, targetVectors...)
334
+ }
335
+
336
+ func checkTargetVectors(t *testing.T, resultVectors map[string]models.Vector) {
337
+ require.NotEmpty(t, resultVectors[m2vec])
338
+ require.NotEmpty(t, resultVectors[m2vec_flat])
339
+ require.NotEmpty(t, resultVectors[m2vec_pq])
340
+ require.NotEmpty(t, resultVectors[m2vec_bq])
341
+ require.NotEmpty(t, resultVectors[transformers])
342
+ require.NotEmpty(t, resultVectors[transformers_flat])
343
+ require.NotEmpty(t, resultVectors[transformers_pq])
344
+ require.NotEmpty(t, resultVectors[transformers_bq])
345
+ assert.Equal(t, resultVectors[m2vec], resultVectors[m2vec_flat])
346
+ assert.Equal(t, resultVectors[m2vec_flat], resultVectors[m2vec_pq])
347
+ assert.Equal(t, resultVectors[m2vec_pq], resultVectors[m2vec_bq])
348
+ assert.Equal(t, resultVectors[transformers], resultVectors[transformers_flat])
349
+ assert.Equal(t, resultVectors[transformers_flat], resultVectors[transformers_pq])
350
+ assert.Equal(t, resultVectors[transformers_pq], resultVectors[transformers_bq])
351
+ assert.NotEqual(t, resultVectors[m2vec], resultVectors[transformers])
352
+ assert.NotEqual(t, resultVectors[m2vec_flat], resultVectors[transformers_flat])
353
+ assert.NotEqual(t, resultVectors[m2vec_pq], resultVectors[transformers_pq])
354
+ assert.NotEqual(t, resultVectors[m2vec_bq], resultVectors[transformers_bq])
355
+ }
356
+
357
+ func testAllObjectsIndexed(t *testing.T, client *wvt.Client, className string) {
358
+ // wait for all of the objects to get indexed
359
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
360
+ resp, err := client.Cluster().NodesStatusGetter().
361
+ WithClass(className).
362
+ WithOutput("verbose").
363
+ Do(context.Background())
364
+ require.NoError(ct, err)
365
+ require.NotEmpty(ct, resp.Nodes)
366
+ for _, n := range resp.Nodes {
367
+ require.NotEmpty(ct, n.Shards)
368
+ for _, s := range n.Shards {
369
+ assert.Equal(ct, "READY", s.VectorIndexingStatus)
370
+ }
371
+ }
372
+ }, 30*time.Second, 500*time.Millisecond)
373
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/named_vectors_tests/test_suits/named_vectors_vector_index_types.go ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package test_suits
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/stretchr/testify/assert"
22
+ "github.com/stretchr/testify/require"
23
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
24
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ "github.com/weaviate/weaviate/entities/schema"
27
+ )
28
+
29
+ func testVectorIndexTypesConfigurations(host string) func(t *testing.T) {
30
+ return func(t *testing.T) {
31
+ ctx := context.Background()
32
+ vectorIndexTypeClassName := "NamedVectorsWithVectorIndexType"
33
+ vectorIndexTargetVectors := []string{"description"}
34
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
35
+ require.Nil(t, err)
36
+
37
+ cleanup := func() {
38
+ err := client.Schema().AllDeleter().Do(context.Background())
39
+ require.Nil(t, err)
40
+ }
41
+
42
+ idsToDelete := []string{id1, id2}
43
+ hasBeenDeleted := func(id string) bool {
44
+ for _, deletedId := range idsToDelete {
45
+ if deletedId == id {
46
+ return true
47
+ }
48
+ }
49
+ return false
50
+ }
51
+
52
+ tests := []struct {
53
+ name string
54
+ vectorIndexType string
55
+ vectorIndexConfig map[string]interface{}
56
+ }{
57
+ {
58
+ name: "flat",
59
+ vectorIndexType: "flat",
60
+ vectorIndexConfig: nil,
61
+ },
62
+ {
63
+ name: "flat_bq",
64
+ vectorIndexType: "flat",
65
+ vectorIndexConfig: bqFlatIndexConfig(),
66
+ },
67
+ {
68
+ name: "hnsw",
69
+ vectorIndexType: "hnsw",
70
+ vectorIndexConfig: nil,
71
+ },
72
+ {
73
+ name: "hnsw_pq",
74
+ vectorIndexType: "hnsw",
75
+ vectorIndexConfig: pqVectorIndexConfig(),
76
+ },
77
+ {
78
+ name: "hnsw_sq",
79
+ vectorIndexType: "hnsw",
80
+ vectorIndexConfig: sqVectorIndexConfig(),
81
+ },
82
+ {
83
+ name: "hnsw_bq",
84
+ vectorIndexType: "hnsw",
85
+ vectorIndexConfig: bqFlatIndexConfig(),
86
+ },
87
+ }
88
+ for _, tt := range tests {
89
+ t.Run(tt.name, func(t *testing.T) {
90
+ cleanup()
91
+
92
+ t.Run("create schema", func(t *testing.T) {
93
+ ctx := context.Background()
94
+ class := &models.Class{
95
+ Class: vectorIndexTypeClassName,
96
+ Properties: []*models.Property{
97
+ {
98
+ Name: "author", DataType: []string{schema.DataTypeText.String()},
99
+ },
100
+ {
101
+ Name: "title", DataType: []string{schema.DataTypeText.String()},
102
+ },
103
+ {
104
+ Name: "description", DataType: []string{schema.DataTypeText.String()},
105
+ },
106
+ {
107
+ Name: "genre", DataType: []string{schema.DataTypeText.String()},
108
+ },
109
+ },
110
+ VectorConfig: map[string]models.VectorConfig{
111
+ vectorIndexTargetVectors[0]: {
112
+ Vectorizer: map[string]interface{}{
113
+ text2vecTransformers: map[string]interface{}{
114
+ "vectorizeClassName": false,
115
+ "properties": []interface{}{"description"},
116
+ },
117
+ },
118
+ VectorIndexType: tt.vectorIndexType,
119
+ VectorIndexConfig: tt.vectorIndexConfig,
120
+ },
121
+ },
122
+ }
123
+
124
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
125
+ require.NoError(t, err)
126
+
127
+ cls, err := client.Schema().ClassGetter().WithClassName(vectorIndexTypeClassName).Do(ctx)
128
+ require.NoError(t, err)
129
+ assert.Equal(t, class.Class, cls.Class)
130
+ require.NotEmpty(t, cls.VectorConfig)
131
+ require.Len(t, cls.VectorConfig, len(vectorIndexTargetVectors))
132
+ for _, name := range vectorIndexTargetVectors {
133
+ require.NotEmpty(t, cls.VectorConfig[name])
134
+ assert.Equal(t, class.VectorConfig[name].VectorIndexType, cls.VectorConfig[name].VectorIndexType)
135
+ vectorizerConfig, ok := cls.VectorConfig[name].Vectorizer.(map[string]interface{})
136
+ require.True(t, ok)
137
+ require.NotEmpty(t, vectorizerConfig[text2vecTransformers])
138
+ }
139
+ })
140
+
141
+ t.Run("batch create objects", func(t *testing.T) {
142
+ objs := []*models.Object{}
143
+ for id, book := range fixtures.Books() {
144
+ obj := &models.Object{
145
+ Class: vectorIndexTypeClassName,
146
+ ID: strfmt.UUID(id),
147
+ Properties: map[string]interface{}{
148
+ "author": book.Author,
149
+ "title": book.Title,
150
+ "description": book.Description,
151
+ "genre": book.Genre,
152
+ },
153
+ }
154
+ objs = append(objs, obj)
155
+ }
156
+
157
+ resp, err := client.Batch().ObjectsBatcher().
158
+ WithObjects(objs...).
159
+ Do(ctx)
160
+ require.NoError(t, err)
161
+ require.NotNil(t, resp)
162
+ })
163
+
164
+ t.Run("check existence", func(t *testing.T) {
165
+ for id := range fixtures.Books() {
166
+ exists, err := client.Data().Checker().
167
+ WithID(id).
168
+ WithClassName(vectorIndexTypeClassName).
169
+ Do(ctx)
170
+ require.NoError(t, err)
171
+ require.True(t, exists)
172
+ }
173
+ })
174
+
175
+ t.Run("GraphQL get vectors", func(t *testing.T) {
176
+ for id := range fixtures.Books() {
177
+ resultVectors := getVectors(t, client, vectorIndexTypeClassName, id, vectorIndexTargetVectors...)
178
+ require.NotEmpty(t, resultVectors[vectorIndexTargetVectors[0]])
179
+ }
180
+ })
181
+
182
+ t.Run("GraphQL near<Media> check", func(t *testing.T) {
183
+ for id, book := range fixtures.Books() {
184
+ for _, targetVector := range vectorIndexTargetVectors {
185
+ nearText := client.GraphQL().NearTextArgBuilder().
186
+ WithConcepts([]string{book.Title}).
187
+ WithTargetVectors(targetVector)
188
+ resultVectors := getVectorsWithNearText(t, client, vectorIndexTypeClassName, id, nearText, vectorIndexTargetVectors...)
189
+ require.NotEmpty(t, resultVectors[vectorIndexTargetVectors[0]])
190
+ }
191
+ }
192
+ })
193
+
194
+ t.Run("batch delete objects", func(t *testing.T) {
195
+ where := filters.Where().
196
+ WithPath([]string{"id"}).
197
+ WithOperator(filters.ContainsAny).
198
+ WithValueText(idsToDelete...)
199
+ resp, err := client.Batch().ObjectsBatchDeleter().
200
+ WithClassName(vectorIndexTypeClassName).
201
+ WithDryRun(true).
202
+ WithOutput("verbose").
203
+ WithWhere(where).
204
+ Do(ctx)
205
+ require.NoError(t, err)
206
+ require.NotNil(t, resp)
207
+ require.NotNil(t, resp.Results)
208
+ require.Len(t, resp.Results.Objects, 2)
209
+ for _, res := range resp.Results.Objects {
210
+ require.Nil(t, res.Errors)
211
+ require.NotNil(t, res.Status)
212
+ assert.Equal(t, models.BatchDeleteResponseResultsObjectsItems0StatusDRYRUN, *res.Status)
213
+ }
214
+
215
+ resp, err = client.Batch().ObjectsBatchDeleter().
216
+ WithClassName(vectorIndexTypeClassName).
217
+ WithDryRun(false).
218
+ WithOutput("verbose").
219
+ WithWhere(where).
220
+ Do(ctx)
221
+ require.NoError(t, err)
222
+ require.NotNil(t, resp)
223
+ require.NotNil(t, resp.Results)
224
+ require.Len(t, resp.Results.Objects, 2)
225
+ for _, res := range resp.Results.Objects {
226
+ require.Nil(t, res.Errors)
227
+ require.NotNil(t, res.Status)
228
+ assert.Equal(t, models.BatchDeleteResponseResultsObjectsItems0StatusSUCCESS, *res.Status)
229
+ }
230
+
231
+ for id := range fixtures.Books() {
232
+ exists, err := client.Data().Checker().
233
+ WithID(id).
234
+ WithClassName(vectorIndexTypeClassName).
235
+ Do(ctx)
236
+ require.NoError(t, err)
237
+ isDeleted := false
238
+ for _, deletedID := range idsToDelete {
239
+ if id == deletedID {
240
+ isDeleted = true
241
+ break
242
+ }
243
+ }
244
+ require.Equal(t, !isDeleted, exists)
245
+ }
246
+ })
247
+
248
+ t.Run("batch update objects and check if vectors changed", func(t *testing.T) {
249
+ existingIds := []string{}
250
+ for id := range fixtures.Books() {
251
+ if !hasBeenDeleted(id) {
252
+ existingIds = append(existingIds, id)
253
+ }
254
+ }
255
+ beforeUpdateVectorsMap := map[string]map[string][]float32{}
256
+ for _, id := range existingIds {
257
+ beforeUpdateVectors := getVectors(t, client, vectorIndexTypeClassName, id, vectorIndexTargetVectors...)
258
+ require.NotEmpty(t, beforeUpdateVectors[vectorIndexTargetVectors[0]])
259
+ }
260
+
261
+ objs := []*models.Object{}
262
+ for id, book := range fixtures.Books() {
263
+ obj := &models.Object{
264
+ Class: vectorIndexTypeClassName,
265
+ ID: strfmt.UUID(id),
266
+ Properties: map[string]interface{}{
267
+ "description": book.Title,
268
+ },
269
+ }
270
+ objs = append(objs, obj)
271
+ }
272
+ resp, err := client.Batch().ObjectsBatcher().
273
+ WithObjects(objs...).
274
+ Do(ctx)
275
+ require.NoError(t, err)
276
+ require.NotNil(t, resp)
277
+
278
+ for _, id := range existingIds {
279
+ afterUpdateVectors := getVectors(t, client, vectorIndexTypeClassName, id, vectorIndexTargetVectors...)
280
+ require.NotEmpty(t, afterUpdateVectors[vectorIndexTargetVectors[0]])
281
+ beforeUpdateVectors := beforeUpdateVectorsMap[id]
282
+ for _, targetVector := range vectorIndexTargetVectors {
283
+ assert.NotEqual(t, beforeUpdateVectors[targetVector], afterUpdateVectors[targetVector])
284
+ }
285
+ }
286
+ })
287
+ })
288
+ }
289
+ }
290
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/__init__.py ADDED
File without changes
platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/test_multi_tenant.py ADDED
File without changes
platform/dbops/binaries/weaviate-src/test/acceptance_with_python/bench/test_named_vectors.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ import pytest
4
+ from typing_extensions import Any, List
5
+ from weaviate.collections.classes.data import DataObject
6
+
7
+ from ..conftest import NamedCollection
8
+
9
+ # run with
10
+ # pytest test/acceptance_with_python/bench/test_named_vectors.py --benchmark-only --benchmark-disable-gc
11
+
12
+
13
+ def compute_vectors():
14
+ # seed with same number to keep reproducible - this is only used to shuffle vectors
15
+ random.seed(4)
16
+ base_vector = [0.01 * i for i in range(100)]
17
+
18
+ def shuffle(input: List[float]) -> List[float]:
19
+ random.shuffle(input)
20
+ return input
21
+
22
+ return [shuffle(base_vector) for _ in range(1500)]
23
+
24
+
25
+ # precompute outside of benchmark so that this does not change the measured times
26
+
27
+ INPUT_VECTORS = compute_vectors()
28
+
29
+
30
+ def named_vectors(named_collection: NamedCollection, num_targets: int) -> None:
31
+ collection = named_collection()
32
+ target_vectors = ["All", "title1", "title2"]
33
+
34
+ num_objects = 100
35
+ ret = collection.data.insert_many(
36
+ [
37
+ DataObject(
38
+ vector={
39
+ "All": INPUT_VECTORS[i * 3],
40
+ "title1": INPUT_VECTORS[i * 3 + 1],
41
+ "title2": INPUT_VECTORS[i * 3 + 2],
42
+ }
43
+ )
44
+ for i in range(num_objects)
45
+ ]
46
+ )
47
+ assert not ret.has_errors
48
+
49
+ query_vecs = INPUT_VECTORS[num_objects * 3 :]
50
+ for j in range(len(query_vecs)):
51
+ collection.query.near_vector(query_vecs[j], target_vector=target_vectors[:num_targets])
52
+
53
+
54
+ @pytest.mark.parametrize("num_targets", [1, 2, 3])
55
+ def test_benchmark_named_vectors(
56
+ benchmark: Any, named_collection: NamedCollection, num_targets: int
57
+ ) -> None:
58
+ benchmark(named_vectors, named_collection, num_targets)
platform/dbops/binaries/weaviate-src/test/acceptance_with_python/rbac/__init__.py ADDED
File without changes