github.com/weaviate/weaviate@v1.24.6/test/acceptance/objects/custom_vectors.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package test 13 14 import ( 15 "testing" 16 17 "github.com/davecgh/go-spew/spew" 18 "github.com/go-openapi/strfmt" 19 "github.com/stretchr/testify/assert" 20 "github.com/stretchr/testify/require" 21 "github.com/weaviate/weaviate/client/objects" 22 "github.com/weaviate/weaviate/entities/models" 23 "github.com/weaviate/weaviate/test/helper" 24 ) 25 26 func customVectors(t *testing.T) { 27 var id strfmt.UUID 28 29 t.Run("create object", func(t *testing.T) { 30 params := objects.NewObjectsCreateParams().WithBody( 31 &models.Object{ 32 Class: "TestObjectCustomVector", 33 Properties: map[string]interface{}{"description": "foo"}, 34 Vector: []float32{0.1, 0.2}, 35 }) 36 resp, err := helper.Client(t).Objects.ObjectsCreate(params, nil) 37 require.Nil(t, err, "creation should succeed") 38 id = resp.Payload.ID 39 }) 40 41 t.Run("check custom vector is set", func(t *testing.T) { 42 include := "vector" 43 params := objects.NewObjectsGetParams().WithID(id).WithInclude(&include) 44 resp, err := helper.Client(t).Objects.ObjectsGet(params, nil) 45 require.Nil(t, err, "get should succeed") 46 assert.Equal(t, []float32{0.1, 0.2}, []float32(resp.Payload.Vector)) 47 }) 48 49 t.Run("replace object entirely (update)", func(t *testing.T) { 50 params := objects.NewObjectsUpdateParams().WithID(id).WithBody(&models.Object{ 51 ID: id, 52 Class: "TestObjectCustomVector", 53 Properties: map[string]interface{}{"description": "foo updated"}, 54 Vector: []float32{0.1, 0.3}, 55 }) 56 _, err := helper.Client(t).Objects.ObjectsUpdate(params, nil) 57 require.Nil(t, err, "update should succeed") 58 }) 59 60 t.Run("check custom vector is updated", func(t *testing.T) { 61 include := "vector" 62 params := objects.NewObjectsGetParams().WithID(id).WithInclude(&include) 63 resp, err := helper.Client(t).Objects.ObjectsGet(params, nil) 64 require.Nil(t, err, "get should succeed") 65 assert.Equal(t, []float32{0.1, 0.3}, []float32(resp.Payload.Vector)) 66 }) 67 68 t.Run("replace only vector through merge", func(t *testing.T) { 69 params := objects.NewObjectsPatchParams().WithID(id).WithBody(&models.Object{ 70 ID: id, 71 Class: "TestObjectCustomVector", 72 Properties: map[string]interface{}{}, 73 Vector: []float32{0.4, 0.3}, 74 }) 75 _, err := helper.Client(t).Objects.ObjectsPatch(params, nil) 76 if err != nil { 77 spew.Dump(err.(*objects.ObjectsPatchInternalServerError).Payload.Error[0]) 78 } 79 require.Nil(t, err, "patch should succeed") 80 }) 81 82 t.Run("check custom vector is updated", func(t *testing.T) { 83 include := "vector" 84 params := objects.NewObjectsGetParams().WithID(id).WithInclude(&include) 85 resp, err := helper.Client(t).Objects.ObjectsGet(params, nil) 86 require.Nil(t, err, "get should succeed") 87 assert.Equal(t, []float32{0.4, 0.3}, []float32(resp.Payload.Vector)) 88 }) 89 }