Add files using upload-large-folder tool
Browse files- platform/dbops/binaries/weaviate-src/test/modules/generative-aws/setup_test.go +72 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-cohere/generative_cohere_test.go +134 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-cohere/setup_test.go +53 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-friendliai/generative_friendliai_test.go +94 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-friendliai/setup_test.go +52 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-google/generative_google_test.go +210 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-google/setup_test.go +59 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-nvidia/generative_nvidia_test.go +121 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-nvidia/setup_test.go +53 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-ollama/generative_ollama_test.go +111 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-ollama/setup_test.go +50 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-openai/generative_openai_test.go +216 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-openai/setup_test.go +58 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-xai/generative_xai_test.go +195 -0
- platform/dbops/binaries/weaviate-src/test/modules/generative-xai/setup_test.go +54 -0
- platform/dbops/binaries/weaviate-src/test/modules/img2vec-neural/neural_test.go +103 -0
- platform/dbops/binaries/weaviate-src/test/modules/img2vec-neural/setup_test.go +44 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-generative/many_generative_test.go +101 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-generative/setup_test.go +100 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-modules/api_based_modules_sanity_test.go +50 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-modules/many_modules_openai_test.go +143 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-modules/many_modules_sanity_test.go +198 -0
- platform/dbops/binaries/weaviate-src/test/modules/many-modules/setup_test.go +101 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2multivec-jinaai/multi2multivec_jinaai_test.go +85 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2multivec-jinaai/setup_test.go +40 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-bind/bind_test.go +84 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-bind/setup_test.go +43 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-clip/multi2vec_clip_test.go +89 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-clip/setup_test.go +35 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-cohere/multi2vec_cohere_test.go +86 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-cohere/setup_test.go +51 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-google/multi2vec_google_test.go +154 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-google/setup_test.go +60 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-jinaai/multi2vec_jinaai_test.go +124 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-jinaai/setup_test.go +43 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-nvidia/multi2vec_nvidia_test.go +86 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-nvidia/setup_test.go +51 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-voyageai/multi2vec_voyageai_test.go +86 -0
- platform/dbops/binaries/weaviate-src/test/modules/multi2vec-voyageai/setup_test.go +51 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/misocnfigured_test.go +197 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offlad_delete_test.go +409 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_bucket_test.go +201 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_download_test.go +354 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_not_enabled_test.go +116 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_test.go +618 -0
- platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_upload_test.go +475 -0
- platform/dbops/binaries/weaviate-src/test/modules/qna-transformers/qna_test.go +107 -0
- platform/dbops/binaries/weaviate-src/test/modules/qna-transformers/setup_test.go +45 -0
- platform/dbops/binaries/weaviate-src/test/modules/ref2vec-centroid/centroid_test.go +212 -0
- platform/dbops/binaries/weaviate-src/test/modules/ref2vec-centroid/setup_test.go +42 -0
platform/dbops/binaries/weaviate-src/test/modules/generative-aws/setup_test.go
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeAWS_SingleNode(t *testing.T) {
|
| 24 |
+
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
| 25 |
+
if accessKey == "" {
|
| 26 |
+
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
| 27 |
+
if accessKey == "" {
|
| 28 |
+
t.Skip("skipping, AWS_ACCESS_KEY environment variable not present")
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
secretKey := os.Getenv("AWS_SECRET_KEY")
|
| 32 |
+
if secretKey == "" {
|
| 33 |
+
secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
| 34 |
+
if secretKey == "" {
|
| 35 |
+
t.Skip("skipping, AWS_SECRET_KEY environment variable not present")
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
|
| 39 |
+
if sessionToken == "" {
|
| 40 |
+
t.Skip("skipping, AWS_SESSION_TOKEN environment variable not present")
|
| 41 |
+
}
|
| 42 |
+
region := os.Getenv("AWS_REGION")
|
| 43 |
+
if region == "" {
|
| 44 |
+
t.Skip("skipping, AWS_REGION environment variable not present")
|
| 45 |
+
}
|
| 46 |
+
ctx := context.Background()
|
| 47 |
+
compose, err := createSingleNodeEnvironment(ctx, accessKey, secretKey, sessionToken)
|
| 48 |
+
require.NoError(t, err)
|
| 49 |
+
defer func() {
|
| 50 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 51 |
+
}()
|
| 52 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 53 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 54 |
+
|
| 55 |
+
t.Run("tests", testGenerativeAWS(endpointREST, endpointGRPC, region))
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func createSingleNodeEnvironment(ctx context.Context, accessKey, secretKey, sessionToken string,
|
| 59 |
+
) (compose *docker.DockerCompose, err error) {
|
| 60 |
+
compose, err = composeModules(accessKey, secretKey, sessionToken).
|
| 61 |
+
WithWeaviateWithGRPC().
|
| 62 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "120s").
|
| 63 |
+
Start(ctx)
|
| 64 |
+
return
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
func composeModules(accessKey, secretKey, sessionToken string) (composeModules *docker.Compose) {
|
| 68 |
+
composeModules = docker.New().
|
| 69 |
+
WithText2VecAWS(accessKey, secretKey, sessionToken).
|
| 70 |
+
WithGenerativeAWS(accessKey, secretKey, sessionToken)
|
| 71 |
+
return
|
| 72 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-cohere/generative_cohere_test.go
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
"time"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/assert"
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 22 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 24 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 25 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
func testGenerativeCohere(rest, grpc string) func(t *testing.T) {
|
| 29 |
+
return func(t *testing.T) {
|
| 30 |
+
helper.SetupClient(rest)
|
| 31 |
+
helper.SetupGRPCClient(t, grpc)
|
| 32 |
+
// Data
|
| 33 |
+
data := planets.Planets
|
| 34 |
+
// Define class
|
| 35 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 36 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 37 |
+
"description": {
|
| 38 |
+
Vectorizer: map[string]interface{}{
|
| 39 |
+
"text2vec-transformers": map[string]interface{}{
|
| 40 |
+
"properties": []interface{}{"description"},
|
| 41 |
+
"vectorizeClassName": false,
|
| 42 |
+
},
|
| 43 |
+
},
|
| 44 |
+
VectorIndexType: "flat",
|
| 45 |
+
},
|
| 46 |
+
}
|
| 47 |
+
tests := []struct {
|
| 48 |
+
name string
|
| 49 |
+
generativeModel string
|
| 50 |
+
absentModuleConfig bool
|
| 51 |
+
}{
|
| 52 |
+
{
|
| 53 |
+
name: "command-r-plus",
|
| 54 |
+
generativeModel: "command-r-plus",
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
name: "command-r",
|
| 58 |
+
generativeModel: "command-r",
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
name: "absent module config",
|
| 62 |
+
generativeModel: "command-r",
|
| 63 |
+
absentModuleConfig: true,
|
| 64 |
+
},
|
| 65 |
+
}
|
| 66 |
+
for idx, tt := range tests {
|
| 67 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 68 |
+
if tt.absentModuleConfig {
|
| 69 |
+
t.Log("skipping adding module config configuration to class")
|
| 70 |
+
} else {
|
| 71 |
+
class.ModuleConfig = map[string]interface{}{
|
| 72 |
+
"generative-cohere": map[string]interface{}{
|
| 73 |
+
"model": tt.generativeModel,
|
| 74 |
+
},
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
// create schema
|
| 78 |
+
helper.CreateClass(t, class)
|
| 79 |
+
defer helper.DeleteClass(t, class.Class)
|
| 80 |
+
// create objects
|
| 81 |
+
t.Run("create objects", func(t *testing.T) {
|
| 82 |
+
planets.InsertObjects(t, class.Class)
|
| 83 |
+
})
|
| 84 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 85 |
+
for _, planet := range data {
|
| 86 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 87 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 88 |
+
require.NoError(t, err)
|
| 89 |
+
require.NotNil(t, obj)
|
| 90 |
+
require.Len(t, obj.Vectors, 1)
|
| 91 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 92 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 93 |
+
})
|
| 94 |
+
}
|
| 95 |
+
})
|
| 96 |
+
// generative task
|
| 97 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 98 |
+
planets.CreateTweetTest(t, class.Class)
|
| 99 |
+
})
|
| 100 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 101 |
+
params := "cohere:{temperature:0.9 k:400}"
|
| 102 |
+
if tt.absentModuleConfig {
|
| 103 |
+
params = fmt.Sprintf("cohere:{temperature:0.9 k:400 model:\"%s\" baseURL:\"https://api.cohere.ai\"}", tt.generativeModel)
|
| 104 |
+
}
|
| 105 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 106 |
+
})
|
| 107 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 108 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 109 |
+
})
|
| 110 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 111 |
+
cohere := &pb.GenerativeCohere{
|
| 112 |
+
MaxTokens: grpchelper.ToPtr(int64(90)),
|
| 113 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 114 |
+
Temperature: grpchelper.ToPtr(0.9),
|
| 115 |
+
K: grpchelper.ToPtr(int64(90)),
|
| 116 |
+
P: grpchelper.ToPtr(0.9),
|
| 117 |
+
StopSequences: &pb.TextArray{Values: []string{"stop"}},
|
| 118 |
+
FrequencyPenalty: grpchelper.ToPtr(0.9),
|
| 119 |
+
}
|
| 120 |
+
if tt.absentModuleConfig {
|
| 121 |
+
cohere.BaseUrl = grpchelper.ToPtr("https://api.cohere.ai")
|
| 122 |
+
}
|
| 123 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 124 |
+
ReturnMetadata: true,
|
| 125 |
+
Kind: &pb.GenerativeProvider_Cohere{Cohere: cohere},
|
| 126 |
+
})
|
| 127 |
+
})
|
| 128 |
+
})
|
| 129 |
+
if idx+1 < len(tests) {
|
| 130 |
+
time.Sleep(60 * time.Second) // sleep to avoid rate limit on cohere api
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-cohere/setup_test.go
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeCohere_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("COHERE_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, COHERE_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 35 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 36 |
+
|
| 37 |
+
t.Run("tests", testGenerativeCohere(endpointREST, endpointGRPC))
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 41 |
+
) (compose *docker.DockerCompose, err error) {
|
| 42 |
+
compose, err = composeModules(apiKey).
|
| 43 |
+
WithWeaviateWithGRPC().
|
| 44 |
+
Start(ctx)
|
| 45 |
+
return
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 49 |
+
composeModules = docker.New().
|
| 50 |
+
WithText2VecTransformers().
|
| 51 |
+
WithGenerativeCohere(apiKey)
|
| 52 |
+
return
|
| 53 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-friendliai/generative_friendliai_test.go
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 generative_friendliai_tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
|
| 17 |
+
"github.com/stretchr/testify/assert"
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testGenerativeFriendliAI(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Data
|
| 28 |
+
data := planets.Planets
|
| 29 |
+
// Define class
|
| 30 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 31 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 32 |
+
"description": {
|
| 33 |
+
Vectorizer: map[string]interface{}{
|
| 34 |
+
"text2vec-transformers": map[string]interface{}{
|
| 35 |
+
"properties": []interface{}{"description"},
|
| 36 |
+
"vectorizeClassName": false,
|
| 37 |
+
},
|
| 38 |
+
},
|
| 39 |
+
VectorIndexType: "flat",
|
| 40 |
+
},
|
| 41 |
+
}
|
| 42 |
+
tests := []struct {
|
| 43 |
+
name string
|
| 44 |
+
generativeModel string
|
| 45 |
+
headerURL string
|
| 46 |
+
}{
|
| 47 |
+
{
|
| 48 |
+
name: "mixtral-8x7b-instruct-v0-1",
|
| 49 |
+
generativeModel: "mixtral-8x7b-instruct-v0-1",
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
name: "meta-llama-3.1-8b-instruct",
|
| 53 |
+
generativeModel: "meta-llama-3.1-8b-instruct",
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
name: "meta-llama-3.1-70b-instruct",
|
| 57 |
+
generativeModel: "meta-llama-3.1-70b-instruct",
|
| 58 |
+
},
|
| 59 |
+
}
|
| 60 |
+
for _, tt := range tests {
|
| 61 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 62 |
+
class.ModuleConfig = map[string]interface{}{
|
| 63 |
+
"generative-friendliai": map[string]interface{}{
|
| 64 |
+
"model": tt.generativeModel,
|
| 65 |
+
"X-Friendli-Baseurl": tt.headerURL,
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
// create schema
|
| 69 |
+
helper.CreateClass(t, class)
|
| 70 |
+
defer helper.DeleteClass(t, class.Class)
|
| 71 |
+
// create objects
|
| 72 |
+
t.Run("create objects", func(t *testing.T) {
|
| 73 |
+
planets.InsertObjects(t, class.Class)
|
| 74 |
+
})
|
| 75 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 76 |
+
for _, planet := range data {
|
| 77 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 78 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 79 |
+
require.NoError(t, err)
|
| 80 |
+
require.NotNil(t, obj)
|
| 81 |
+
require.Len(t, obj.Vectors, 1)
|
| 82 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 83 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 84 |
+
})
|
| 85 |
+
}
|
| 86 |
+
})
|
| 87 |
+
// generative task
|
| 88 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 89 |
+
planets.CreateTweetTest(t, class.Class)
|
| 90 |
+
})
|
| 91 |
+
})
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-friendliai/setup_test.go
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 generative_friendliai_tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeFriendliAI_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("FRIENDLI_TOKEN")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, FRIENDLI_TOKEN environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpoint := compose.GetWeaviate().URI()
|
| 35 |
+
|
| 36 |
+
t.Run("tests", testGenerativeFriendliAI(endpoint))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 40 |
+
) (compose *docker.DockerCompose, err error) {
|
| 41 |
+
compose, err = composeModules(apiKey).
|
| 42 |
+
WithWeaviate().
|
| 43 |
+
Start(ctx)
|
| 44 |
+
return
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 48 |
+
composeModules = docker.New().
|
| 49 |
+
WithText2VecTransformers().
|
| 50 |
+
WithGenerativeFriendliAI(apiKey)
|
| 51 |
+
return
|
| 52 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-google/generative_google_test.go
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/assert"
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func testGenerativeGoogle(rest, grpc, gcpProject, generativeGoogle string) func(t *testing.T) {
|
| 28 |
+
return func(t *testing.T) {
|
| 29 |
+
helper.SetupClient(rest)
|
| 30 |
+
helper.SetupGRPCClient(t, grpc)
|
| 31 |
+
// Define path to test/helper/sample-schema/planets/data folder
|
| 32 |
+
dataFolderPath := "../../../test/helper/sample-schema/planets/data"
|
| 33 |
+
// Data
|
| 34 |
+
data := planets.Planets
|
| 35 |
+
// Define class
|
| 36 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 37 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 38 |
+
"description": {
|
| 39 |
+
Vectorizer: map[string]interface{}{
|
| 40 |
+
"text2vec-google": map[string]interface{}{
|
| 41 |
+
"properties": []interface{}{"description"},
|
| 42 |
+
"vectorizeClassName": false,
|
| 43 |
+
"projectId": gcpProject,
|
| 44 |
+
"modelId": "text-embedding-005",
|
| 45 |
+
},
|
| 46 |
+
},
|
| 47 |
+
VectorIndexType: "flat",
|
| 48 |
+
},
|
| 49 |
+
}
|
| 50 |
+
tests := []struct {
|
| 51 |
+
name string
|
| 52 |
+
generativeModel string
|
| 53 |
+
frequencyPenalty *float64
|
| 54 |
+
presencePenalty *float64
|
| 55 |
+
absentModuleConfig bool
|
| 56 |
+
withImages bool
|
| 57 |
+
}{
|
| 58 |
+
{
|
| 59 |
+
name: "gemini-2.0-flash-lite-001",
|
| 60 |
+
generativeModel: "gemini-2.0-flash-lite-001",
|
| 61 |
+
frequencyPenalty: grpchelper.ToPtr(0.5),
|
| 62 |
+
presencePenalty: grpchelper.ToPtr(0.5),
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
name: "gemini-2.0-flash-001",
|
| 66 |
+
generativeModel: "gemini-2.0-flash-001",
|
| 67 |
+
frequencyPenalty: grpchelper.ToPtr(0.5),
|
| 68 |
+
presencePenalty: grpchelper.ToPtr(0.5),
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
name: "absent module config",
|
| 72 |
+
generativeModel: "gemini-2.0-flash-lite-001",
|
| 73 |
+
absentModuleConfig: true,
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
name: "gemini-2.0-flash-001",
|
| 77 |
+
generativeModel: "gemini-2.0-flash-001",
|
| 78 |
+
withImages: true,
|
| 79 |
+
},
|
| 80 |
+
}
|
| 81 |
+
for _, tt := range tests {
|
| 82 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 83 |
+
if tt.absentModuleConfig {
|
| 84 |
+
t.Log("skipping adding module config configuration to class")
|
| 85 |
+
} else {
|
| 86 |
+
class.ModuleConfig = map[string]interface{}{
|
| 87 |
+
generativeGoogle: map[string]interface{}{
|
| 88 |
+
"projectId": gcpProject,
|
| 89 |
+
"modelId": tt.generativeModel,
|
| 90 |
+
},
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
// create schema
|
| 94 |
+
helper.CreateClass(t, class)
|
| 95 |
+
defer helper.DeleteClass(t, class.Class)
|
| 96 |
+
// create objects
|
| 97 |
+
t.Run("create objects", func(t *testing.T) {
|
| 98 |
+
if tt.withImages {
|
| 99 |
+
planets.InsertObjectsWithImages(t, class.Class, dataFolderPath)
|
| 100 |
+
} else {
|
| 101 |
+
planets.InsertObjects(t, class.Class)
|
| 102 |
+
}
|
| 103 |
+
})
|
| 104 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 105 |
+
for _, company := range data {
|
| 106 |
+
t.Run(company.ID.String(), func(t *testing.T) {
|
| 107 |
+
obj, err := helper.GetObject(t, class.Class, company.ID, "vector")
|
| 108 |
+
require.NoError(t, err)
|
| 109 |
+
require.NotNil(t, obj)
|
| 110 |
+
require.Len(t, obj.Vectors, 1)
|
| 111 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 112 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 113 |
+
})
|
| 114 |
+
}
|
| 115 |
+
})
|
| 116 |
+
// generative task
|
| 117 |
+
if tt.absentModuleConfig {
|
| 118 |
+
t.Log("skipping create tweet tests with default values as e2e tests rely on specific GCP settings")
|
| 119 |
+
} else {
|
| 120 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 121 |
+
planets.CreateTweetTest(t, class.Class)
|
| 122 |
+
})
|
| 123 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 124 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 125 |
+
})
|
| 126 |
+
}
|
| 127 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 128 |
+
params := "google:{topP:0.1 topK:40}"
|
| 129 |
+
if tt.absentModuleConfig {
|
| 130 |
+
params = fmt.Sprintf("google:{topP:0.1 topK:40 projectId:%q model:%q}", gcpProject, tt.generativeModel)
|
| 131 |
+
}
|
| 132 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 133 |
+
})
|
| 134 |
+
|
| 135 |
+
params := func() *pb.GenerativeGoogle {
|
| 136 |
+
params := &pb.GenerativeGoogle{
|
| 137 |
+
MaxTokens: grpchelper.ToPtr(int64(256)),
|
| 138 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 139 |
+
Temperature: grpchelper.ToPtr(0.5),
|
| 140 |
+
TopK: grpchelper.ToPtr(int64(40)),
|
| 141 |
+
TopP: grpchelper.ToPtr(0.1),
|
| 142 |
+
FrequencyPenalty: tt.frequencyPenalty,
|
| 143 |
+
PresencePenalty: tt.presencePenalty,
|
| 144 |
+
}
|
| 145 |
+
if tt.absentModuleConfig {
|
| 146 |
+
params.ProjectId = &gcpProject
|
| 147 |
+
}
|
| 148 |
+
return params
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 152 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 153 |
+
ReturnMetadata: true,
|
| 154 |
+
Kind: &pb.GenerativeProvider_Google{Google: params()},
|
| 155 |
+
})
|
| 156 |
+
})
|
| 157 |
+
if tt.withImages {
|
| 158 |
+
t.Run("image prompt", func(t *testing.T) {
|
| 159 |
+
t.Run("graphql", func(t *testing.T) {
|
| 160 |
+
prompt := "Caption image"
|
| 161 |
+
params := "google:{imageProperties:\"image\"}"
|
| 162 |
+
planets.CreatePromptTestWithParams(t, class.Class, prompt, params)
|
| 163 |
+
})
|
| 164 |
+
|
| 165 |
+
singlePrompt := "Give a short answer: What's on the image?"
|
| 166 |
+
groupPrompt := "Give a short answer: What are on the following images?"
|
| 167 |
+
|
| 168 |
+
t.Run("grpc server stored images", func(t *testing.T) {
|
| 169 |
+
params := params()
|
| 170 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 171 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 172 |
+
ReturnMetadata: true,
|
| 173 |
+
Kind: &pb.GenerativeProvider_Google{Google: params},
|
| 174 |
+
})
|
| 175 |
+
})
|
| 176 |
+
|
| 177 |
+
t.Run("grpc user provided images", func(t *testing.T) {
|
| 178 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 179 |
+
require.NoError(t, err)
|
| 180 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 181 |
+
require.NoError(t, err)
|
| 182 |
+
|
| 183 |
+
params := params()
|
| 184 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 185 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 186 |
+
ReturnMetadata: true,
|
| 187 |
+
Kind: &pb.GenerativeProvider_Google{Google: params},
|
| 188 |
+
})
|
| 189 |
+
})
|
| 190 |
+
|
| 191 |
+
t.Run("grpc mixed images", func(t *testing.T) {
|
| 192 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 193 |
+
require.NoError(t, err)
|
| 194 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 195 |
+
require.NoError(t, err)
|
| 196 |
+
|
| 197 |
+
params := params()
|
| 198 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 199 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 200 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 201 |
+
ReturnMetadata: true,
|
| 202 |
+
Kind: &pb.GenerativeProvider_Google{Google: params},
|
| 203 |
+
})
|
| 204 |
+
})
|
| 205 |
+
})
|
| 206 |
+
}
|
| 207 |
+
})
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-google/setup_test.go
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeGoogle_VertexAI_SingleNode(t *testing.T) {
|
| 24 |
+
gcpProject := os.Getenv("GCP_PROJECT")
|
| 25 |
+
if gcpProject == "" {
|
| 26 |
+
t.Skip("skipping, GCP_PROJECT environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
googleApiKey := os.Getenv("GOOGLE_APIKEY")
|
| 29 |
+
if googleApiKey == "" {
|
| 30 |
+
t.Skip("skipping, GOOGLE_APIKEY environment variable not present")
|
| 31 |
+
}
|
| 32 |
+
ctx := context.Background()
|
| 33 |
+
compose, err := createSingleNodeEnvironment(ctx, googleApiKey)
|
| 34 |
+
require.NoError(t, err)
|
| 35 |
+
defer func() {
|
| 36 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 37 |
+
}()
|
| 38 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 39 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 40 |
+
|
| 41 |
+
t.Run("generative-google", testGenerativeGoogle(endpointREST, endpointGRPC, gcpProject, "generative-google"))
|
| 42 |
+
t.Run("generative-palm", testGenerativeGoogle(endpointREST, endpointGRPC, gcpProject, "generative-palm"))
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
func createSingleNodeEnvironment(ctx context.Context, googleApiKey string,
|
| 46 |
+
) (compose *docker.DockerCompose, err error) {
|
| 47 |
+
compose, err = composeModules(googleApiKey).
|
| 48 |
+
WithWeaviateWithGRPC().
|
| 49 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "120s").
|
| 50 |
+
Start(ctx)
|
| 51 |
+
return
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func composeModules(googleApiKey string) (composeModules *docker.Compose) {
|
| 55 |
+
composeModules = docker.New().
|
| 56 |
+
WithText2VecGoogle(googleApiKey).
|
| 57 |
+
WithGenerativeGoogle(googleApiKey)
|
| 58 |
+
return
|
| 59 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-nvidia/generative_nvidia_test.go
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 22 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
func testGenerativeNvidia(rest, grpc string) func(t *testing.T) {
|
| 27 |
+
return func(t *testing.T) {
|
| 28 |
+
helper.SetupClient(rest)
|
| 29 |
+
helper.SetupGRPCClient(t, grpc)
|
| 30 |
+
// Data
|
| 31 |
+
data := planets.Planets
|
| 32 |
+
// Define class
|
| 33 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 34 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 35 |
+
"description": {
|
| 36 |
+
Vectorizer: map[string]interface{}{
|
| 37 |
+
"text2vec-transformers": map[string]interface{}{
|
| 38 |
+
"properties": []interface{}{"description"},
|
| 39 |
+
"vectorizeClassName": false,
|
| 40 |
+
},
|
| 41 |
+
},
|
| 42 |
+
VectorIndexType: "flat",
|
| 43 |
+
},
|
| 44 |
+
}
|
| 45 |
+
tests := []struct {
|
| 46 |
+
name string
|
| 47 |
+
generativeModel string
|
| 48 |
+
absentModuleConfig bool
|
| 49 |
+
withImages bool
|
| 50 |
+
}{
|
| 51 |
+
{
|
| 52 |
+
name: "meta/llama-3.2-1b-instruct",
|
| 53 |
+
generativeModel: "meta/llama-3.2-1b-instruct",
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
name: "absent module config",
|
| 57 |
+
generativeModel: "microsoft/phi-3.5-mini-instruct",
|
| 58 |
+
absentModuleConfig: true,
|
| 59 |
+
},
|
| 60 |
+
}
|
| 61 |
+
for _, tt := range tests {
|
| 62 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 63 |
+
if tt.absentModuleConfig {
|
| 64 |
+
t.Log("skipping adding module config configuration to class")
|
| 65 |
+
} else {
|
| 66 |
+
class.ModuleConfig = map[string]interface{}{
|
| 67 |
+
"generative-nvidia": map[string]interface{}{
|
| 68 |
+
"model": tt.generativeModel,
|
| 69 |
+
},
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
// create schema
|
| 73 |
+
helper.CreateClass(t, class)
|
| 74 |
+
defer helper.DeleteClass(t, class.Class)
|
| 75 |
+
// create objects
|
| 76 |
+
t.Run("create objects", func(t *testing.T) {
|
| 77 |
+
planets.InsertObjects(t, class.Class)
|
| 78 |
+
})
|
| 79 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 80 |
+
for _, planet := range data {
|
| 81 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 82 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 83 |
+
require.NoError(t, err)
|
| 84 |
+
require.NotNil(t, obj)
|
| 85 |
+
require.Len(t, obj.Vectors, 1)
|
| 86 |
+
})
|
| 87 |
+
}
|
| 88 |
+
})
|
| 89 |
+
// generative task
|
| 90 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 91 |
+
planets.CreateTweetTest(t, class.Class)
|
| 92 |
+
})
|
| 93 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 94 |
+
params := "nvidia:{temperature:0.1}"
|
| 95 |
+
if tt.absentModuleConfig {
|
| 96 |
+
params = fmt.Sprintf("nvidia:{temperature:0.1 model:\"%s\" baseURL:\"https://integrate.api.nvidia.com\"}", tt.generativeModel)
|
| 97 |
+
}
|
| 98 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 99 |
+
})
|
| 100 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 101 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 102 |
+
})
|
| 103 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 104 |
+
nvidiaParams := &pb.GenerativeNvidia{
|
| 105 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 106 |
+
MaxTokens: grpchelper.ToPtr(int64(1024)),
|
| 107 |
+
Temperature: grpchelper.ToPtr(0.2),
|
| 108 |
+
TopP: grpchelper.ToPtr(0.7),
|
| 109 |
+
}
|
| 110 |
+
if tt.absentModuleConfig {
|
| 111 |
+
nvidiaParams.BaseUrl = grpchelper.ToPtr("https://integrate.api.nvidia.com")
|
| 112 |
+
}
|
| 113 |
+
params := &pb.GenerativeProvider_Nvidia{
|
| 114 |
+
Nvidia: nvidiaParams,
|
| 115 |
+
}
|
| 116 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{ReturnMetadata: true, Kind: params})
|
| 117 |
+
})
|
| 118 |
+
})
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-nvidia/setup_test.go
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeNvidia_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("NVIDIA_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, NVIDIA_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 35 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 36 |
+
|
| 37 |
+
t.Run("tests", testGenerativeNvidia(endpointREST, endpointGRPC))
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 41 |
+
) (compose *docker.DockerCompose, err error) {
|
| 42 |
+
compose, err = composeModules(apiKey).
|
| 43 |
+
WithWeaviateWithGRPC().
|
| 44 |
+
Start(ctx)
|
| 45 |
+
return
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 49 |
+
composeModules = docker.New().
|
| 50 |
+
WithText2VecTransformers().
|
| 51 |
+
WithGenerativeNvidia(apiKey)
|
| 52 |
+
return
|
| 53 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-ollama/generative_ollama_test.go
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
|
| 17 |
+
"github.com/stretchr/testify/assert"
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 22 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
func testGenerativeOllama(rest, grpc, ollamaApiEndpoint string) func(t *testing.T) {
|
| 27 |
+
return func(t *testing.T) {
|
| 28 |
+
helper.SetupClient(rest)
|
| 29 |
+
helper.SetupGRPCClient(t, grpc)
|
| 30 |
+
// Data
|
| 31 |
+
p := planets.Planets
|
| 32 |
+
// Define class
|
| 33 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 34 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 35 |
+
"description": {
|
| 36 |
+
Vectorizer: map[string]interface{}{
|
| 37 |
+
"text2vec-transformers": map[string]interface{}{
|
| 38 |
+
"properties": []interface{}{"description"},
|
| 39 |
+
"vectorizeClassName": false,
|
| 40 |
+
},
|
| 41 |
+
},
|
| 42 |
+
VectorIndexType: "flat",
|
| 43 |
+
},
|
| 44 |
+
}
|
| 45 |
+
tests := []struct {
|
| 46 |
+
name string
|
| 47 |
+
generativeModel string
|
| 48 |
+
}{
|
| 49 |
+
{
|
| 50 |
+
name: "tinyllama",
|
| 51 |
+
generativeModel: "tinyllama",
|
| 52 |
+
},
|
| 53 |
+
}
|
| 54 |
+
for _, tt := range tests {
|
| 55 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 56 |
+
class.ModuleConfig = map[string]interface{}{
|
| 57 |
+
"generative-ollama": map[string]interface{}{
|
| 58 |
+
"apiEndpoint": ollamaApiEndpoint,
|
| 59 |
+
"model": tt.generativeModel,
|
| 60 |
+
},
|
| 61 |
+
}
|
| 62 |
+
// create schema
|
| 63 |
+
helper.CreateClass(t, class)
|
| 64 |
+
defer helper.DeleteClass(t, class.Class)
|
| 65 |
+
// create objects
|
| 66 |
+
t.Run("create objects", func(t *testing.T) {
|
| 67 |
+
planets.InsertObjects(t, class.Class)
|
| 68 |
+
})
|
| 69 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 70 |
+
for _, planet := range p {
|
| 71 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 72 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 73 |
+
require.NoError(t, err)
|
| 74 |
+
require.NotNil(t, obj)
|
| 75 |
+
require.Len(t, obj.Vectors, 1)
|
| 76 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 77 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 78 |
+
})
|
| 79 |
+
}
|
| 80 |
+
})
|
| 81 |
+
// generative task
|
| 82 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 83 |
+
planets.CreateTweetTest(t, class.Class)
|
| 84 |
+
})
|
| 85 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 86 |
+
params := "ollama:{temperature:0.1}"
|
| 87 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 88 |
+
})
|
| 89 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 90 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 91 |
+
})
|
| 92 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 93 |
+
params := &pb.GenerativeProvider_Ollama{
|
| 94 |
+
Ollama: &pb.GenerativeOllama{
|
| 95 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 96 |
+
Temperature: grpchelper.ToPtr(0.9),
|
| 97 |
+
},
|
| 98 |
+
}
|
| 99 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 100 |
+
ReturnMetadata: false, // no metadata for ollama
|
| 101 |
+
Kind: params,
|
| 102 |
+
})
|
| 103 |
+
})
|
| 104 |
+
t.Run("check if other properties are being added to prompt", func(t *testing.T) {
|
| 105 |
+
prompt := "Write a summary using: planet's name: {name}, mean radius: {meanRadius}, moons: {satellites}, surface temperatures [min,mean,max]: {surfaceTemperaturesCelcius} and is habitable: {isHabitable} information"
|
| 106 |
+
planets.CreatePromptTestWithParamsWithDebug(t, class.Class, prompt, "", true)
|
| 107 |
+
})
|
| 108 |
+
})
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-ollama/setup_test.go
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
func TestGenerativeOllama_SingleNode(t *testing.T) {
|
| 23 |
+
ctx := context.Background()
|
| 24 |
+
compose, err := createSingleNodeEnvironment(ctx)
|
| 25 |
+
require.NoError(t, err)
|
| 26 |
+
defer func() {
|
| 27 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 28 |
+
}()
|
| 29 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 30 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 31 |
+
ollamaApiEndpoint := compose.GetOllamaGenerative().GetEndpoint("apiEndpoint")
|
| 32 |
+
|
| 33 |
+
t.Run("tests", testGenerativeOllama(endpointREST, endpointGRPC, ollamaApiEndpoint))
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func createSingleNodeEnvironment(ctx context.Context,
|
| 37 |
+
) (compose *docker.DockerCompose, err error) {
|
| 38 |
+
compose, err = composeModules().
|
| 39 |
+
WithWeaviateWithGRPC().
|
| 40 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "120s").
|
| 41 |
+
Start(ctx)
|
| 42 |
+
return
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
func composeModules() (composeModules *docker.Compose) {
|
| 46 |
+
composeModules = docker.New().
|
| 47 |
+
WithText2VecTransformers().
|
| 48 |
+
WithGenerativeOllama()
|
| 49 |
+
return
|
| 50 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-openai/generative_openai_test.go
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"strings"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/assert"
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 22 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 24 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 25 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
func testGenerativeOpenAI(rest, grpc string) func(t *testing.T) {
|
| 29 |
+
return func(t *testing.T) {
|
| 30 |
+
helper.SetupClient(rest)
|
| 31 |
+
helper.SetupGRPCClient(t, grpc)
|
| 32 |
+
// Define path to test/helper/sample-schema/planets/data folder
|
| 33 |
+
dataFolderPath := "../../../test/helper/sample-schema/planets/data"
|
| 34 |
+
// Data
|
| 35 |
+
data := planets.Planets
|
| 36 |
+
// Define class
|
| 37 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 38 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 39 |
+
"description": {
|
| 40 |
+
Vectorizer: map[string]interface{}{
|
| 41 |
+
"text2vec-transformers": map[string]interface{}{
|
| 42 |
+
"properties": []interface{}{"description"},
|
| 43 |
+
"vectorizeClassName": false,
|
| 44 |
+
},
|
| 45 |
+
},
|
| 46 |
+
VectorIndexType: "flat",
|
| 47 |
+
},
|
| 48 |
+
}
|
| 49 |
+
tests := []struct {
|
| 50 |
+
name string
|
| 51 |
+
generativeModel string
|
| 52 |
+
absentModuleConfig bool
|
| 53 |
+
withImages bool
|
| 54 |
+
}{
|
| 55 |
+
{
|
| 56 |
+
name: "gpt-3.5-turbo",
|
| 57 |
+
generativeModel: "gpt-3.5-turbo",
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
name: "gpt-4",
|
| 61 |
+
generativeModel: "gpt-4",
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
name: "absent module config",
|
| 65 |
+
generativeModel: "gpt-4",
|
| 66 |
+
absentModuleConfig: true,
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
name: "gpt-4o-mini",
|
| 70 |
+
generativeModel: "gpt-4o-mini",
|
| 71 |
+
withImages: true,
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
name: "gpt-5",
|
| 75 |
+
generativeModel: "gpt-5",
|
| 76 |
+
withImages: true,
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
name: "gpt-5-mini",
|
| 80 |
+
generativeModel: "gpt-5-mini",
|
| 81 |
+
withImages: true,
|
| 82 |
+
},
|
| 83 |
+
}
|
| 84 |
+
for _, tt := range tests {
|
| 85 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 86 |
+
if tt.absentModuleConfig {
|
| 87 |
+
t.Log("skipping adding module config configuration to class")
|
| 88 |
+
} else {
|
| 89 |
+
class.ModuleConfig = map[string]interface{}{
|
| 90 |
+
"generative-openai": map[string]interface{}{
|
| 91 |
+
"model": tt.generativeModel,
|
| 92 |
+
},
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
// create schema
|
| 96 |
+
helper.CreateClass(t, class)
|
| 97 |
+
defer helper.DeleteClass(t, class.Class)
|
| 98 |
+
// create objects
|
| 99 |
+
t.Run("create objects", func(t *testing.T) {
|
| 100 |
+
if tt.withImages {
|
| 101 |
+
planets.InsertObjectsWithImages(t, class.Class, dataFolderPath)
|
| 102 |
+
} else {
|
| 103 |
+
planets.InsertObjects(t, class.Class)
|
| 104 |
+
}
|
| 105 |
+
})
|
| 106 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 107 |
+
for _, planet := range data {
|
| 108 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 109 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 110 |
+
require.NoError(t, err)
|
| 111 |
+
require.NotNil(t, obj)
|
| 112 |
+
require.Len(t, obj.Vectors, 1)
|
| 113 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 114 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 115 |
+
})
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
// generative task
|
| 119 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 120 |
+
planets.CreateTweetTest(t, class.Class)
|
| 121 |
+
})
|
| 122 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 123 |
+
params := "openai:{temperature:1.0}"
|
| 124 |
+
if tt.absentModuleConfig {
|
| 125 |
+
params = fmt.Sprintf("openai:{temperature:1.0 model:\"%s\" baseURL:\"https://api.openai.com\" isAzure:false}", tt.generativeModel)
|
| 126 |
+
}
|
| 127 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 128 |
+
})
|
| 129 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 130 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
params := func() *pb.GenerativeOpenAI {
|
| 134 |
+
params := &pb.GenerativeOpenAI{
|
| 135 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 136 |
+
MaxTokens: grpchelper.ToPtr(int64(2000)),
|
| 137 |
+
Temperature: grpchelper.ToPtr(1.0),
|
| 138 |
+
N: grpchelper.ToPtr(int64(8)),
|
| 139 |
+
}
|
| 140 |
+
if !strings.HasPrefix(tt.generativeModel, "gpt-5") {
|
| 141 |
+
// gpt-5 models don't support topP, presencePenalty and frequencyPenalty parameters
|
| 142 |
+
params.TopP = grpchelper.ToPtr(0.9)
|
| 143 |
+
params.PresencePenalty = grpchelper.ToPtr(0.9)
|
| 144 |
+
params.FrequencyPenalty = grpchelper.ToPtr(0.9)
|
| 145 |
+
}
|
| 146 |
+
if strings.HasPrefix(tt.generativeModel, "gpt-4o") {
|
| 147 |
+
// increase the max tokens
|
| 148 |
+
params.MaxTokens = grpchelper.ToPtr(int64(5000))
|
| 149 |
+
}
|
| 150 |
+
if tt.absentModuleConfig {
|
| 151 |
+
params.BaseUrl = grpchelper.ToPtr("https://api.openai.com")
|
| 152 |
+
}
|
| 153 |
+
return params
|
| 154 |
+
}
|
| 155 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 156 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 157 |
+
ReturnMetadata: true,
|
| 158 |
+
Kind: &pb.GenerativeProvider_Openai{
|
| 159 |
+
Openai: params(),
|
| 160 |
+
},
|
| 161 |
+
})
|
| 162 |
+
})
|
| 163 |
+
if tt.withImages {
|
| 164 |
+
t.Run("image prompt", func(t *testing.T) {
|
| 165 |
+
t.Run("graphql", func(t *testing.T) {
|
| 166 |
+
prompt := "Describe image"
|
| 167 |
+
params := "openai:{imageProperties:\"image\"}"
|
| 168 |
+
planets.CreatePromptTestWithParams(t, class.Class, prompt, params)
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
singlePrompt := "Give a short answer: What's on the image?"
|
| 172 |
+
groupPrompt := "Give a short answer: What are on the following images?"
|
| 173 |
+
|
| 174 |
+
t.Run("grpc server stored images", func(t *testing.T) {
|
| 175 |
+
params := params()
|
| 176 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 177 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 178 |
+
ReturnMetadata: true,
|
| 179 |
+
Kind: &pb.GenerativeProvider_Openai{Openai: params},
|
| 180 |
+
})
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
t.Run("grpc user provided images", func(t *testing.T) {
|
| 184 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 185 |
+
require.NoError(t, err)
|
| 186 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 187 |
+
require.NoError(t, err)
|
| 188 |
+
|
| 189 |
+
params := params()
|
| 190 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 191 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 192 |
+
ReturnMetadata: true,
|
| 193 |
+
Kind: &pb.GenerativeProvider_Openai{Openai: params},
|
| 194 |
+
})
|
| 195 |
+
})
|
| 196 |
+
|
| 197 |
+
t.Run("grpc mixed images", func(t *testing.T) {
|
| 198 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 199 |
+
require.NoError(t, err)
|
| 200 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 201 |
+
require.NoError(t, err)
|
| 202 |
+
|
| 203 |
+
params := params()
|
| 204 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 205 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 206 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 207 |
+
ReturnMetadata: true,
|
| 208 |
+
Kind: &pb.GenerativeProvider_Openai{Openai: params},
|
| 209 |
+
})
|
| 210 |
+
})
|
| 211 |
+
})
|
| 212 |
+
}
|
| 213 |
+
})
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-openai/setup_test.go
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeOpenAI_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("OPENAI_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, OPENAI_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
organization := os.Getenv("OPENAI_ORGANIZATION")
|
| 29 |
+
if organization == "" {
|
| 30 |
+
t.Skip("skipping, OPENAI_ORGANIZATION environment variable not present")
|
| 31 |
+
}
|
| 32 |
+
ctx := context.Background()
|
| 33 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey, organization)
|
| 34 |
+
require.NoError(t, err)
|
| 35 |
+
defer func() {
|
| 36 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 37 |
+
}()
|
| 38 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 39 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 40 |
+
|
| 41 |
+
t.Run("tests", testGenerativeOpenAI(endpointREST, endpointGRPC))
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey, organization string,
|
| 45 |
+
) (compose *docker.DockerCompose, err error) {
|
| 46 |
+
compose, err = composeModules(apiKey, organization).
|
| 47 |
+
WithWeaviateWithGRPC().
|
| 48 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "180s").
|
| 49 |
+
Start(ctx)
|
| 50 |
+
return
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
func composeModules(apiKey, organization string) (composeModules *docker.Compose) {
|
| 54 |
+
composeModules = docker.New().
|
| 55 |
+
WithText2VecTransformers().
|
| 56 |
+
WithGenerativeOpenAI(apiKey, organization, "")
|
| 57 |
+
return
|
| 58 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-xai/generative_xai_test.go
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/assert"
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
grpchelper "github.com/weaviate/weaviate/test/helper/grpc"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func testGenerativeXAI(rest, grpc string) func(t *testing.T) {
|
| 28 |
+
return func(t *testing.T) {
|
| 29 |
+
helper.SetupClient(rest)
|
| 30 |
+
helper.SetupGRPCClient(t, grpc)
|
| 31 |
+
// Define path to test/helper/sample-schema/planets/data folder
|
| 32 |
+
dataFolderPath := "../../../test/helper/sample-schema/planets/data"
|
| 33 |
+
// Data
|
| 34 |
+
data := planets.Planets
|
| 35 |
+
// Define class
|
| 36 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 37 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 38 |
+
"description": {
|
| 39 |
+
Vectorizer: map[string]any{
|
| 40 |
+
"text2vec-transformers": map[string]any{
|
| 41 |
+
"properties": []any{"description"},
|
| 42 |
+
"vectorizeClassName": false,
|
| 43 |
+
},
|
| 44 |
+
},
|
| 45 |
+
VectorIndexType: "flat",
|
| 46 |
+
},
|
| 47 |
+
}
|
| 48 |
+
tests := []struct {
|
| 49 |
+
name string
|
| 50 |
+
generativeModel string
|
| 51 |
+
absentModuleConfig bool
|
| 52 |
+
withImages bool
|
| 53 |
+
}{
|
| 54 |
+
{
|
| 55 |
+
name: "grok-2-latest",
|
| 56 |
+
generativeModel: "grok-2-latest",
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
name: "grok-2-1212",
|
| 60 |
+
generativeModel: "grok-2-1212",
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
name: "absent module config",
|
| 64 |
+
generativeModel: "grok-2-1212",
|
| 65 |
+
absentModuleConfig: true,
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
name: "grok-2-vision-1212",
|
| 69 |
+
generativeModel: "grok-2-vision-1212",
|
| 70 |
+
withImages: true,
|
| 71 |
+
},
|
| 72 |
+
}
|
| 73 |
+
for _, tt := range tests {
|
| 74 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 75 |
+
if tt.absentModuleConfig {
|
| 76 |
+
t.Log("skipping adding module config configuration to class")
|
| 77 |
+
} else {
|
| 78 |
+
class.ModuleConfig = map[string]any{
|
| 79 |
+
"generative-xai": map[string]any{
|
| 80 |
+
"model": tt.generativeModel,
|
| 81 |
+
},
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
// create schema
|
| 85 |
+
helper.CreateClass(t, class)
|
| 86 |
+
defer helper.DeleteClass(t, class.Class)
|
| 87 |
+
// create objects
|
| 88 |
+
t.Run("create objects", func(t *testing.T) {
|
| 89 |
+
if tt.withImages {
|
| 90 |
+
planets.InsertObjectsWithImages(t, class.Class, dataFolderPath)
|
| 91 |
+
} else {
|
| 92 |
+
planets.InsertObjects(t, class.Class)
|
| 93 |
+
}
|
| 94 |
+
})
|
| 95 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 96 |
+
for _, planet := range data {
|
| 97 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 98 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 99 |
+
require.NoError(t, err)
|
| 100 |
+
require.NotNil(t, obj)
|
| 101 |
+
require.Len(t, obj.Vectors, 1)
|
| 102 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 103 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 104 |
+
})
|
| 105 |
+
}
|
| 106 |
+
})
|
| 107 |
+
// generative task
|
| 108 |
+
t.Run("create a tweet", func(t *testing.T) {
|
| 109 |
+
planets.CreateTweetTest(t, class.Class)
|
| 110 |
+
})
|
| 111 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 112 |
+
params := "xai:{temperature:0.1}"
|
| 113 |
+
if tt.absentModuleConfig {
|
| 114 |
+
params = fmt.Sprintf("xai:{temperature:0.1 model:\"%s\" baseURL:\"https://api.x.ai\"}", tt.generativeModel)
|
| 115 |
+
}
|
| 116 |
+
planets.CreateTweetTestWithParams(t, class.Class, params)
|
| 117 |
+
})
|
| 118 |
+
t.Run("create a tweet using grpc", func(t *testing.T) {
|
| 119 |
+
planets.CreateTweetTestGRPC(t, class.Class)
|
| 120 |
+
})
|
| 121 |
+
|
| 122 |
+
params := func() *pb.GenerativeXAI {
|
| 123 |
+
params := &pb.GenerativeXAI{
|
| 124 |
+
MaxTokens: grpchelper.ToPtr(int64(90)),
|
| 125 |
+
Model: grpchelper.ToPtr(tt.generativeModel),
|
| 126 |
+
Temperature: grpchelper.ToPtr(0.9),
|
| 127 |
+
TopP: grpchelper.ToPtr(0.9),
|
| 128 |
+
}
|
| 129 |
+
if tt.absentModuleConfig {
|
| 130 |
+
params.BaseUrl = grpchelper.ToPtr("https://api.x.ai")
|
| 131 |
+
}
|
| 132 |
+
return params
|
| 133 |
+
}
|
| 134 |
+
t.Run("create a tweet with params using grpc", func(t *testing.T) {
|
| 135 |
+
planets.CreateTweetTestWithParamsGRPC(t, class.Class, &pb.GenerativeProvider{
|
| 136 |
+
ReturnMetadata: true,
|
| 137 |
+
Kind: &pb.GenerativeProvider_Xai{
|
| 138 |
+
Xai: params(),
|
| 139 |
+
},
|
| 140 |
+
})
|
| 141 |
+
})
|
| 142 |
+
if tt.withImages {
|
| 143 |
+
t.Run("image prompt", func(t *testing.T) {
|
| 144 |
+
t.Run("graphql", func(t *testing.T) {
|
| 145 |
+
prompt := "Describe image"
|
| 146 |
+
params := "xai:{imageProperties:\"image\"}"
|
| 147 |
+
planets.CreatePromptTestWithParams(t, class.Class, prompt, params)
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
singlePrompt := "Give a short answer: What's on the image?"
|
| 151 |
+
groupPrompt := "Give a short answer: What are on the following images?"
|
| 152 |
+
|
| 153 |
+
t.Run("grpc server stored images", func(t *testing.T) {
|
| 154 |
+
params := params()
|
| 155 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 156 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 157 |
+
ReturnMetadata: true,
|
| 158 |
+
Kind: &pb.GenerativeProvider_Xai{Xai: params},
|
| 159 |
+
})
|
| 160 |
+
})
|
| 161 |
+
|
| 162 |
+
t.Run("grpc user provided images", func(t *testing.T) {
|
| 163 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 164 |
+
require.NoError(t, err)
|
| 165 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 166 |
+
require.NoError(t, err)
|
| 167 |
+
|
| 168 |
+
params := params()
|
| 169 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 170 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 171 |
+
ReturnMetadata: true,
|
| 172 |
+
Kind: &pb.GenerativeProvider_Xai{Xai: params},
|
| 173 |
+
})
|
| 174 |
+
})
|
| 175 |
+
|
| 176 |
+
t.Run("grpc mixed images", func(t *testing.T) {
|
| 177 |
+
earth, err := planets.GetImageBlob(dataFolderPath, "earth")
|
| 178 |
+
require.NoError(t, err)
|
| 179 |
+
mars, err := planets.GetImageBlob(dataFolderPath, "mars")
|
| 180 |
+
require.NoError(t, err)
|
| 181 |
+
|
| 182 |
+
params := params()
|
| 183 |
+
params.Images = &pb.TextArray{Values: []string{earth, mars}}
|
| 184 |
+
params.ImageProperties = &pb.TextArray{Values: []string{"image"}}
|
| 185 |
+
planets.CreatePromptTestWithParamsGRPC(t, class.Class, singlePrompt, groupPrompt, &pb.GenerativeProvider{
|
| 186 |
+
ReturnMetadata: true,
|
| 187 |
+
Kind: &pb.GenerativeProvider_Xai{Xai: params},
|
| 188 |
+
})
|
| 189 |
+
})
|
| 190 |
+
})
|
| 191 |
+
}
|
| 192 |
+
})
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/generative-xai/setup_test.go
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeOpenAI_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("XAI_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, XAI_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpointREST := compose.GetWeaviate().URI()
|
| 35 |
+
endpointGRPC := compose.GetWeaviate().GrpcURI()
|
| 36 |
+
|
| 37 |
+
t.Run("tests", testGenerativeXAI(endpointREST, endpointGRPC))
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 41 |
+
) (compose *docker.DockerCompose, err error) {
|
| 42 |
+
compose, err = composeModules(apiKey).
|
| 43 |
+
WithWeaviateWithGRPC().
|
| 44 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", "120s").
|
| 45 |
+
Start(ctx)
|
| 46 |
+
return
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 50 |
+
composeModules = docker.New().
|
| 51 |
+
WithText2VecTransformers().
|
| 52 |
+
WithGenerativeXAI(apiKey)
|
| 53 |
+
return
|
| 54 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/img2vec-neural/neural_test.go
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/base64"
|
| 16 |
+
"fmt"
|
| 17 |
+
"io"
|
| 18 |
+
"os"
|
| 19 |
+
"testing"
|
| 20 |
+
|
| 21 |
+
"github.com/stretchr/testify/assert"
|
| 22 |
+
"github.com/stretchr/testify/require"
|
| 23 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 25 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 26 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
func Test_Img2VecNeural(t *testing.T) {
|
| 30 |
+
helper.SetupClient(os.Getenv(weaviateEndpoint))
|
| 31 |
+
|
| 32 |
+
fashionItemClass := &models.Class{
|
| 33 |
+
Class: "FashionItem",
|
| 34 |
+
Vectorizer: "img2vec-neural",
|
| 35 |
+
ModuleConfig: map[string]interface{}{
|
| 36 |
+
"img2vec-neural": map[string]interface{}{
|
| 37 |
+
"imageFields": []string{"image"},
|
| 38 |
+
},
|
| 39 |
+
},
|
| 40 |
+
Properties: []*models.Property{
|
| 41 |
+
{
|
| 42 |
+
Name: "image",
|
| 43 |
+
DataType: schema.DataTypeBlob.PropString(),
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
Name: "description",
|
| 47 |
+
DataType: schema.DataTypeText.PropString(),
|
| 48 |
+
Tokenization: models.PropertyTokenizationWhitespace,
|
| 49 |
+
},
|
| 50 |
+
},
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
helper.CreateClass(t, fashionItemClass)
|
| 54 |
+
defer helper.DeleteClass(t, fashionItemClass.Class)
|
| 55 |
+
|
| 56 |
+
getBase64EncodedTestImage := func() string {
|
| 57 |
+
image, err := os.Open("./data/pixel.png")
|
| 58 |
+
require.Nil(t, err)
|
| 59 |
+
require.NotNil(t, image)
|
| 60 |
+
content, err := io.ReadAll(image)
|
| 61 |
+
require.Nil(t, err)
|
| 62 |
+
return base64.StdEncoding.EncodeToString(content)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
t.Run("import data", func(t *testing.T) {
|
| 66 |
+
base64Image := getBase64EncodedTestImage()
|
| 67 |
+
obj := &models.Object{
|
| 68 |
+
Class: fashionItemClass.Class,
|
| 69 |
+
Properties: map[string]interface{}{
|
| 70 |
+
"image": base64Image,
|
| 71 |
+
"description": "A single black pixel",
|
| 72 |
+
},
|
| 73 |
+
}
|
| 74 |
+
helper.CreateObject(t, obj)
|
| 75 |
+
})
|
| 76 |
+
|
| 77 |
+
t.Run("perform nearImage query", func(t *testing.T) {
|
| 78 |
+
queryTemplate := `
|
| 79 |
+
{
|
| 80 |
+
Get {
|
| 81 |
+
FashionItem(
|
| 82 |
+
nearImage: {
|
| 83 |
+
image: "%s"
|
| 84 |
+
}
|
| 85 |
+
){
|
| 86 |
+
image
|
| 87 |
+
description
|
| 88 |
+
_additional{vector}
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}`
|
| 92 |
+
query := fmt.Sprintf(queryTemplate, getBase64EncodedTestImage())
|
| 93 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 94 |
+
fashionItems := result.Get("Get", "FashionItem").AsSlice()
|
| 95 |
+
require.True(t, len(fashionItems) > 0)
|
| 96 |
+
item, ok := fashionItems[0].(map[string]interface{})
|
| 97 |
+
require.True(t, ok)
|
| 98 |
+
assert.NotNil(t, item["image"])
|
| 99 |
+
assert.NotNil(t, item["description"])
|
| 100 |
+
vector := item["_additional"].(map[string]interface{})["vector"]
|
| 101 |
+
assert.NotNil(t, vector)
|
| 102 |
+
})
|
| 103 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/img2vec-neural/setup_test.go
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/pkg/errors"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const weaviateEndpoint = "WEAVIATE_ENDPOINT"
|
| 24 |
+
|
| 25 |
+
func TestMain(m *testing.M) {
|
| 26 |
+
ctx := context.Background()
|
| 27 |
+
compose, err := docker.New().
|
| 28 |
+
WithWeaviate().
|
| 29 |
+
WithText2VecContextionary().
|
| 30 |
+
WithImg2VecNeural().
|
| 31 |
+
Start(ctx)
|
| 32 |
+
if err != nil {
|
| 33 |
+
panic(errors.Wrapf(err, "cannot start"))
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
os.Setenv(weaviateEndpoint, compose.GetWeaviate().URI())
|
| 37 |
+
code := m.Run()
|
| 38 |
+
|
| 39 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 40 |
+
panic(errors.Wrapf(err, "cannot terminate"))
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
os.Exit(code)
|
| 44 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-generative/many_generative_test.go
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
|
| 17 |
+
"github.com/stretchr/testify/assert"
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/planets"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testGenerativeManyModules(host, ollamaApiEndpoint, region, gcpProject string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Data
|
| 28 |
+
data := planets.Planets
|
| 29 |
+
// Define class
|
| 30 |
+
class := planets.BaseClass("PlanetsGenerativeTest")
|
| 31 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 32 |
+
"description": {
|
| 33 |
+
Vectorizer: map[string]interface{}{
|
| 34 |
+
"text2vec-transformers": map[string]interface{}{
|
| 35 |
+
"properties": []interface{}{"description"},
|
| 36 |
+
"vectorizeClassName": false,
|
| 37 |
+
},
|
| 38 |
+
},
|
| 39 |
+
VectorIndexType: "flat",
|
| 40 |
+
},
|
| 41 |
+
}
|
| 42 |
+
class.ModuleConfig = map[string]interface{}{
|
| 43 |
+
"generative-aws": map[string]interface{}{
|
| 44 |
+
"service": "bedrock",
|
| 45 |
+
"region": region,
|
| 46 |
+
"model": "amazon.titan-text-lite-v1",
|
| 47 |
+
},
|
| 48 |
+
"generative-google": map[string]interface{}{
|
| 49 |
+
"projectId": gcpProject,
|
| 50 |
+
"modelId": "gemini-1.0-pro",
|
| 51 |
+
},
|
| 52 |
+
"generative-ollama": map[string]interface{}{
|
| 53 |
+
"apiEndpoint": ollamaApiEndpoint,
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
// create schema
|
| 57 |
+
helper.CreateClass(t, class)
|
| 58 |
+
defer helper.DeleteClass(t, class.Class)
|
| 59 |
+
// create objects
|
| 60 |
+
t.Run("create objects", func(t *testing.T) {
|
| 61 |
+
planets.InsertObjects(t, class.Class)
|
| 62 |
+
})
|
| 63 |
+
t.Run("check objects existence", func(t *testing.T) {
|
| 64 |
+
for _, planet := range data {
|
| 65 |
+
t.Run(planet.ID.String(), func(t *testing.T) {
|
| 66 |
+
obj, err := helper.GetObject(t, class.Class, planet.ID, "vector")
|
| 67 |
+
require.NoError(t, err)
|
| 68 |
+
require.NotNil(t, obj)
|
| 69 |
+
require.Len(t, obj.Vectors, 1)
|
| 70 |
+
require.IsType(t, []float32{}, obj.Vectors["description"])
|
| 71 |
+
assert.True(t, len(obj.Vectors["description"].([]float32)) > 0)
|
| 72 |
+
})
|
| 73 |
+
}
|
| 74 |
+
})
|
| 75 |
+
// generative task with params
|
| 76 |
+
tests := []struct {
|
| 77 |
+
name string
|
| 78 |
+
params string
|
| 79 |
+
}{
|
| 80 |
+
{
|
| 81 |
+
name: "ollama",
|
| 82 |
+
params: `ollama:{temperature:0.1 model:"tinyllama"}`,
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
name: "aws",
|
| 86 |
+
params: `aws:{temperature:0.9 model:"ai21.j2-mid-v1"}`,
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
name: "google",
|
| 90 |
+
params: `google:{topP:0.8 topK:30 model:"chat-bison"}`,
|
| 91 |
+
},
|
| 92 |
+
}
|
| 93 |
+
for _, tt := range tests {
|
| 94 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 95 |
+
t.Run("create a tweet with params", func(t *testing.T) {
|
| 96 |
+
planets.CreateTweetTestWithParams(t, class.Class, tt.params)
|
| 97 |
+
})
|
| 98 |
+
})
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-generative/setup_test.go
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestGenerativeManyModules_SingleNode(t *testing.T) {
|
| 24 |
+
// AWS
|
| 25 |
+
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
| 26 |
+
if accessKey == "" {
|
| 27 |
+
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
| 28 |
+
if accessKey == "" {
|
| 29 |
+
t.Skip("skipping, AWS_ACCESS_KEY environment variable not present")
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
secretKey := os.Getenv("AWS_SECRET_KEY")
|
| 33 |
+
if secretKey == "" {
|
| 34 |
+
secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
| 35 |
+
if secretKey == "" {
|
| 36 |
+
t.Skip("skipping, AWS_SECRET_KEY environment variable not present")
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
|
| 40 |
+
if sessionToken == "" {
|
| 41 |
+
t.Skip("skipping, AWS_SESSION_TOKEN environment variable not present")
|
| 42 |
+
}
|
| 43 |
+
region := os.Getenv("AWS_REGION")
|
| 44 |
+
if region == "" {
|
| 45 |
+
t.Skip("skipping, AWS_REGION environment variable not present")
|
| 46 |
+
}
|
| 47 |
+
// Google
|
| 48 |
+
gcpProject := os.Getenv("GCP_PROJECT")
|
| 49 |
+
if gcpProject == "" {
|
| 50 |
+
t.Skip("skipping, GCP_PROJECT environment variable not present")
|
| 51 |
+
}
|
| 52 |
+
googleApiKey := os.Getenv("GOOGLE_APIKEY")
|
| 53 |
+
if googleApiKey == "" {
|
| 54 |
+
t.Skip("skipping, GOOGLE_APIKEY environment variable not present")
|
| 55 |
+
}
|
| 56 |
+
// OpenAI
|
| 57 |
+
openAIApiKey := os.Getenv("OPENAI_APIKEY")
|
| 58 |
+
openAIOrganization := os.Getenv("OPENAI_ORGANIZATION")
|
| 59 |
+
// Cohere
|
| 60 |
+
cohereApiKey := os.Getenv("COHERE_APIKEY")
|
| 61 |
+
ctx := context.Background()
|
| 62 |
+
compose, err := createSingleNodeEnvironment(ctx, accessKey, secretKey, sessionToken,
|
| 63 |
+
openAIApiKey, openAIOrganization, googleApiKey, cohereApiKey,
|
| 64 |
+
)
|
| 65 |
+
require.NoError(t, err)
|
| 66 |
+
defer func() {
|
| 67 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 68 |
+
}()
|
| 69 |
+
endpoint := compose.GetWeaviate().URI()
|
| 70 |
+
ollamaApiEndpoint := compose.GetOllamaGenerative().GetEndpoint("apiEndpoint")
|
| 71 |
+
|
| 72 |
+
t.Run("tests", testGenerativeManyModules(endpoint, ollamaApiEndpoint, region, gcpProject))
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
func createSingleNodeEnvironment(ctx context.Context,
|
| 76 |
+
accessKey, secretKey, sessionToken string,
|
| 77 |
+
openAIApiKey, openAIOrganization string,
|
| 78 |
+
googleApiKey, cohereApiKey string,
|
| 79 |
+
) (compose *docker.DockerCompose, err error) {
|
| 80 |
+
compose, err = composeModules(accessKey, secretKey, sessionToken,
|
| 81 |
+
openAIApiKey, openAIOrganization, googleApiKey, cohereApiKey,
|
| 82 |
+
).
|
| 83 |
+
WithWeaviate().
|
| 84 |
+
Start(ctx)
|
| 85 |
+
return
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
func composeModules(accessKey, secretKey, sessionToken string,
|
| 89 |
+
openAIApiKey, openAIOrganization string,
|
| 90 |
+
googleApiKey, cohereApiKey string,
|
| 91 |
+
) (composeModules *docker.Compose) {
|
| 92 |
+
composeModules = docker.New().
|
| 93 |
+
WithText2VecTransformers().
|
| 94 |
+
WithGenerativeOllama().
|
| 95 |
+
WithGenerativeAWS(accessKey, secretKey, sessionToken).
|
| 96 |
+
WithGenerativeGoogle(googleApiKey).
|
| 97 |
+
WithGenerativeOpenAI(openAIApiKey, openAIOrganization, "").
|
| 98 |
+
WithGenerativeCohere(cohereApiKey)
|
| 99 |
+
return
|
| 100 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-modules/api_based_modules_sanity_test.go
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"testing"
|
| 16 |
+
|
| 17 |
+
"github.com/stretchr/testify/assert"
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
func apiBasedModulesTests(endpoint string) func(t *testing.T) {
|
| 23 |
+
return func(t *testing.T) {
|
| 24 |
+
helper.SetupClient(endpoint)
|
| 25 |
+
|
| 26 |
+
t.Run("check enabled modules", func(t *testing.T) {
|
| 27 |
+
meta := helper.GetMeta(t)
|
| 28 |
+
require.NotNil(t, meta)
|
| 29 |
+
|
| 30 |
+
expectedModuleNames := []string{
|
| 31 |
+
"generative-cohere", "generative-google", "generative-openai", "generative-aws", "generative-anyscale", "generative-friendliai",
|
| 32 |
+
"text2vec-cohere", "text2vec-contextionary", "text2vec-openai", "text2vec-huggingface",
|
| 33 |
+
"text2vec-google", "text2vec-aws", "text2vec-transformers", "qna-openai", "reranker-cohere",
|
| 34 |
+
"text2vec-voyageai", "reranker-voyageai",
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
modules, ok := meta.Modules.(map[string]interface{})
|
| 38 |
+
require.True(t, ok)
|
| 39 |
+
assert.True(t, len(modules) >= len(expectedModuleNames))
|
| 40 |
+
|
| 41 |
+
moduleNames := []string{}
|
| 42 |
+
for name := range modules {
|
| 43 |
+
moduleNames = append(moduleNames, name)
|
| 44 |
+
}
|
| 45 |
+
for _, name := range expectedModuleNames {
|
| 46 |
+
assert.Contains(t, moduleNames, name)
|
| 47 |
+
}
|
| 48 |
+
})
|
| 49 |
+
}
|
| 50 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-modules/many_modules_openai_test.go
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/json"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/assert"
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
func createSchemaOpenAISanityChecks(endpoint string) func(t *testing.T) {
|
| 26 |
+
return func(t *testing.T) {
|
| 27 |
+
helper.SetupClient(endpoint)
|
| 28 |
+
|
| 29 |
+
vectorizer := "text2vec-openai"
|
| 30 |
+
class := &models.Class{
|
| 31 |
+
Class: "OpenAI",
|
| 32 |
+
Properties: []*models.Property{
|
| 33 |
+
{
|
| 34 |
+
Name: "text",
|
| 35 |
+
DataType: []string{schema.DataTypeText.String()},
|
| 36 |
+
},
|
| 37 |
+
},
|
| 38 |
+
Vectorizer: vectorizer,
|
| 39 |
+
}
|
| 40 |
+
tests := []struct {
|
| 41 |
+
name string
|
| 42 |
+
text2vecOpenAI map[string]interface{}
|
| 43 |
+
expectDefaultSettings bool
|
| 44 |
+
}{
|
| 45 |
+
{
|
| 46 |
+
name: "model: text-embedding-3-large, dimensions: 256, vectorizeClassName: false",
|
| 47 |
+
text2vecOpenAI: map[string]interface{}{
|
| 48 |
+
"vectorizeClassName": false,
|
| 49 |
+
"model": "text-embedding-3-large",
|
| 50 |
+
"dimensions": 256,
|
| 51 |
+
},
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
name: "model: text-embedding-3-large, dimensions: 1024, vectorizeClassName: false",
|
| 55 |
+
text2vecOpenAI: map[string]interface{}{
|
| 56 |
+
"vectorizeClassName": false,
|
| 57 |
+
"model": "text-embedding-3-large",
|
| 58 |
+
"dimensions": 1024,
|
| 59 |
+
},
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
name: "model: text-embedding-3-large, dimensions: 3072, vectorizeClassName: false",
|
| 63 |
+
text2vecOpenAI: map[string]interface{}{
|
| 64 |
+
"vectorizeClassName": false,
|
| 65 |
+
"model": "text-embedding-3-large",
|
| 66 |
+
"dimensions": 3072,
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
name: "model: text-embedding-3-small, dimensions: 512, vectorizeClassName: true",
|
| 71 |
+
text2vecOpenAI: map[string]interface{}{
|
| 72 |
+
"vectorizeClassName": true,
|
| 73 |
+
"model": "text-embedding-3-small",
|
| 74 |
+
"dimensions": 512,
|
| 75 |
+
},
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
name: "model: text-embedding-3-small, dimensions: 1536, vectorizeClassName: false",
|
| 79 |
+
text2vecOpenAI: map[string]interface{}{
|
| 80 |
+
"vectorizeClassName": false,
|
| 81 |
+
"model": "text-embedding-3-small",
|
| 82 |
+
"dimensions": 1536,
|
| 83 |
+
},
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
name: "model: text-embedding-3-small, dimensions: 1536, vectorizeClassName: true",
|
| 87 |
+
text2vecOpenAI: map[string]interface{}{
|
| 88 |
+
"vectorizeClassName": true,
|
| 89 |
+
"model": "text-embedding-3-small",
|
| 90 |
+
"dimensions": 1536,
|
| 91 |
+
},
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
name: "model: ada, vectorizeClassName: false",
|
| 95 |
+
text2vecOpenAI: map[string]interface{}{
|
| 96 |
+
"vectorizeClassName": false,
|
| 97 |
+
"model": "ada",
|
| 98 |
+
},
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
name: "nil settings",
|
| 102 |
+
text2vecOpenAI: nil,
|
| 103 |
+
expectDefaultSettings: true,
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
name: "empty settings",
|
| 107 |
+
text2vecOpenAI: map[string]interface{}{},
|
| 108 |
+
expectDefaultSettings: true,
|
| 109 |
+
},
|
| 110 |
+
}
|
| 111 |
+
for _, tt := range tests {
|
| 112 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 113 |
+
class.ModuleConfig = map[string]interface{}{
|
| 114 |
+
vectorizer: tt.text2vecOpenAI,
|
| 115 |
+
}
|
| 116 |
+
helper.CreateClass(t, class)
|
| 117 |
+
defer helper.DeleteClass(t, class.Class)
|
| 118 |
+
verifyClass := helper.GetClass(t, class.Class)
|
| 119 |
+
moduleConfig, ok := verifyClass.ModuleConfig.(map[string]interface{})
|
| 120 |
+
require.True(t, ok)
|
| 121 |
+
require.NotEmpty(t, moduleConfig)
|
| 122 |
+
text2vecOpenAI, ok := moduleConfig[vectorizer].(map[string]interface{})
|
| 123 |
+
require.True(t, ok)
|
| 124 |
+
require.NotEmpty(t, text2vecOpenAI)
|
| 125 |
+
if tt.expectDefaultSettings {
|
| 126 |
+
assert.Equal(t, "text-embedding-3-small", text2vecOpenAI["model"])
|
| 127 |
+
assert.Equal(t, true, text2vecOpenAI["vectorizeClassName"])
|
| 128 |
+
} else {
|
| 129 |
+
assert.Equal(t, tt.text2vecOpenAI["model"], text2vecOpenAI["model"])
|
| 130 |
+
assert.Equal(t, tt.text2vecOpenAI["vectorizeClassName"], text2vecOpenAI["vectorizeClassName"])
|
| 131 |
+
expectedDimensions, ok := tt.text2vecOpenAI["dimensions"]
|
| 132 |
+
if ok {
|
| 133 |
+
dimensions, ok := text2vecOpenAI["dimensions"].(json.Number)
|
| 134 |
+
require.True(t, ok)
|
| 135 |
+
dimensionsInt64, err := dimensions.Int64()
|
| 136 |
+
require.NoError(t, err)
|
| 137 |
+
assert.Equal(t, expectedDimensions, int(dimensionsInt64))
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
})
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-modules/many_modules_sanity_test.go
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/json"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/go-openapi/strfmt"
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/books"
|
| 25 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multishard"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
func manyModulesTests(endpoint string) func(t *testing.T) {
|
| 29 |
+
return func(t *testing.T) {
|
| 30 |
+
helper.SetupClient(endpoint)
|
| 31 |
+
|
| 32 |
+
t.Run("check enabled modules", func(t *testing.T) {
|
| 33 |
+
meta := helper.GetMeta(t)
|
| 34 |
+
require.NotNil(t, meta)
|
| 35 |
+
|
| 36 |
+
expectedModuleNames := []string{
|
| 37 |
+
"generative-cohere", "generative-google", "generative-openai", "generative-aws", "generative-anyscale", "generative-friendliai",
|
| 38 |
+
"generative-anthropic", "text2vec-cohere", "text2vec-contextionary", "text2vec-openai", "text2vec-huggingface",
|
| 39 |
+
"text2vec-google", "text2vec-aws", "text2vec-transformers", "qna-openai", "reranker-cohere",
|
| 40 |
+
"text2vec-voyageai", "reranker-voyageai",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
modules, ok := meta.Modules.(map[string]interface{})
|
| 44 |
+
require.True(t, ok)
|
| 45 |
+
assert.Len(t, modules, len(expectedModuleNames))
|
| 46 |
+
|
| 47 |
+
moduleNames := []string{}
|
| 48 |
+
for name := range modules {
|
| 49 |
+
moduleNames = append(moduleNames, name)
|
| 50 |
+
}
|
| 51 |
+
assert.ElementsMatch(t, expectedModuleNames, moduleNames)
|
| 52 |
+
})
|
| 53 |
+
|
| 54 |
+
booksClass := books.ClassContextionaryVectorizer()
|
| 55 |
+
multiShardClass := multishard.ClassContextionaryVectorizer()
|
| 56 |
+
helper.CreateClass(t, booksClass)
|
| 57 |
+
helper.CreateClass(t, multiShardClass)
|
| 58 |
+
defer helper.DeleteClass(t, booksClass.Class)
|
| 59 |
+
defer helper.DeleteClass(t, multiShardClass.Class)
|
| 60 |
+
|
| 61 |
+
t.Run("import data", func(t *testing.T) {
|
| 62 |
+
for _, book := range books.Objects() {
|
| 63 |
+
helper.CreateObject(t, book)
|
| 64 |
+
helper.AssertGetObjectEventually(t, book.Class, book.ID)
|
| 65 |
+
}
|
| 66 |
+
for _, multishard := range multishard.Objects() {
|
| 67 |
+
helper.CreateObject(t, multishard)
|
| 68 |
+
helper.AssertGetObjectEventually(t, multishard.Class, multishard.ID)
|
| 69 |
+
}
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
t.Run("sanity checks", func(t *testing.T) {
|
| 73 |
+
concepts := []string{
|
| 74 |
+
"Frank", "Herbert", "Dune", "Book", "Project", "Hail", "Mary",
|
| 75 |
+
"The Lord of the Ice Garden", "Ice Garden", "science", "fiction",
|
| 76 |
+
"fantasy novel", "novelist",
|
| 77 |
+
}
|
| 78 |
+
checkResults := func(query string) {
|
| 79 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 80 |
+
books := result.Get("Get", "Books").AsSlice()
|
| 81 |
+
require.True(t, len(books) > 0)
|
| 82 |
+
results, ok := books[0].(map[string]interface{})
|
| 83 |
+
require.True(t, ok)
|
| 84 |
+
assert.True(t, results["title"] != nil)
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
t.Run("nearText queries", func(t *testing.T) {
|
| 88 |
+
queryTemplate := `
|
| 89 |
+
{
|
| 90 |
+
Get {
|
| 91 |
+
Books(
|
| 92 |
+
nearText: {
|
| 93 |
+
concepts: ["%s"]
|
| 94 |
+
}
|
| 95 |
+
){
|
| 96 |
+
title
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}`
|
| 100 |
+
for _, concept := range concepts {
|
| 101 |
+
checkResults(fmt.Sprintf(queryTemplate, concept))
|
| 102 |
+
}
|
| 103 |
+
})
|
| 104 |
+
t.Run("nearObject queries", func(t *testing.T) {
|
| 105 |
+
queryTemplate := `
|
| 106 |
+
{
|
| 107 |
+
Get {
|
| 108 |
+
Books(
|
| 109 |
+
nearObject: {
|
| 110 |
+
id: "%s"
|
| 111 |
+
}
|
| 112 |
+
){
|
| 113 |
+
title
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}`
|
| 117 |
+
ids := []strfmt.UUID{books.Dune, books.ProjectHailMary, books.TheLordOfTheIceGarden}
|
| 118 |
+
for _, id := range ids {
|
| 119 |
+
checkResults(fmt.Sprintf(queryTemplate, id))
|
| 120 |
+
}
|
| 121 |
+
})
|
| 122 |
+
t.Run("nearVector queries", func(t *testing.T) {
|
| 123 |
+
getVectors := func() []string {
|
| 124 |
+
query := `
|
| 125 |
+
{
|
| 126 |
+
Get {
|
| 127 |
+
Books(limit: 3){ _additional{ vector } }
|
| 128 |
+
}
|
| 129 |
+
}`
|
| 130 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
|
| 131 |
+
books := result.Get("Get", "Books").AsSlice()
|
| 132 |
+
require.True(t, len(books) == 3)
|
| 133 |
+
vectors := make([]string, 3)
|
| 134 |
+
for i := 0; i < 3; i++ {
|
| 135 |
+
results, ok := books[i].(map[string]interface{})
|
| 136 |
+
require.True(t, ok)
|
| 137 |
+
vector, ok := results["_additional"].(map[string]interface{})["vector"].([]interface{})
|
| 138 |
+
require.True(t, ok)
|
| 139 |
+
vec, err := json.Marshal(vector)
|
| 140 |
+
require.Nil(t, err)
|
| 141 |
+
vectors[i] = string(vec)
|
| 142 |
+
}
|
| 143 |
+
return vectors
|
| 144 |
+
}
|
| 145 |
+
vectors := getVectors()
|
| 146 |
+
queryTemplate := `
|
| 147 |
+
{
|
| 148 |
+
Get {
|
| 149 |
+
Books(
|
| 150 |
+
nearVector: {
|
| 151 |
+
vector: %s
|
| 152 |
+
}
|
| 153 |
+
){
|
| 154 |
+
title
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}`
|
| 158 |
+
for _, vector := range vectors {
|
| 159 |
+
checkResults(fmt.Sprintf(queryTemplate, vector))
|
| 160 |
+
}
|
| 161 |
+
})
|
| 162 |
+
t.Run("hybrid queries", func(t *testing.T) {
|
| 163 |
+
queryTemplate := `
|
| 164 |
+
{
|
| 165 |
+
Get {
|
| 166 |
+
Books(
|
| 167 |
+
hybrid: {
|
| 168 |
+
query: "%s"
|
| 169 |
+
}
|
| 170 |
+
){
|
| 171 |
+
title
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}`
|
| 175 |
+
for _, concept := range concepts {
|
| 176 |
+
checkResults(fmt.Sprintf(queryTemplate, concept))
|
| 177 |
+
}
|
| 178 |
+
})
|
| 179 |
+
t.Run("bm25 queries", func(t *testing.T) {
|
| 180 |
+
queryTemplate := `
|
| 181 |
+
{
|
| 182 |
+
Get {
|
| 183 |
+
Books(
|
| 184 |
+
bm25:{
|
| 185 |
+
query: "%s"
|
| 186 |
+
}
|
| 187 |
+
){
|
| 188 |
+
title
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}`
|
| 192 |
+
for _, concept := range []string{"Frank", "Project Hail Mary", "Dune", "Project", "Hail", "Mary"} {
|
| 193 |
+
checkResults(fmt.Sprintf(queryTemplate, concept))
|
| 194 |
+
}
|
| 195 |
+
})
|
| 196 |
+
})
|
| 197 |
+
}
|
| 198 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/many-modules/setup_test.go
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func Test_ManyModules_SingleNode(t *testing.T) {
|
| 24 |
+
ctx := context.Background()
|
| 25 |
+
compose, err := createSingleNodeEnvironment(ctx)
|
| 26 |
+
require.NoError(t, err)
|
| 27 |
+
defer func() {
|
| 28 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 29 |
+
}()
|
| 30 |
+
endpoint := compose.GetWeaviate().URI()
|
| 31 |
+
t.Run("many modules", manyModulesTests(endpoint))
|
| 32 |
+
t.Run("create schema with specific text2vec-openai settings", createSchemaOpenAISanityChecks(endpoint))
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
func Test_ManyModules_SingleNode_Enabled_API_Based_Modules(t *testing.T) {
|
| 36 |
+
ctx := context.Background()
|
| 37 |
+
compose, err := createSingleNodeEnvironmentWithEnabledApiBasedModules(ctx)
|
| 38 |
+
require.NoError(t, err)
|
| 39 |
+
defer func() {
|
| 40 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 41 |
+
}()
|
| 42 |
+
endpoint := compose.GetWeaviate().URI()
|
| 43 |
+
t.Run("api based modules", apiBasedModulesTests(endpoint))
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func Test_ManyModules_Cluster(t *testing.T) {
|
| 47 |
+
ctx := context.Background()
|
| 48 |
+
compose, err := createClusterEnvironment(ctx)
|
| 49 |
+
require.NoError(t, err)
|
| 50 |
+
defer func() {
|
| 51 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 52 |
+
}()
|
| 53 |
+
endpoint := compose.GetWeaviate().URI()
|
| 54 |
+
t.Run("many modules", manyModulesTests(endpoint))
|
| 55 |
+
t.Run("create schema with specific text2vec-openai settings", createSchemaOpenAISanityChecks(endpoint))
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func createSingleNodeEnvironment(ctx context.Context) (compose *docker.DockerCompose, err error) {
|
| 59 |
+
compose, err = composeModules().
|
| 60 |
+
WithWeaviate().
|
| 61 |
+
Start(ctx)
|
| 62 |
+
return
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func createSingleNodeEnvironmentWithEnabledApiBasedModules(ctx context.Context) (compose *docker.DockerCompose, err error) {
|
| 66 |
+
compose, err = composeModules().
|
| 67 |
+
WithWeaviate().
|
| 68 |
+
Start(ctx)
|
| 69 |
+
return
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
func createClusterEnvironment(ctx context.Context) (compose *docker.DockerCompose, err error) {
|
| 73 |
+
compose, err = composeModules().
|
| 74 |
+
WithWeaviateCluster(3).
|
| 75 |
+
Start(ctx)
|
| 76 |
+
return
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
func composeModules() (composeModules *docker.Compose) {
|
| 80 |
+
composeModules = docker.New().
|
| 81 |
+
WithWeaviateEnv("API_BASED_MODULES_DISABLED", "true").
|
| 82 |
+
WithText2VecContextionary().
|
| 83 |
+
WithText2VecTransformers().
|
| 84 |
+
WithText2VecOpenAI(os.Getenv("OPENAI_APIKEY"), os.Getenv("OPENAI_ORGANIZATION"), os.Getenv("AZURE_APIKEY")).
|
| 85 |
+
WithText2VecCohere(os.Getenv("COHERE_APIKEY")).
|
| 86 |
+
WithText2VecVoyageAI(os.Getenv("VOYAGEAI_APIKEY")).
|
| 87 |
+
WithText2VecGoogle(os.Getenv("GOOGLE_APIKEY")).
|
| 88 |
+
WithText2VecHuggingFace(os.Getenv("HUGGINGFACE_APIKEY")).
|
| 89 |
+
WithText2VecAWS(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), os.Getenv("AWS_SESSION_TOKEN")).
|
| 90 |
+
WithGenerativeOpenAI(os.Getenv("OPENAI_APIKEY"), os.Getenv("OPENAI_ORGANIZATION"), os.Getenv("AZURE_APIKEY")).
|
| 91 |
+
WithGenerativeCohere(os.Getenv("COHERE_APIKEY")).
|
| 92 |
+
WithGenerativeGoogle(os.Getenv("GOOGLE_APIKEY")).
|
| 93 |
+
WithGenerativeAWS(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), os.Getenv("AWS_SESSION_TOKEN")).
|
| 94 |
+
WithGenerativeAnyscale().
|
| 95 |
+
WithGenerativeAnthropic(os.Getenv("ANTHROPIC_APIKEY")).
|
| 96 |
+
WithGenerativeFriendliAI(os.Getenv("FRIENDLI_TOKEN")).
|
| 97 |
+
WithQnAOpenAI().
|
| 98 |
+
WithRerankerCohere().
|
| 99 |
+
WithRerankerVoyageAI()
|
| 100 |
+
return
|
| 101 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2multivec-jinaai/multi2multivec_jinaai_test.go
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/vectorindex/hnsw"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
func testMulti2MultivecJinaAI(host string) func(t *testing.T) {
|
| 26 |
+
return func(t *testing.T) {
|
| 27 |
+
helper.SetupClient(host)
|
| 28 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 29 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 30 |
+
// Define class
|
| 31 |
+
vectorizerName := "multi2multivec-jinaai"
|
| 32 |
+
className := "ClipTest"
|
| 33 |
+
class := multimodal.BaseClass(className, false)
|
| 34 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 35 |
+
"clip": {
|
| 36 |
+
Vectorizer: map[string]interface{}{
|
| 37 |
+
vectorizerName: map[string]interface{}{
|
| 38 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
VectorIndexType: "hnsw",
|
| 42 |
+
VectorIndexConfig: hnsw.MultivectorConfig{Enabled: true},
|
| 43 |
+
},
|
| 44 |
+
}
|
| 45 |
+
// create schema
|
| 46 |
+
helper.CreateClass(t, class)
|
| 47 |
+
defer helper.DeleteClass(t, class.Class)
|
| 48 |
+
|
| 49 |
+
t.Run("import data", func(t *testing.T) {
|
| 50 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
t.Run("check objects", func(t *testing.T) {
|
| 54 |
+
multimodal.CheckObjects(t, dataFolderPath, class.Class, nil, []string{"clip"})
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 58 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 59 |
+
require.NoError(t, err)
|
| 60 |
+
targetVector := "clip"
|
| 61 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 62 |
+
nearImage: {
|
| 63 |
+
image: "%s"
|
| 64 |
+
targetVectors: ["%s"]
|
| 65 |
+
}
|
| 66 |
+
`, blob, targetVector)
|
| 67 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 68 |
+
titlePropertyValue := "waterfalls"
|
| 69 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, nil)
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
t.Run("nearText", func(t *testing.T) {
|
| 73 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 74 |
+
titlePropertyValue := "waterfalls"
|
| 75 |
+
targetVector := "clip"
|
| 76 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 77 |
+
nearText: {
|
| 78 |
+
concepts: "%s"
|
| 79 |
+
targetVectors: ["%s"]
|
| 80 |
+
}
|
| 81 |
+
`, titlePropertyValue, targetVector)
|
| 82 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, nil)
|
| 83 |
+
})
|
| 84 |
+
}
|
| 85 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2multivec-jinaai/setup_test.go
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestMulti2VecJinaAI_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("JINAAI_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, JINAAI_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := docker.New().
|
| 30 |
+
WithWeaviate().
|
| 31 |
+
WithMulti2MultivecJinaAI(apiKey).
|
| 32 |
+
Start(ctx)
|
| 33 |
+
require.NoError(t, err)
|
| 34 |
+
defer func() {
|
| 35 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 36 |
+
}()
|
| 37 |
+
endpoint := compose.GetWeaviate().URI()
|
| 38 |
+
|
| 39 |
+
t.Run("multi2multivec-jinaai", testMulti2MultivecJinaAI(endpoint))
|
| 40 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-bind/bind_test.go
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/json"
|
| 16 |
+
"fmt"
|
| 17 |
+
"os"
|
| 18 |
+
"testing"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/books"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func Test_Bind(t *testing.T) {
|
| 28 |
+
helper.SetupClient(os.Getenv(weaviateEndpoint))
|
| 29 |
+
booksClass := books.ClassBindVectorizer()
|
| 30 |
+
helper.CreateClass(t, booksClass)
|
| 31 |
+
defer helper.DeleteClass(t, booksClass.Class)
|
| 32 |
+
|
| 33 |
+
t.Run("add data to Books schema", func(t *testing.T) {
|
| 34 |
+
for _, book := range books.Objects() {
|
| 35 |
+
helper.CreateObject(t, book)
|
| 36 |
+
helper.AssertGetObjectEventually(t, book.Class, book.ID)
|
| 37 |
+
}
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
tests := []struct {
|
| 41 |
+
concept string
|
| 42 |
+
expectedTitle string
|
| 43 |
+
}{
|
| 44 |
+
{
|
| 45 |
+
concept: "Dune",
|
| 46 |
+
expectedTitle: "Dune",
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
concept: "three",
|
| 50 |
+
expectedTitle: "The Lord of the Ice Garden",
|
| 51 |
+
},
|
| 52 |
+
}
|
| 53 |
+
for _, tt := range tests {
|
| 54 |
+
t.Run("query Books data with nearText", func(t *testing.T) {
|
| 55 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, fmt.Sprintf(`
|
| 56 |
+
{
|
| 57 |
+
Get {
|
| 58 |
+
Books(
|
| 59 |
+
limit: 1
|
| 60 |
+
nearText: {
|
| 61 |
+
concepts: ["%v"]
|
| 62 |
+
distance: 0.5
|
| 63 |
+
}
|
| 64 |
+
){
|
| 65 |
+
title
|
| 66 |
+
_additional {
|
| 67 |
+
distance
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
`, tt.concept))
|
| 73 |
+
books := result.Get("Get", "Books").AsSlice()
|
| 74 |
+
require.Len(t, books, 1)
|
| 75 |
+
title := books[0].(map[string]interface{})["title"]
|
| 76 |
+
assert.Equal(t, tt.expectedTitle, title)
|
| 77 |
+
distance := books[0].(map[string]interface{})["_additional"].(map[string]interface{})["distance"].(json.Number)
|
| 78 |
+
assert.NotNil(t, distance)
|
| 79 |
+
dist, err := distance.Float64()
|
| 80 |
+
require.Nil(t, err)
|
| 81 |
+
assert.Greater(t, dist, 0.0)
|
| 82 |
+
})
|
| 83 |
+
}
|
| 84 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-bind/setup_test.go
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/pkg/errors"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const weaviateEndpoint = "WEAVIATE_ENDPOINT"
|
| 24 |
+
|
| 25 |
+
func TestMain(m *testing.M) {
|
| 26 |
+
ctx := context.Background()
|
| 27 |
+
compose, err := docker.New().
|
| 28 |
+
WithWeaviate().
|
| 29 |
+
WithMulti2VecBind().
|
| 30 |
+
Start(ctx)
|
| 31 |
+
if err != nil {
|
| 32 |
+
panic(errors.Wrapf(err, "cannot start"))
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
os.Setenv(weaviateEndpoint, compose.GetWeaviate().URI())
|
| 36 |
+
code := m.Run()
|
| 37 |
+
|
| 38 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 39 |
+
panic(errors.Wrapf(err, "cannot terminate"))
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
os.Exit(code)
|
| 43 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-clip/multi2vec_clip_test.go
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecClip(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
// Define class
|
| 30 |
+
vectorizerName := "multi2vec-clip"
|
| 31 |
+
className := "ClipTest"
|
| 32 |
+
class := multimodal.BaseClass(className, false)
|
| 33 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 34 |
+
"clip": {
|
| 35 |
+
Vectorizer: map[string]interface{}{
|
| 36 |
+
vectorizerName: map[string]interface{}{
|
| 37 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 38 |
+
"vectorizeClassName": false,
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
VectorIndexType: "flat",
|
| 42 |
+
},
|
| 43 |
+
"clip_weights": {
|
| 44 |
+
Vectorizer: map[string]interface{}{
|
| 45 |
+
vectorizerName: map[string]interface{}{
|
| 46 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 47 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 48 |
+
"weights": map[string]interface{}{
|
| 49 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 50 |
+
"imageFields": []interface{}{0.9},
|
| 51 |
+
},
|
| 52 |
+
"vectorizeClassName": false,
|
| 53 |
+
},
|
| 54 |
+
},
|
| 55 |
+
VectorIndexType: "flat",
|
| 56 |
+
},
|
| 57 |
+
}
|
| 58 |
+
// create schema
|
| 59 |
+
helper.CreateClass(t, class)
|
| 60 |
+
defer helper.DeleteClass(t, class.Class)
|
| 61 |
+
|
| 62 |
+
t.Run("import data", func(t *testing.T) {
|
| 63 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 64 |
+
})
|
| 65 |
+
|
| 66 |
+
t.Run("check objects", func(t *testing.T) {
|
| 67 |
+
multimodal.CheckObjects(t, dataFolderPath, class.Class, []string{"clip", "clip_weights"}, nil)
|
| 68 |
+
})
|
| 69 |
+
|
| 70 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 71 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 72 |
+
require.NoError(t, err)
|
| 73 |
+
targetVector := "clip"
|
| 74 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 75 |
+
nearImage: {
|
| 76 |
+
image: "%s"
|
| 77 |
+
targetVectors: ["%s"]
|
| 78 |
+
}
|
| 79 |
+
`, blob, targetVector)
|
| 80 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 81 |
+
titlePropertyValue := "waterfalls"
|
| 82 |
+
targetVectors := map[string]int{
|
| 83 |
+
"clip": 512,
|
| 84 |
+
"clip_weights": 512,
|
| 85 |
+
}
|
| 86 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 87 |
+
})
|
| 88 |
+
}
|
| 89 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-clip/setup_test.go
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
func TestMulti2VecClip_SingleNode(t *testing.T) {
|
| 23 |
+
ctx := context.Background()
|
| 24 |
+
compose, err := docker.New().
|
| 25 |
+
WithWeaviate().
|
| 26 |
+
WithMulti2VecCLIP().
|
| 27 |
+
Start(ctx)
|
| 28 |
+
require.NoError(t, err)
|
| 29 |
+
defer func() {
|
| 30 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 31 |
+
}()
|
| 32 |
+
endpoint := compose.GetWeaviate().URI()
|
| 33 |
+
|
| 34 |
+
t.Run("multi2vec-clip", testMulti2VecClip(endpoint))
|
| 35 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-cohere/multi2vec_cohere_test.go
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecCohere(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
// Define class
|
| 30 |
+
vectorizerName := "multi2vec-cohere"
|
| 31 |
+
className := "CohereClipTest"
|
| 32 |
+
class := multimodal.BaseClass(className, false)
|
| 33 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 34 |
+
"clip": {
|
| 35 |
+
Vectorizer: map[string]interface{}{
|
| 36 |
+
vectorizerName: map[string]interface{}{
|
| 37 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 38 |
+
"vectorizeClassName": false,
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
VectorIndexType: "flat",
|
| 42 |
+
},
|
| 43 |
+
"clip_weights": {
|
| 44 |
+
Vectorizer: map[string]interface{}{
|
| 45 |
+
vectorizerName: map[string]interface{}{
|
| 46 |
+
"model": "embed-english-light-v3.0",
|
| 47 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 48 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 49 |
+
"weights": map[string]interface{}{
|
| 50 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 51 |
+
"imageFields": []interface{}{0.9},
|
| 52 |
+
},
|
| 53 |
+
"vectorizeClassName": false,
|
| 54 |
+
},
|
| 55 |
+
},
|
| 56 |
+
VectorIndexType: "flat",
|
| 57 |
+
},
|
| 58 |
+
}
|
| 59 |
+
// create schema
|
| 60 |
+
helper.CreateClass(t, class)
|
| 61 |
+
defer helper.DeleteClass(t, class.Class)
|
| 62 |
+
|
| 63 |
+
t.Run("import data", func(t *testing.T) {
|
| 64 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 65 |
+
})
|
| 66 |
+
|
| 67 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 68 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 69 |
+
require.NoError(t, err)
|
| 70 |
+
targetVector := "clip"
|
| 71 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 72 |
+
nearImage: {
|
| 73 |
+
image: "%s"
|
| 74 |
+
targetVectors: ["%s"]
|
| 75 |
+
}
|
| 76 |
+
`, blob, targetVector)
|
| 77 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 78 |
+
titlePropertyValue := "waterfalls"
|
| 79 |
+
targetVectors := map[string]int{
|
| 80 |
+
"clip": 1024,
|
| 81 |
+
"clip_weights": 384,
|
| 82 |
+
}
|
| 83 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 84 |
+
})
|
| 85 |
+
}
|
| 86 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-cohere/setup_test.go
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestMulti2VecCohere_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("COHERE_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, COHERE_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpoint := compose.GetWeaviate().URI()
|
| 35 |
+
|
| 36 |
+
t.Run("multi2vec-cohere", testMulti2VecCohere(endpoint))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 40 |
+
) (compose *docker.DockerCompose, err error) {
|
| 41 |
+
compose, err = composeModules(apiKey).
|
| 42 |
+
WithWeaviate().
|
| 43 |
+
Start(ctx)
|
| 44 |
+
return
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 48 |
+
composeModules = docker.New().
|
| 49 |
+
WithMulti2VecCohere(apiKey)
|
| 50 |
+
return
|
| 51 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-google/multi2vec_google_test.go
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecGoogle(host, gcpProject, location, vectorizerName string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
// Define class
|
| 30 |
+
className := "GoogleClipTest"
|
| 31 |
+
class := multimodal.BaseClass(className, true)
|
| 32 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 33 |
+
"clip_google": {
|
| 34 |
+
Vectorizer: map[string]interface{}{
|
| 35 |
+
vectorizerName: map[string]interface{}{
|
| 36 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 37 |
+
"vectorizeClassName": false,
|
| 38 |
+
"location": location,
|
| 39 |
+
"projectId": gcpProject,
|
| 40 |
+
},
|
| 41 |
+
},
|
| 42 |
+
VectorIndexType: "flat",
|
| 43 |
+
},
|
| 44 |
+
"clip_google_128": {
|
| 45 |
+
Vectorizer: map[string]interface{}{
|
| 46 |
+
vectorizerName: map[string]interface{}{
|
| 47 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 48 |
+
"vectorizeClassName": false,
|
| 49 |
+
"location": location,
|
| 50 |
+
"projectId": gcpProject,
|
| 51 |
+
"dimensions": 128,
|
| 52 |
+
},
|
| 53 |
+
},
|
| 54 |
+
VectorIndexType: "flat",
|
| 55 |
+
},
|
| 56 |
+
"clip_google_256": {
|
| 57 |
+
Vectorizer: map[string]interface{}{
|
| 58 |
+
vectorizerName: map[string]interface{}{
|
| 59 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 60 |
+
"vectorizeClassName": false,
|
| 61 |
+
"location": location,
|
| 62 |
+
"projectId": gcpProject,
|
| 63 |
+
"dimensions": 256,
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
VectorIndexType: "flat",
|
| 67 |
+
},
|
| 68 |
+
"clip_google_video": {
|
| 69 |
+
Vectorizer: map[string]interface{}{
|
| 70 |
+
vectorizerName: map[string]interface{}{
|
| 71 |
+
"videoFields": []interface{}{multimodal.PropertyVideo},
|
| 72 |
+
"vectorizeClassName": false,
|
| 73 |
+
"location": location,
|
| 74 |
+
"projectId": gcpProject,
|
| 75 |
+
},
|
| 76 |
+
},
|
| 77 |
+
VectorIndexType: "flat",
|
| 78 |
+
},
|
| 79 |
+
"clip_google_weights": {
|
| 80 |
+
Vectorizer: map[string]interface{}{
|
| 81 |
+
vectorizerName: map[string]interface{}{
|
| 82 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 83 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 84 |
+
"weights": map[string]interface{}{
|
| 85 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 86 |
+
"imageFields": []interface{}{0.9},
|
| 87 |
+
},
|
| 88 |
+
"vectorizeClassName": false,
|
| 89 |
+
"location": location,
|
| 90 |
+
"projectId": gcpProject,
|
| 91 |
+
"dimensions": 512,
|
| 92 |
+
},
|
| 93 |
+
},
|
| 94 |
+
VectorIndexType: "flat",
|
| 95 |
+
},
|
| 96 |
+
}
|
| 97 |
+
// create schema
|
| 98 |
+
helper.CreateClass(t, class)
|
| 99 |
+
defer helper.DeleteClass(t, class.Class)
|
| 100 |
+
|
| 101 |
+
t.Run("import data", func(t *testing.T) {
|
| 102 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, true)
|
| 103 |
+
})
|
| 104 |
+
|
| 105 |
+
t.Run("check objects", func(t *testing.T) {
|
| 106 |
+
vectorNames := []string{"clip_google", "clip_google_128", "clip_google_256", "clip_google_video", "clip_google_weights"}
|
| 107 |
+
multimodal.CheckObjects(t, dataFolderPath, class.Class, vectorNames, nil)
|
| 108 |
+
})
|
| 109 |
+
|
| 110 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 111 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 112 |
+
require.NoError(t, err)
|
| 113 |
+
targetVector := "clip_google"
|
| 114 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 115 |
+
nearImage: {
|
| 116 |
+
image: "%s"
|
| 117 |
+
targetVectors: ["%s"]
|
| 118 |
+
}
|
| 119 |
+
`, blob, targetVector)
|
| 120 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 121 |
+
titlePropertyValue := "waterfalls"
|
| 122 |
+
targetVectors := map[string]int{
|
| 123 |
+
"clip_google": 1408,
|
| 124 |
+
"clip_google_128": 128,
|
| 125 |
+
"clip_google_256": 256,
|
| 126 |
+
"clip_google_video": 1408,
|
| 127 |
+
"clip_google_weights": 512,
|
| 128 |
+
}
|
| 129 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 130 |
+
})
|
| 131 |
+
|
| 132 |
+
t.Run("nearVideo", func(t *testing.T) {
|
| 133 |
+
blob, err := multimodal.GetVideoBlob(dataFolderPath, 2)
|
| 134 |
+
require.NoError(t, err)
|
| 135 |
+
targetVector := "clip_google_video"
|
| 136 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 137 |
+
nearVideo: {
|
| 138 |
+
video: "%s"
|
| 139 |
+
targetVectors: ["%s"]
|
| 140 |
+
}
|
| 141 |
+
`, blob, targetVector)
|
| 142 |
+
titleProperty := multimodal.PropertyVideoTitle
|
| 143 |
+
titlePropertyValue := "dog"
|
| 144 |
+
targetVectors := map[string]int{
|
| 145 |
+
"clip_google": 1408,
|
| 146 |
+
"clip_google_128": 128,
|
| 147 |
+
"clip_google_256": 256,
|
| 148 |
+
"clip_google_video": 1408,
|
| 149 |
+
"clip_google_weights": 512,
|
| 150 |
+
}
|
| 151 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 152 |
+
})
|
| 153 |
+
}
|
| 154 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-google/setup_test.go
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const (
|
| 24 |
+
location = "us-central1"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func TestMulti2VecGoogle_SingleNode(t *testing.T) {
|
| 28 |
+
gcpProject := os.Getenv("GCP_PROJECT")
|
| 29 |
+
if gcpProject == "" {
|
| 30 |
+
t.Skip("skipping, GCP_PROJECT environment variable not present")
|
| 31 |
+
}
|
| 32 |
+
googleApiKey := os.Getenv("GOOGLE_APIKEY")
|
| 33 |
+
if googleApiKey == "" {
|
| 34 |
+
t.Skip("skipping, GOOGLE_APIKEY environment variable not present")
|
| 35 |
+
}
|
| 36 |
+
ctx := context.Background()
|
| 37 |
+
compose, err := createSingleNodeEnvironment(ctx, googleApiKey)
|
| 38 |
+
require.NoError(t, err)
|
| 39 |
+
defer func() {
|
| 40 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 41 |
+
}()
|
| 42 |
+
endpoint := compose.GetWeaviate().URI()
|
| 43 |
+
|
| 44 |
+
t.Run("multi2vec-google", testMulti2VecGoogle(endpoint, gcpProject, location, "multi2vec-google"))
|
| 45 |
+
t.Run("multi2vec-palm", testMulti2VecGoogle(endpoint, gcpProject, location, "multi2vec-palm"))
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
func createSingleNodeEnvironment(ctx context.Context, googleApiKey string,
|
| 49 |
+
) (compose *docker.DockerCompose, err error) {
|
| 50 |
+
compose, err = composeModules(googleApiKey).
|
| 51 |
+
WithWeaviate().
|
| 52 |
+
Start(ctx)
|
| 53 |
+
return
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func composeModules(googleApiKey string) (composeModules *docker.Compose) {
|
| 57 |
+
composeModules = docker.New().
|
| 58 |
+
WithMulti2VecGoogle(googleApiKey)
|
| 59 |
+
return
|
| 60 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-jinaai/multi2vec_jinaai_test.go
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecJinaAI(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
tests := []struct {
|
| 30 |
+
name string
|
| 31 |
+
model string
|
| 32 |
+
clipWeightsDimensions int
|
| 33 |
+
}{
|
| 34 |
+
{
|
| 35 |
+
name: "default settings",
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
name: "jina-embeddings-v4",
|
| 39 |
+
model: "jina-embeddings-v4",
|
| 40 |
+
clipWeightsDimensions: 2048,
|
| 41 |
+
},
|
| 42 |
+
}
|
| 43 |
+
for _, tt := range tests {
|
| 44 |
+
t.Run(tt.name, func(t *testing.T) {
|
| 45 |
+
// Define settings
|
| 46 |
+
clipSettings := map[string]interface{}{
|
| 47 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 48 |
+
"vectorizeClassName": false,
|
| 49 |
+
"dimensions": 600,
|
| 50 |
+
}
|
| 51 |
+
if tt.model != "" {
|
| 52 |
+
clipSettings["model"] = tt.model
|
| 53 |
+
}
|
| 54 |
+
clipWeightsSettings := map[string]interface{}{
|
| 55 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 56 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 57 |
+
"weights": map[string]interface{}{
|
| 58 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 59 |
+
"imageFields": []interface{}{0.9},
|
| 60 |
+
},
|
| 61 |
+
"vectorizeClassName": false,
|
| 62 |
+
}
|
| 63 |
+
if tt.model != "" {
|
| 64 |
+
clipWeightsSettings["model"] = tt.model
|
| 65 |
+
}
|
| 66 |
+
if tt.clipWeightsDimensions > 0 {
|
| 67 |
+
clipWeightsSettings["dimensions"] = tt.clipWeightsDimensions
|
| 68 |
+
}
|
| 69 |
+
// Define class
|
| 70 |
+
vectorizerName := "multi2vec-jinaai"
|
| 71 |
+
className := "ClipTest"
|
| 72 |
+
class := multimodal.BaseClass(className, false)
|
| 73 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 74 |
+
"clip": {
|
| 75 |
+
Vectorizer: map[string]interface{}{
|
| 76 |
+
vectorizerName: clipSettings,
|
| 77 |
+
},
|
| 78 |
+
VectorIndexType: "flat",
|
| 79 |
+
},
|
| 80 |
+
"clip_weights": {
|
| 81 |
+
Vectorizer: map[string]interface{}{
|
| 82 |
+
vectorizerName: clipWeightsSettings,
|
| 83 |
+
},
|
| 84 |
+
VectorIndexType: "flat",
|
| 85 |
+
},
|
| 86 |
+
}
|
| 87 |
+
// create schema
|
| 88 |
+
helper.CreateClass(t, class)
|
| 89 |
+
defer helper.DeleteClass(t, class.Class)
|
| 90 |
+
|
| 91 |
+
t.Run("import data", func(t *testing.T) {
|
| 92 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 93 |
+
})
|
| 94 |
+
|
| 95 |
+
t.Run("check objects", func(t *testing.T) {
|
| 96 |
+
multimodal.CheckObjects(t, dataFolderPath, class.Class, []string{"clip", "clip_weights"}, nil)
|
| 97 |
+
})
|
| 98 |
+
|
| 99 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 100 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 101 |
+
require.NoError(t, err)
|
| 102 |
+
targetVector := "clip"
|
| 103 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 104 |
+
nearImage: {
|
| 105 |
+
image: "%s"
|
| 106 |
+
targetVectors: ["%s"]
|
| 107 |
+
}
|
| 108 |
+
`, blob, targetVector)
|
| 109 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 110 |
+
titlePropertyValue := "waterfalls"
|
| 111 |
+
clipWeightsDimensions := 1024
|
| 112 |
+
if tt.clipWeightsDimensions > 0 {
|
| 113 |
+
clipWeightsDimensions = tt.clipWeightsDimensions
|
| 114 |
+
}
|
| 115 |
+
targetVectors := map[string]int{
|
| 116 |
+
"clip": 600,
|
| 117 |
+
"clip_weights": clipWeightsDimensions,
|
| 118 |
+
}
|
| 119 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 120 |
+
})
|
| 121 |
+
})
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-jinaai/setup_test.go
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"os"
|
| 18 |
+
"testing"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
func TestMulti2VecJinaAI_SingleNode(t *testing.T) {
|
| 26 |
+
apiKey := os.Getenv("JINAAI_APIKEY")
|
| 27 |
+
if apiKey == "" {
|
| 28 |
+
t.Skip("skipping, JINAAI_APIKEY environment variable not present")
|
| 29 |
+
}
|
| 30 |
+
ctx := context.Background()
|
| 31 |
+
compose, err := docker.New().
|
| 32 |
+
WithWeaviate().
|
| 33 |
+
WithMulti2VecJinaAI(apiKey).
|
| 34 |
+
WithWeaviateEnv("MODULES_CLIENT_TIMEOUT", fmt.Sprintf("%.0fs", multimodal.DefaultTimeout.Seconds())).
|
| 35 |
+
Start(ctx)
|
| 36 |
+
require.NoError(t, err)
|
| 37 |
+
defer func() {
|
| 38 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 39 |
+
}()
|
| 40 |
+
endpoint := compose.GetWeaviate().URI()
|
| 41 |
+
|
| 42 |
+
t.Run("multi2vec-jinaai", testMulti2VecJinaAI(endpoint))
|
| 43 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-nvidia/multi2vec_nvidia_test.go
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecNvidia(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
// Define class
|
| 30 |
+
vectorizerName := "multi2vec-nvidia"
|
| 31 |
+
className := "NvidiaClipTest"
|
| 32 |
+
class := multimodal.BaseClass(className, false)
|
| 33 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 34 |
+
"clip": {
|
| 35 |
+
Vectorizer: map[string]interface{}{
|
| 36 |
+
vectorizerName: map[string]interface{}{
|
| 37 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 38 |
+
"vectorizeClassName": false,
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
VectorIndexType: "flat",
|
| 42 |
+
},
|
| 43 |
+
"clip_weights": {
|
| 44 |
+
Vectorizer: map[string]interface{}{
|
| 45 |
+
vectorizerName: map[string]interface{}{
|
| 46 |
+
"model": "nvidia/nvclip",
|
| 47 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 48 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 49 |
+
"weights": map[string]interface{}{
|
| 50 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 51 |
+
"imageFields": []interface{}{0.9},
|
| 52 |
+
},
|
| 53 |
+
"vectorizeClassName": false,
|
| 54 |
+
},
|
| 55 |
+
},
|
| 56 |
+
VectorIndexType: "flat",
|
| 57 |
+
},
|
| 58 |
+
}
|
| 59 |
+
// create schema
|
| 60 |
+
helper.CreateClass(t, class)
|
| 61 |
+
defer helper.DeleteClass(t, class.Class)
|
| 62 |
+
|
| 63 |
+
t.Run("import data", func(t *testing.T) {
|
| 64 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 65 |
+
})
|
| 66 |
+
|
| 67 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 68 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 69 |
+
require.NoError(t, err)
|
| 70 |
+
targetVector := "clip"
|
| 71 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 72 |
+
nearImage: {
|
| 73 |
+
image: "%s"
|
| 74 |
+
targetVectors: ["%s"]
|
| 75 |
+
}
|
| 76 |
+
`, blob, targetVector)
|
| 77 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 78 |
+
titlePropertyValue := "waterfalls"
|
| 79 |
+
targetVectors := map[string]int{
|
| 80 |
+
"clip": 1024,
|
| 81 |
+
"clip_weights": 1024,
|
| 82 |
+
}
|
| 83 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 84 |
+
})
|
| 85 |
+
}
|
| 86 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-nvidia/setup_test.go
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestMulti2VecNvidia(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("NVIDIA_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, NVIDIA_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpoint := compose.GetWeaviate().URI()
|
| 35 |
+
|
| 36 |
+
t.Run("multi2vec-nvidia", testMulti2VecNvidia(endpoint))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 40 |
+
) (compose *docker.DockerCompose, err error) {
|
| 41 |
+
compose, err = composeModules(apiKey).
|
| 42 |
+
WithWeaviate().
|
| 43 |
+
Start(ctx)
|
| 44 |
+
return
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 48 |
+
composeModules = docker.New().
|
| 49 |
+
WithMulti2VecNvidia(apiKey)
|
| 50 |
+
return
|
| 51 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-voyageai/multi2vec_voyageai_test.go
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"fmt"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/stretchr/testify/require"
|
| 19 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 20 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 21 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/multimodal"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func testMulti2VecVoyageAI(host string) func(t *testing.T) {
|
| 25 |
+
return func(t *testing.T) {
|
| 26 |
+
helper.SetupClient(host)
|
| 27 |
+
// Define path to test/helper/sample-schema/multimodal/data folder
|
| 28 |
+
dataFolderPath := "../../../test/helper/sample-schema/multimodal/data"
|
| 29 |
+
// Define class
|
| 30 |
+
vectorizerName := "multi2vec-voyageai"
|
| 31 |
+
className := "VoyageAIClipTest"
|
| 32 |
+
class := multimodal.BaseClass(className, false)
|
| 33 |
+
class.VectorConfig = map[string]models.VectorConfig{
|
| 34 |
+
"clip": {
|
| 35 |
+
Vectorizer: map[string]interface{}{
|
| 36 |
+
vectorizerName: map[string]interface{}{
|
| 37 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 38 |
+
"vectorizeClassName": false,
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
VectorIndexType: "flat",
|
| 42 |
+
},
|
| 43 |
+
"clip_weights": {
|
| 44 |
+
Vectorizer: map[string]interface{}{
|
| 45 |
+
vectorizerName: map[string]interface{}{
|
| 46 |
+
"model": "voyage-multimodal-3",
|
| 47 |
+
"textFields": []interface{}{multimodal.PropertyImageTitle, multimodal.PropertyImageDescription},
|
| 48 |
+
"imageFields": []interface{}{multimodal.PropertyImage},
|
| 49 |
+
"weights": map[string]interface{}{
|
| 50 |
+
"textFields": []interface{}{0.05, 0.05},
|
| 51 |
+
"imageFields": []interface{}{0.9},
|
| 52 |
+
},
|
| 53 |
+
"vectorizeClassName": false,
|
| 54 |
+
},
|
| 55 |
+
},
|
| 56 |
+
VectorIndexType: "flat",
|
| 57 |
+
},
|
| 58 |
+
}
|
| 59 |
+
// create schema
|
| 60 |
+
helper.CreateClass(t, class)
|
| 61 |
+
defer helper.DeleteClass(t, class.Class)
|
| 62 |
+
|
| 63 |
+
t.Run("import data", func(t *testing.T) {
|
| 64 |
+
multimodal.InsertObjects(t, dataFolderPath, class.Class, false)
|
| 65 |
+
})
|
| 66 |
+
|
| 67 |
+
t.Run("nearImage", func(t *testing.T) {
|
| 68 |
+
blob, err := multimodal.GetImageBlob(dataFolderPath, 2)
|
| 69 |
+
require.NoError(t, err)
|
| 70 |
+
targetVector := "clip"
|
| 71 |
+
nearMediaArgument := fmt.Sprintf(`
|
| 72 |
+
nearImage: {
|
| 73 |
+
image: "%s"
|
| 74 |
+
targetVectors: ["%s"]
|
| 75 |
+
}
|
| 76 |
+
`, blob, targetVector)
|
| 77 |
+
titleProperty := multimodal.PropertyImageTitle
|
| 78 |
+
titlePropertyValue := "waterfalls"
|
| 79 |
+
targetVectors := map[string]int{
|
| 80 |
+
"clip": 1024,
|
| 81 |
+
"clip_weights": 1024,
|
| 82 |
+
}
|
| 83 |
+
multimodal.TestQuery(t, class.Class, nearMediaArgument, titleProperty, titlePropertyValue, targetVectors)
|
| 84 |
+
})
|
| 85 |
+
}
|
| 86 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/multi2vec-voyageai/setup_test.go
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 tests
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/stretchr/testify/require"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
func TestMulti2VecVoyageAI_SingleNode(t *testing.T) {
|
| 24 |
+
apiKey := os.Getenv("VOYAGEAI_APIKEY")
|
| 25 |
+
if apiKey == "" {
|
| 26 |
+
t.Skip("skipping, VOYAGEAI_APIKEY environment variable not present")
|
| 27 |
+
}
|
| 28 |
+
ctx := context.Background()
|
| 29 |
+
compose, err := createSingleNodeEnvironment(ctx, apiKey)
|
| 30 |
+
require.NoError(t, err)
|
| 31 |
+
defer func() {
|
| 32 |
+
require.NoError(t, compose.Terminate(ctx))
|
| 33 |
+
}()
|
| 34 |
+
endpoint := compose.GetWeaviate().URI()
|
| 35 |
+
|
| 36 |
+
t.Run("multi2vec-voyageai", testMulti2VecVoyageAI(endpoint))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func createSingleNodeEnvironment(ctx context.Context, apiKey string,
|
| 40 |
+
) (compose *docker.DockerCompose, err error) {
|
| 41 |
+
compose, err = composeModules(apiKey).
|
| 42 |
+
WithWeaviate().
|
| 43 |
+
Start(ctx)
|
| 44 |
+
return
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func composeModules(apiKey string) (composeModules *docker.Compose) {
|
| 48 |
+
composeModules = docker.New().
|
| 49 |
+
WithMulti2VecVoyageAI(apiKey)
|
| 50 |
+
return
|
| 51 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/misocnfigured_test.go
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"slices"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/require"
|
| 21 |
+
|
| 22 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 23 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func Test_DeleteTenantsWhileMisconfigured(t *testing.T) {
|
| 28 |
+
t.Run("misconfigure offload, create tenant, delete tenant", func(t *testing.T) {
|
| 29 |
+
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
| 30 |
+
defer cancel()
|
| 31 |
+
t.Log("pre-instance env setup")
|
| 32 |
+
t.Setenv(envS3AccessKey, "the_wrong_Key")
|
| 33 |
+
t.Setenv(envS3SecretKey, "the_wrong_Key")
|
| 34 |
+
|
| 35 |
+
compose, err := docker.New().
|
| 36 |
+
WithOffloadS3("not-existing-bucket", "us-west-1").
|
| 37 |
+
WithWeaviateEnv("OFFLOAD_TIMEOUT", "120").
|
| 38 |
+
WithWeaviateEnv("OFFLOAD_S3_ENDPOINT", "http://test-minio:0000"). // wrong port configured
|
| 39 |
+
WithoutWeaviateEnvs("OFFLOAD_S3_BUCKET_AUTO_CREATE").
|
| 40 |
+
With3NodeCluster().
|
| 41 |
+
Start(ctx)
|
| 42 |
+
require.Nil(t, err)
|
| 43 |
+
|
| 44 |
+
defer func() {
|
| 45 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 46 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 47 |
+
}
|
| 48 |
+
}()
|
| 49 |
+
|
| 50 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 51 |
+
|
| 52 |
+
className := "MultiTenantClass"
|
| 53 |
+
testClass := models.Class{
|
| 54 |
+
Class: className,
|
| 55 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 56 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 57 |
+
Enabled: true,
|
| 58 |
+
},
|
| 59 |
+
}
|
| 60 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 61 |
+
helper.CreateClass(t, &testClass)
|
| 62 |
+
})
|
| 63 |
+
|
| 64 |
+
defer func() {
|
| 65 |
+
helper.DeleteClass(t, className)
|
| 66 |
+
}()
|
| 67 |
+
|
| 68 |
+
tenantNames := []string{
|
| 69 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 70 |
+
}
|
| 71 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 72 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 73 |
+
for i := range tenants {
|
| 74 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i], ActivityStatus: models.TenantActivityStatusACTIVE}
|
| 75 |
+
}
|
| 76 |
+
helper.CreateTenants(t, className, tenants)
|
| 77 |
+
})
|
| 78 |
+
|
| 79 |
+
t.Run("delete tenant 1 in time manner", func(t *testing.T) {
|
| 80 |
+
customCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
| 81 |
+
defer cancel()
|
| 82 |
+
|
| 83 |
+
errChan := make(chan error, 1)
|
| 84 |
+
go func() {
|
| 85 |
+
errChan <- helper.DeleteTenantsWithContext(t, customCtx, className, []string{tenantNames[0]})
|
| 86 |
+
}()
|
| 87 |
+
|
| 88 |
+
select {
|
| 89 |
+
case err := <-errChan:
|
| 90 |
+
require.NoError(t, err, "got error while expecting none")
|
| 91 |
+
|
| 92 |
+
case <-customCtx.Done():
|
| 93 |
+
require.FailNowf(t, "operation took longer than timeout: %v", customCtx.Err().Error())
|
| 94 |
+
}
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
t.Run("get tenants after deletion", func(t *testing.T) {
|
| 98 |
+
response, err := helper.GetTenants(t, className)
|
| 99 |
+
require.NoError(t, err)
|
| 100 |
+
returnedTenantsNames := []string{}
|
| 101 |
+
for _, tn := range response.Payload {
|
| 102 |
+
returnedTenantsNames = append(returnedTenantsNames, tn.Name)
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
slices.Sort(tenantNames[1:])
|
| 106 |
+
slices.Sort(returnedTenantsNames)
|
| 107 |
+
require.Equal(t, tenantNames[1:], returnedTenantsNames, "expected tenant to be deleted but it's not")
|
| 108 |
+
})
|
| 109 |
+
})
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
func Test_DeleteTenantsWhileProviderIsDown(t *testing.T) {
|
| 113 |
+
t.Run("offload, create tenant, minio down, delete tenant", func(t *testing.T) {
|
| 114 |
+
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
| 115 |
+
defer cancel()
|
| 116 |
+
t.Log("pre-instance env setup")
|
| 117 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 118 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 119 |
+
|
| 120 |
+
compose, err := docker.New().
|
| 121 |
+
WithOffloadS3("not-existing-bucket", "us-west-1").
|
| 122 |
+
WithWeaviateEnv("OFFLOAD_TIMEOUT", "120").
|
| 123 |
+
WithoutWeaviateEnvs("OFFLOAD_S3_BUCKET_AUTO_CREATE").
|
| 124 |
+
With3NodeCluster().
|
| 125 |
+
Start(ctx)
|
| 126 |
+
require.Nil(t, err)
|
| 127 |
+
|
| 128 |
+
defer func() {
|
| 129 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 130 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 131 |
+
}
|
| 132 |
+
}()
|
| 133 |
+
|
| 134 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 135 |
+
|
| 136 |
+
className := "MultiTenantClass"
|
| 137 |
+
testClass := models.Class{
|
| 138 |
+
Class: className,
|
| 139 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 140 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 141 |
+
Enabled: true,
|
| 142 |
+
},
|
| 143 |
+
}
|
| 144 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 145 |
+
helper.CreateClass(t, &testClass)
|
| 146 |
+
})
|
| 147 |
+
|
| 148 |
+
defer func() {
|
| 149 |
+
helper.DeleteClass(t, className)
|
| 150 |
+
}()
|
| 151 |
+
|
| 152 |
+
tenantNames := []string{
|
| 153 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 154 |
+
}
|
| 155 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 156 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 157 |
+
for i := range tenants {
|
| 158 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i], ActivityStatus: models.TenantActivityStatusACTIVE}
|
| 159 |
+
}
|
| 160 |
+
helper.CreateTenants(t, className, tenants)
|
| 161 |
+
})
|
| 162 |
+
t.Run("stop minio", func(t *testing.T) {
|
| 163 |
+
require.NoError(t, compose.StopMinIO(ctx))
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
+
t.Run("delete tenant 1 in time manner", func(t *testing.T) {
|
| 167 |
+
customCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
| 168 |
+
defer cancel()
|
| 169 |
+
|
| 170 |
+
errChan := make(chan error, 1)
|
| 171 |
+
go func() {
|
| 172 |
+
errChan <- helper.DeleteTenantsWithContext(t, customCtx, className, []string{tenantNames[0]})
|
| 173 |
+
}()
|
| 174 |
+
|
| 175 |
+
select {
|
| 176 |
+
case err := <-errChan:
|
| 177 |
+
require.NoError(t, err, "got error while expecting none")
|
| 178 |
+
|
| 179 |
+
case <-customCtx.Done():
|
| 180 |
+
require.FailNowf(t, "operation took longer than timeout: %v", customCtx.Err().Error())
|
| 181 |
+
}
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
t.Run("get tenants after deletion", func(t *testing.T) {
|
| 185 |
+
response, err := helper.GetTenants(t, className)
|
| 186 |
+
require.NoError(t, err)
|
| 187 |
+
returnedTenantsNames := []string{}
|
| 188 |
+
for _, tn := range response.Payload {
|
| 189 |
+
returnedTenantsNames = append(returnedTenantsNames, tn.Name)
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
slices.Sort(tenantNames[1:])
|
| 193 |
+
slices.Sort(returnedTenantsNames)
|
| 194 |
+
require.Equal(t, tenantNames[1:], returnedTenantsNames, "expected tenant to be deleted but it's not")
|
| 195 |
+
})
|
| 196 |
+
})
|
| 197 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offlad_delete_test.go
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"strings"
|
| 18 |
+
"testing"
|
| 19 |
+
"time"
|
| 20 |
+
|
| 21 |
+
"github.com/minio/minio-go/v7"
|
| 22 |
+
"github.com/minio/minio-go/v7/pkg/credentials"
|
| 23 |
+
"github.com/stretchr/testify/assert"
|
| 24 |
+
"github.com/stretchr/testify/require"
|
| 25 |
+
"github.com/weaviate/weaviate/cluster/types"
|
| 26 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 27 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 28 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 29 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
func Test_DeleteClassS3Journey(t *testing.T) {
|
| 33 |
+
t.Run("delete class, deleting frozen tenants", func(t *testing.T) {
|
| 34 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 35 |
+
defer cancel()
|
| 36 |
+
|
| 37 |
+
t.Log("pre-instance env setup")
|
| 38 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 39 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 40 |
+
|
| 41 |
+
compose, err := docker.New().
|
| 42 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 43 |
+
WithText2VecContextionary().
|
| 44 |
+
With3NodeCluster().
|
| 45 |
+
Start(ctx)
|
| 46 |
+
require.Nil(t, err)
|
| 47 |
+
|
| 48 |
+
defer func() {
|
| 49 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 50 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 51 |
+
}
|
| 52 |
+
}()
|
| 53 |
+
|
| 54 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 55 |
+
|
| 56 |
+
className := "MultiTenantClass"
|
| 57 |
+
testClass := models.Class{
|
| 58 |
+
Class: className,
|
| 59 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 60 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 61 |
+
Enabled: true,
|
| 62 |
+
},
|
| 63 |
+
Properties: []*models.Property{
|
| 64 |
+
{
|
| 65 |
+
Name: "name",
|
| 66 |
+
DataType: schema.DataTypeText.PropString(),
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
}
|
| 70 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 71 |
+
helper.CreateClass(t, &testClass)
|
| 72 |
+
})
|
| 73 |
+
|
| 74 |
+
tenantNames := []string{
|
| 75 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 76 |
+
}
|
| 77 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 78 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 79 |
+
for i := range tenants {
|
| 80 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 81 |
+
}
|
| 82 |
+
helper.CreateTenants(t, className, tenants)
|
| 83 |
+
})
|
| 84 |
+
|
| 85 |
+
tenantObjects := []*models.Object{
|
| 86 |
+
{
|
| 87 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 88 |
+
Class: className,
|
| 89 |
+
Properties: map[string]interface{}{
|
| 90 |
+
"name": tenantNames[0],
|
| 91 |
+
},
|
| 92 |
+
Tenant: tenantNames[0],
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 96 |
+
Class: className,
|
| 97 |
+
Properties: map[string]interface{}{
|
| 98 |
+
"name": tenantNames[0],
|
| 99 |
+
},
|
| 100 |
+
Tenant: tenantNames[0],
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 104 |
+
Class: className,
|
| 105 |
+
Properties: map[string]interface{}{
|
| 106 |
+
"name": tenantNames[0],
|
| 107 |
+
},
|
| 108 |
+
Tenant: tenantNames[0],
|
| 109 |
+
},
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 113 |
+
for _, obj := range tenantObjects {
|
| 114 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 115 |
+
}
|
| 116 |
+
})
|
| 117 |
+
|
| 118 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 119 |
+
for _, obj := range tenantObjects {
|
| 120 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[0])
|
| 121 |
+
require.Nil(t, err)
|
| 122 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 123 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 124 |
+
}
|
| 125 |
+
})
|
| 126 |
+
|
| 127 |
+
t.Run("verify created objects length", func(t *testing.T) {
|
| 128 |
+
resp, err := helper.TenantListObjects(t, className, tenantNames[0])
|
| 129 |
+
require.Nil(t, err)
|
| 130 |
+
assert.Equal(t, len(tenantObjects), len(resp.Objects))
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 134 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 135 |
+
{
|
| 136 |
+
Name: tenantNames[0],
|
| 137 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 138 |
+
},
|
| 139 |
+
})
|
| 140 |
+
})
|
| 141 |
+
|
| 142 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 143 |
+
resp, err := helper.GetTenants(t, className)
|
| 144 |
+
require.Nil(t, err)
|
| 145 |
+
for _, tn := range resp.Payload {
|
| 146 |
+
if tn.Name == tenantNames[0] {
|
| 147 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 148 |
+
break
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
})
|
| 152 |
+
|
| 153 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 154 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 155 |
+
require.NotNil(t, err)
|
| 156 |
+
})
|
| 157 |
+
|
| 158 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 159 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 160 |
+
resp, err := helper.GetTenants(t, className)
|
| 161 |
+
require.Nil(t, err)
|
| 162 |
+
for _, tn := range resp.Payload {
|
| 163 |
+
if tn.Name == tenantNames[0] {
|
| 164 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 165 |
+
break
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
t.Run("verify deleting class", func(t *testing.T) {
|
| 172 |
+
helper.DeleteClass(t, className)
|
| 173 |
+
})
|
| 174 |
+
|
| 175 |
+
t.Run("verify frozen tenants deleted from cloud", func(t *testing.T) {
|
| 176 |
+
client, err := minio.New(compose.GetMinIO().URI(), &minio.Options{
|
| 177 |
+
Creds: credentials.NewEnvAWS(),
|
| 178 |
+
Secure: false,
|
| 179 |
+
})
|
| 180 |
+
require.Nil(t, err)
|
| 181 |
+
|
| 182 |
+
count := 0
|
| 183 |
+
for obj := range client.ListObjects(ctx, "offloading", minio.ListObjectsOptions{Prefix: strings.ToLower(className)}) {
|
| 184 |
+
if obj.Key != "" {
|
| 185 |
+
count++
|
| 186 |
+
t.Log(obj.Key)
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
require.Nil(t, err)
|
| 190 |
+
require.Zero(t, count)
|
| 191 |
+
})
|
| 192 |
+
})
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
func Test_DeleteAndRecreateS3Journey(t *testing.T) {
|
| 196 |
+
t.Run("create tenant, freeze, delete, re-create", func(t *testing.T) {
|
| 197 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 198 |
+
defer cancel()
|
| 199 |
+
t.Log("pre-instance env setup")
|
| 200 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 201 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 202 |
+
|
| 203 |
+
compose, err := docker.New().
|
| 204 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 205 |
+
WithText2VecContextionary().
|
| 206 |
+
With3NodeCluster().
|
| 207 |
+
Start(ctx)
|
| 208 |
+
require.Nil(t, err)
|
| 209 |
+
|
| 210 |
+
defer func() {
|
| 211 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 212 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 213 |
+
}
|
| 214 |
+
}()
|
| 215 |
+
|
| 216 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 217 |
+
|
| 218 |
+
className := "MultiTenantClass"
|
| 219 |
+
testClass := models.Class{
|
| 220 |
+
Class: className,
|
| 221 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 222 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 223 |
+
Enabled: true,
|
| 224 |
+
},
|
| 225 |
+
Properties: []*models.Property{
|
| 226 |
+
{
|
| 227 |
+
Name: "name",
|
| 228 |
+
DataType: schema.DataTypeText.PropString(),
|
| 229 |
+
},
|
| 230 |
+
},
|
| 231 |
+
}
|
| 232 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 233 |
+
helper.CreateClass(t, &testClass)
|
| 234 |
+
})
|
| 235 |
+
|
| 236 |
+
tenantNames := []string{
|
| 237 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 238 |
+
}
|
| 239 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 240 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 241 |
+
for i := range tenants {
|
| 242 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 243 |
+
}
|
| 244 |
+
helper.CreateTenants(t, className, tenants)
|
| 245 |
+
})
|
| 246 |
+
|
| 247 |
+
tenantObjects := []*models.Object{
|
| 248 |
+
{
|
| 249 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 250 |
+
Class: className,
|
| 251 |
+
Properties: map[string]interface{}{
|
| 252 |
+
"name": tenantNames[0],
|
| 253 |
+
},
|
| 254 |
+
Tenant: tenantNames[0],
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 258 |
+
Class: className,
|
| 259 |
+
Properties: map[string]interface{}{
|
| 260 |
+
"name": tenantNames[0],
|
| 261 |
+
},
|
| 262 |
+
Tenant: tenantNames[0],
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 266 |
+
Class: className,
|
| 267 |
+
Properties: map[string]interface{}{
|
| 268 |
+
"name": tenantNames[0],
|
| 269 |
+
},
|
| 270 |
+
Tenant: tenantNames[0],
|
| 271 |
+
},
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
defer func() {
|
| 275 |
+
helper.DeleteClass(t, className)
|
| 276 |
+
}()
|
| 277 |
+
|
| 278 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 279 |
+
for _, obj := range tenantObjects {
|
| 280 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 281 |
+
}
|
| 282 |
+
})
|
| 283 |
+
|
| 284 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 285 |
+
for _, obj := range tenantObjects {
|
| 286 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[0])
|
| 287 |
+
require.Nil(t, err)
|
| 288 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 289 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 290 |
+
}
|
| 291 |
+
})
|
| 292 |
+
|
| 293 |
+
t.Run("verify created objects length", func(t *testing.T) {
|
| 294 |
+
resp, err := helper.TenantListObjects(t, className, tenantNames[0])
|
| 295 |
+
require.Nil(t, err)
|
| 296 |
+
assert.Equal(t, len(tenantObjects), len(resp.Objects))
|
| 297 |
+
})
|
| 298 |
+
|
| 299 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 300 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 301 |
+
{
|
| 302 |
+
Name: tenantNames[0],
|
| 303 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 304 |
+
},
|
| 305 |
+
})
|
| 306 |
+
})
|
| 307 |
+
|
| 308 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 309 |
+
resp, err := helper.GetTenants(t, className)
|
| 310 |
+
require.Nil(t, err)
|
| 311 |
+
for _, tn := range resp.Payload {
|
| 312 |
+
if tn.Name == tenantNames[0] {
|
| 313 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 314 |
+
break
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
})
|
| 318 |
+
|
| 319 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 320 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 321 |
+
require.NotNil(t, err)
|
| 322 |
+
})
|
| 323 |
+
|
| 324 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 325 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 326 |
+
resp, err := helper.GetTenants(t, className)
|
| 327 |
+
require.Nil(t, err)
|
| 328 |
+
for _, tn := range resp.Payload {
|
| 329 |
+
if tn.Name == tenantNames[0] {
|
| 330 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 331 |
+
break
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 335 |
+
})
|
| 336 |
+
|
| 337 |
+
t.Run("delete tenant", func(t *testing.T) {
|
| 338 |
+
err := helper.DeleteTenants(t, className, []string{tenantNames[0]})
|
| 339 |
+
require.Nil(t, err)
|
| 340 |
+
})
|
| 341 |
+
|
| 342 |
+
t.Run("create tenant", func(t *testing.T) {
|
| 343 |
+
helper.CreateTenants(t, className, []*models.Tenant{{Name: tenantNames[0]}})
|
| 344 |
+
})
|
| 345 |
+
|
| 346 |
+
t.Run("add tenant 1 object", func(t *testing.T) {
|
| 347 |
+
assert.Nil(t, helper.CreateObject(t, tenantObjects[0]))
|
| 348 |
+
})
|
| 349 |
+
|
| 350 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 351 |
+
resp, err := helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 352 |
+
require.Nil(t, err)
|
| 353 |
+
assert.Equal(t, tenantObjects[0].Class, resp.Class)
|
| 354 |
+
assert.Equal(t, tenantObjects[0].Properties, resp.Properties)
|
| 355 |
+
})
|
| 356 |
+
|
| 357 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 358 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 359 |
+
{
|
| 360 |
+
Name: tenantNames[0],
|
| 361 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 362 |
+
},
|
| 363 |
+
})
|
| 364 |
+
})
|
| 365 |
+
|
| 366 |
+
t.Run("verify tenant status is FROZEN", func(t *testing.T) {
|
| 367 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 368 |
+
resp, err := helper.GetTenants(t, className)
|
| 369 |
+
require.Nil(t, err)
|
| 370 |
+
for _, tn := range resp.Payload {
|
| 371 |
+
if tn.Name == tenantNames[0] {
|
| 372 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 373 |
+
break
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 377 |
+
})
|
| 378 |
+
|
| 379 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 380 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 381 |
+
{
|
| 382 |
+
Name: tenantNames[0],
|
| 383 |
+
ActivityStatus: models.TenantActivityStatusHOT,
|
| 384 |
+
},
|
| 385 |
+
})
|
| 386 |
+
})
|
| 387 |
+
|
| 388 |
+
t.Run("verify tenant status is HOT", func(t *testing.T) {
|
| 389 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 390 |
+
resp, err := helper.GetTenants(t, className)
|
| 391 |
+
require.Nil(t, err)
|
| 392 |
+
for _, tn := range resp.Payload {
|
| 393 |
+
if tn.Name == tenantNames[0] {
|
| 394 |
+
assert.Equal(at, models.TenantActivityStatusHOT, tn.ActivityStatus)
|
| 395 |
+
break
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusHOT))
|
| 399 |
+
})
|
| 400 |
+
|
| 401 |
+
t.Run("verify created object", func(t *testing.T) {
|
| 402 |
+
resp, err := helper.TenantListObjects(t, className, tenantNames[0])
|
| 403 |
+
require.Nil(t, err)
|
| 404 |
+
assert.Equal(t, 1, len(resp.Objects))
|
| 405 |
+
assert.Equal(t, tenantObjects[0].Class, resp.Objects[0].Class)
|
| 406 |
+
assert.Equal(t, tenantObjects[0].Properties, resp.Objects[0].Properties)
|
| 407 |
+
})
|
| 408 |
+
})
|
| 409 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_bucket_test.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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"strings"
|
| 18 |
+
"testing"
|
| 19 |
+
"time"
|
| 20 |
+
|
| 21 |
+
"github.com/minio/minio-go/v7"
|
| 22 |
+
"github.com/minio/minio-go/v7/pkg/credentials"
|
| 23 |
+
"github.com/stretchr/testify/assert"
|
| 24 |
+
"github.com/stretchr/testify/require"
|
| 25 |
+
"github.com/weaviate/weaviate/cluster/types"
|
| 26 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 27 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 28 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 29 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
func Test_OffloadBucketNotAutoCreate(t *testing.T) {
|
| 33 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 34 |
+
defer cancel()
|
| 35 |
+
|
| 36 |
+
t.Log("pre-instance env setup")
|
| 37 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 38 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 39 |
+
|
| 40 |
+
compose, err := docker.New().
|
| 41 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 42 |
+
WithText2VecContextionary().
|
| 43 |
+
WithWeaviateEnv("OFFLOAD_TIMEOUT", "1").
|
| 44 |
+
WithoutWeaviateEnvs("OFFLOAD_S3_BUCKET_AUTO_CREATE").
|
| 45 |
+
WithWeaviate().
|
| 46 |
+
Start(ctx)
|
| 47 |
+
require.Nil(t, err)
|
| 48 |
+
|
| 49 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 50 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func Test_OffloadBucketNotAutoCreateMinioManualCreate(t *testing.T) {
|
| 55 |
+
t.Run("success because created manually in minio", func(t *testing.T) {
|
| 56 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 57 |
+
defer cancel()
|
| 58 |
+
bucketname := "offloading"
|
| 59 |
+
t.Log("pre-instance env setup")
|
| 60 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 61 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 62 |
+
|
| 63 |
+
compose, err := docker.New().
|
| 64 |
+
WithOffloadS3(bucketname, "us-west-1").
|
| 65 |
+
WithText2VecContextionary().
|
| 66 |
+
WithWeaviateEnv("OFFLOAD_S3_BUCKET_AUTO_CREATE", "false").
|
| 67 |
+
With3NodeCluster().
|
| 68 |
+
Start(ctx)
|
| 69 |
+
require.Nil(t, err)
|
| 70 |
+
|
| 71 |
+
defer func() {
|
| 72 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 73 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 74 |
+
}
|
| 75 |
+
}()
|
| 76 |
+
|
| 77 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 78 |
+
|
| 79 |
+
className := "MultiTenantClass"
|
| 80 |
+
testClass := models.Class{
|
| 81 |
+
Class: className,
|
| 82 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 83 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 84 |
+
Enabled: true,
|
| 85 |
+
},
|
| 86 |
+
Properties: []*models.Property{
|
| 87 |
+
{
|
| 88 |
+
Name: "name",
|
| 89 |
+
DataType: schema.DataTypeText.PropString(),
|
| 90 |
+
},
|
| 91 |
+
},
|
| 92 |
+
}
|
| 93 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 94 |
+
helper.CreateClass(t, &testClass)
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
tenantNames := []string{
|
| 98 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 99 |
+
}
|
| 100 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 101 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 102 |
+
for i := range tenants {
|
| 103 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 104 |
+
}
|
| 105 |
+
helper.CreateTenants(t, className, tenants)
|
| 106 |
+
})
|
| 107 |
+
|
| 108 |
+
tenantObjects := []*models.Object{
|
| 109 |
+
{
|
| 110 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 111 |
+
Class: className,
|
| 112 |
+
Properties: map[string]interface{}{
|
| 113 |
+
"name": tenantNames[0],
|
| 114 |
+
},
|
| 115 |
+
Tenant: tenantNames[0],
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 119 |
+
Class: className,
|
| 120 |
+
Properties: map[string]interface{}{
|
| 121 |
+
"name": tenantNames[0],
|
| 122 |
+
},
|
| 123 |
+
Tenant: tenantNames[0],
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 127 |
+
Class: className,
|
| 128 |
+
Properties: map[string]interface{}{
|
| 129 |
+
"name": tenantNames[0],
|
| 130 |
+
},
|
| 131 |
+
Tenant: tenantNames[0],
|
| 132 |
+
},
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 136 |
+
for _, obj := range tenantObjects {
|
| 137 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 138 |
+
}
|
| 139 |
+
})
|
| 140 |
+
|
| 141 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 142 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 143 |
+
{
|
| 144 |
+
Name: tenantNames[0],
|
| 145 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 146 |
+
},
|
| 147 |
+
})
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 151 |
+
resp, err := helper.GetTenants(t, className)
|
| 152 |
+
require.Nil(t, err)
|
| 153 |
+
for _, tn := range resp.Payload {
|
| 154 |
+
if tn.Name == tenantNames[0] {
|
| 155 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 156 |
+
break
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
})
|
| 160 |
+
|
| 161 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 162 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 163 |
+
require.NotNil(t, err)
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 167 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 168 |
+
resp, err := helper.GetTenants(t, className)
|
| 169 |
+
require.Nil(t, err)
|
| 170 |
+
for _, tn := range resp.Payload {
|
| 171 |
+
if tn.Name == tenantNames[0] {
|
| 172 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 173 |
+
break
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 177 |
+
})
|
| 178 |
+
|
| 179 |
+
t.Run("verify deleting class", func(t *testing.T) {
|
| 180 |
+
helper.DeleteClass(t, className)
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
t.Run("verify frozen tenants deleted from cloud", func(t *testing.T) {
|
| 184 |
+
client, err := minio.New(compose.GetMinIO().URI(), &minio.Options{
|
| 185 |
+
Creds: credentials.NewEnvAWS(),
|
| 186 |
+
Secure: false,
|
| 187 |
+
})
|
| 188 |
+
require.Nil(t, err)
|
| 189 |
+
|
| 190 |
+
count := 0
|
| 191 |
+
for obj := range client.ListObjects(ctx, "offloading", minio.ListObjectsOptions{Prefix: strings.ToLower(className)}) {
|
| 192 |
+
if obj.Key != "" {
|
| 193 |
+
count++
|
| 194 |
+
t.Log(obj.Key)
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
require.Nil(t, err)
|
| 198 |
+
require.Zero(t, count)
|
| 199 |
+
})
|
| 200 |
+
})
|
| 201 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_download_test.go
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 23 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 24 |
+
pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
|
| 25 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 26 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
func Test_DownloadS3Journey(t *testing.T) {
|
| 30 |
+
t.Run("happy path with RF 2 download from s3 provider, HOT status", func(t *testing.T) {
|
| 31 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 32 |
+
defer cancel()
|
| 33 |
+
t.Log("pre-instance env setup")
|
| 34 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 35 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 36 |
+
|
| 37 |
+
compose, err := docker.New().
|
| 38 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 39 |
+
WithText2VecContextionary().
|
| 40 |
+
WithWeaviateClusterWithGRPC().
|
| 41 |
+
Start(ctx)
|
| 42 |
+
require.Nil(t, err)
|
| 43 |
+
|
| 44 |
+
defer func() {
|
| 45 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 46 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 47 |
+
}
|
| 48 |
+
}()
|
| 49 |
+
|
| 50 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 51 |
+
helper.SetupGRPCClient(t, compose.GetWeaviate().GrpcURI())
|
| 52 |
+
|
| 53 |
+
className := "MultiTenantClass"
|
| 54 |
+
testClass := models.Class{
|
| 55 |
+
Class: className,
|
| 56 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 57 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 58 |
+
Enabled: true,
|
| 59 |
+
},
|
| 60 |
+
Properties: []*models.Property{
|
| 61 |
+
{
|
| 62 |
+
Name: "name",
|
| 63 |
+
DataType: schema.DataTypeText.PropString(),
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
}
|
| 67 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 68 |
+
helper.CreateClass(t, &testClass)
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
+
tenantNames := []string{
|
| 72 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 73 |
+
}
|
| 74 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 75 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 76 |
+
for i := range tenants {
|
| 77 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 78 |
+
}
|
| 79 |
+
helper.CreateTenants(t, className, tenants)
|
| 80 |
+
})
|
| 81 |
+
|
| 82 |
+
tenantObjects := []*models.Object{
|
| 83 |
+
{
|
| 84 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 85 |
+
Class: className,
|
| 86 |
+
Properties: map[string]interface{}{
|
| 87 |
+
"name": tenantNames[0],
|
| 88 |
+
},
|
| 89 |
+
Tenant: tenantNames[0],
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 93 |
+
Class: className,
|
| 94 |
+
Properties: map[string]interface{}{
|
| 95 |
+
"name": tenantNames[1],
|
| 96 |
+
},
|
| 97 |
+
Tenant: tenantNames[1],
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 101 |
+
Class: className,
|
| 102 |
+
Properties: map[string]interface{}{
|
| 103 |
+
"name": tenantNames[2],
|
| 104 |
+
},
|
| 105 |
+
Tenant: tenantNames[2],
|
| 106 |
+
},
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
defer func() {
|
| 110 |
+
helper.DeleteClass(t, className)
|
| 111 |
+
}()
|
| 112 |
+
|
| 113 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 114 |
+
for _, obj := range tenantObjects {
|
| 115 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
|
| 119 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 120 |
+
for i, obj := range tenantObjects {
|
| 121 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 122 |
+
require.Nil(t, err)
|
| 123 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 124 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 125 |
+
}
|
| 126 |
+
})
|
| 127 |
+
|
| 128 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 129 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 130 |
+
{
|
| 131 |
+
Name: tenantNames[0],
|
| 132 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 133 |
+
},
|
| 134 |
+
})
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 138 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 139 |
+
resp, err := helper.GetTenantsGRPC(t, className)
|
| 140 |
+
require.Nil(t, err)
|
| 141 |
+
for _, tn := range resp.Tenants {
|
| 142 |
+
if tn.Name == tenantNames[0] {
|
| 143 |
+
assert.Equal(at, pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_FROZEN, tn.ActivityStatus)
|
| 144 |
+
break
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_FROZEN))
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 151 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 152 |
+
require.NotNil(t, err)
|
| 153 |
+
})
|
| 154 |
+
|
| 155 |
+
t.Run("updating tenant status to HOT", func(t *testing.T) {
|
| 156 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 157 |
+
{
|
| 158 |
+
Name: tenantNames[0],
|
| 159 |
+
ActivityStatus: models.TenantActivityStatusHOT,
|
| 160 |
+
},
|
| 161 |
+
})
|
| 162 |
+
})
|
| 163 |
+
|
| 164 |
+
t.Run("verify tenant status HOT", func(t *testing.T) {
|
| 165 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 166 |
+
resp, err := helper.GetTenantsGRPC(t, className)
|
| 167 |
+
require.Nil(t, err)
|
| 168 |
+
for _, tn := range resp.Tenants {
|
| 169 |
+
if tn.Name == tenantNames[0] {
|
| 170 |
+
assert.Equal(at, pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_HOT, tn.ActivityStatus)
|
| 171 |
+
break
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_HOT))
|
| 175 |
+
})
|
| 176 |
+
|
| 177 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 178 |
+
for i, obj := range tenantObjects {
|
| 179 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 180 |
+
require.Nil(t, err)
|
| 181 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 182 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 183 |
+
}
|
| 184 |
+
})
|
| 185 |
+
})
|
| 186 |
+
|
| 187 |
+
t.Run("happy path with RF 2 download from s3 provider COLD status", func(t *testing.T) {
|
| 188 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 189 |
+
defer cancel()
|
| 190 |
+
t.Log("pre-instance env setup")
|
| 191 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 192 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 193 |
+
|
| 194 |
+
compose, err := docker.New().
|
| 195 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 196 |
+
WithText2VecContextionary().
|
| 197 |
+
WithWeaviateClusterWithGRPC().
|
| 198 |
+
Start(ctx)
|
| 199 |
+
require.Nil(t, err)
|
| 200 |
+
|
| 201 |
+
defer func() {
|
| 202 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 203 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 204 |
+
}
|
| 205 |
+
}()
|
| 206 |
+
|
| 207 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 208 |
+
helper.SetupGRPCClient(t, compose.GetWeaviate().GrpcURI())
|
| 209 |
+
|
| 210 |
+
className := "MultiTenantClass"
|
| 211 |
+
testClass := models.Class{
|
| 212 |
+
Class: className,
|
| 213 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 214 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 215 |
+
Enabled: true,
|
| 216 |
+
},
|
| 217 |
+
Properties: []*models.Property{
|
| 218 |
+
{
|
| 219 |
+
Name: "name",
|
| 220 |
+
DataType: schema.DataTypeText.PropString(),
|
| 221 |
+
},
|
| 222 |
+
},
|
| 223 |
+
}
|
| 224 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 225 |
+
helper.CreateClass(t, &testClass)
|
| 226 |
+
})
|
| 227 |
+
|
| 228 |
+
tenantNames := []string{
|
| 229 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 230 |
+
}
|
| 231 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 232 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 233 |
+
for i := range tenants {
|
| 234 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 235 |
+
}
|
| 236 |
+
helper.CreateTenants(t, className, tenants)
|
| 237 |
+
})
|
| 238 |
+
|
| 239 |
+
tenantObjects := []*models.Object{
|
| 240 |
+
{
|
| 241 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 242 |
+
Class: className,
|
| 243 |
+
Properties: map[string]interface{}{
|
| 244 |
+
"name": tenantNames[0],
|
| 245 |
+
},
|
| 246 |
+
Tenant: tenantNames[0],
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 250 |
+
Class: className,
|
| 251 |
+
Properties: map[string]interface{}{
|
| 252 |
+
"name": tenantNames[1],
|
| 253 |
+
},
|
| 254 |
+
Tenant: tenantNames[1],
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 258 |
+
Class: className,
|
| 259 |
+
Properties: map[string]interface{}{
|
| 260 |
+
"name": tenantNames[2],
|
| 261 |
+
},
|
| 262 |
+
Tenant: tenantNames[2],
|
| 263 |
+
},
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
defer func() {
|
| 267 |
+
helper.DeleteClass(t, className)
|
| 268 |
+
}()
|
| 269 |
+
|
| 270 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 271 |
+
for _, obj := range tenantObjects {
|
| 272 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 273 |
+
}
|
| 274 |
+
})
|
| 275 |
+
|
| 276 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 277 |
+
for i, obj := range tenantObjects {
|
| 278 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 279 |
+
require.Nil(t, err)
|
| 280 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 281 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 282 |
+
}
|
| 283 |
+
})
|
| 284 |
+
|
| 285 |
+
t.Run("updating tenant status to COLD", func(t *testing.T) {
|
| 286 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 287 |
+
{
|
| 288 |
+
Name: tenantNames[0],
|
| 289 |
+
ActivityStatus: models.TenantActivityStatusCOLD,
|
| 290 |
+
},
|
| 291 |
+
})
|
| 292 |
+
})
|
| 293 |
+
|
| 294 |
+
t.Run("verify tenant status COLD", func(t *testing.T) {
|
| 295 |
+
resp, err := helper.GetTenantsGRPC(t, className)
|
| 296 |
+
require.Nil(t, err)
|
| 297 |
+
for _, tn := range resp.Tenants {
|
| 298 |
+
if tn.Name == tenantNames[0] {
|
| 299 |
+
require.Equal(t, pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_COLD, tn.ActivityStatus)
|
| 300 |
+
break
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
})
|
| 304 |
+
|
| 305 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 306 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 307 |
+
{
|
| 308 |
+
Name: tenantNames[0],
|
| 309 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 310 |
+
},
|
| 311 |
+
})
|
| 312 |
+
})
|
| 313 |
+
|
| 314 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 315 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 316 |
+
resp, err := helper.GetTenantsGRPC(t, className)
|
| 317 |
+
require.Nil(t, err)
|
| 318 |
+
for _, tn := range resp.Tenants {
|
| 319 |
+
if tn.Name == tenantNames[0] {
|
| 320 |
+
assert.Equal(at, pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_FROZEN, tn.ActivityStatus)
|
| 321 |
+
break
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_FROZEN))
|
| 325 |
+
})
|
| 326 |
+
|
| 327 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 328 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 329 |
+
require.NotNil(t, err)
|
| 330 |
+
})
|
| 331 |
+
|
| 332 |
+
t.Run("updating tenant status to COLD", func(t *testing.T) {
|
| 333 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 334 |
+
{
|
| 335 |
+
Name: tenantNames[0],
|
| 336 |
+
ActivityStatus: models.TenantActivityStatusCOLD,
|
| 337 |
+
},
|
| 338 |
+
})
|
| 339 |
+
})
|
| 340 |
+
|
| 341 |
+
t.Run("verify tenant status COLD", func(t *testing.T) {
|
| 342 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 343 |
+
resp, err := helper.GetTenantsGRPC(t, className)
|
| 344 |
+
require.Nil(t, err)
|
| 345 |
+
for _, tn := range resp.Tenants {
|
| 346 |
+
if tn.Name == tenantNames[0] {
|
| 347 |
+
assert.Equal(at, pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_COLD, tn.ActivityStatus)
|
| 348 |
+
break
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", pb.TenantActivityStatus_TENANT_ACTIVITY_STATUS_COLD))
|
| 352 |
+
})
|
| 353 |
+
})
|
| 354 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_not_enabled_test.go
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"errors"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
client "github.com/weaviate/weaviate/client/schema"
|
| 23 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 25 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 26 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
func Test_Offload_When_Not_Enabled(t *testing.T) {
|
| 30 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 31 |
+
defer cancel()
|
| 32 |
+
compose, err := docker.New().
|
| 33 |
+
WithText2VecContextionary().
|
| 34 |
+
With3NodeCluster().
|
| 35 |
+
Start(ctx)
|
| 36 |
+
require.Nil(t, err)
|
| 37 |
+
|
| 38 |
+
defer func() {
|
| 39 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 40 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 41 |
+
}
|
| 42 |
+
}()
|
| 43 |
+
|
| 44 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 45 |
+
|
| 46 |
+
className := "MultiTenantClass"
|
| 47 |
+
testClass := models.Class{
|
| 48 |
+
Class: className,
|
| 49 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 50 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 51 |
+
Enabled: true,
|
| 52 |
+
},
|
| 53 |
+
Properties: []*models.Property{
|
| 54 |
+
{
|
| 55 |
+
Name: "name",
|
| 56 |
+
DataType: schema.DataTypeText.PropString(),
|
| 57 |
+
},
|
| 58 |
+
},
|
| 59 |
+
}
|
| 60 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 61 |
+
helper.CreateClass(t, &testClass)
|
| 62 |
+
})
|
| 63 |
+
|
| 64 |
+
tenantNames := []string{
|
| 65 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 66 |
+
}
|
| 67 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 68 |
+
|
| 69 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 70 |
+
for i := range tenants {
|
| 71 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 72 |
+
}
|
| 73 |
+
helper.CreateTenants(t, className, tenants)
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
tenantObjects := make([]*models.Object, len(tenantNames))
|
| 77 |
+
for i := range tenantObjects {
|
| 78 |
+
tenantObjects[i] = &models.Object{
|
| 79 |
+
Class: className,
|
| 80 |
+
Properties: map[string]interface{}{
|
| 81 |
+
"name": tenantNames[0],
|
| 82 |
+
},
|
| 83 |
+
Tenant: tenantNames[0],
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
defer func() {
|
| 88 |
+
helper.DeleteClass(t, className)
|
| 89 |
+
}()
|
| 90 |
+
|
| 91 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 92 |
+
for _, obj := range tenantObjects {
|
| 93 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 94 |
+
}
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 98 |
+
t.Helper()
|
| 99 |
+
for i := range tenants {
|
| 100 |
+
tenants[i].ActivityStatus = "FROZEN"
|
| 101 |
+
}
|
| 102 |
+
params := client.NewTenantsUpdateParams().
|
| 103 |
+
WithClassName(className).WithBody(tenants)
|
| 104 |
+
_, err := helper.Client(t).Schema.TenantsUpdate(params, nil)
|
| 105 |
+
require.NotNil(t, err)
|
| 106 |
+
|
| 107 |
+
tenantErr := &client.TenantsUpdateUnprocessableEntity{}
|
| 108 |
+
if !errors.As(err, &tenantErr) {
|
| 109 |
+
t.Fatalf("expected %T, got: %T", tenantErr, err)
|
| 110 |
+
}
|
| 111 |
+
require.NotNil(t, tenantErr.Payload)
|
| 112 |
+
require.Len(t, tenantErr.Payload.Error, 1)
|
| 113 |
+
msg := tenantErr.Payload.Error[0].Message
|
| 114 |
+
assert.Equal(t, "can't offload tenants, because offload-s3 module is not enabled", msg)
|
| 115 |
+
})
|
| 116 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_test.go
ADDED
|
@@ -0,0 +1,618 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"errors"
|
| 17 |
+
"fmt"
|
| 18 |
+
"testing"
|
| 19 |
+
"time"
|
| 20 |
+
|
| 21 |
+
"github.com/go-openapi/strfmt"
|
| 22 |
+
"github.com/google/uuid"
|
| 23 |
+
"github.com/stretchr/testify/assert"
|
| 24 |
+
"github.com/stretchr/testify/require"
|
| 25 |
+
"github.com/weaviate/weaviate/client/objects"
|
| 26 |
+
"github.com/weaviate/weaviate/cluster/types"
|
| 27 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 28 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 29 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 30 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
const (
|
| 34 |
+
envS3AccessKey = "AWS_ACCESS_KEY_ID"
|
| 35 |
+
envS3SecretKey = "AWS_SECRET_KEY"
|
| 36 |
+
s3BackupJourneyAccessKey = "aws_access_key"
|
| 37 |
+
s3BackupJourneySecretKey = "aws_secret_key"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
func Test_Upload_DownloadS3Journey(t *testing.T) {
|
| 41 |
+
t.Run("happy path with RF 2 upload to s3 provider", func(t *testing.T) {
|
| 42 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 43 |
+
defer cancel()
|
| 44 |
+
t.Log("pre-instance env setup")
|
| 45 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 46 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 47 |
+
|
| 48 |
+
compose, err := docker.New().
|
| 49 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 50 |
+
WithText2VecContextionary().
|
| 51 |
+
With3NodeCluster().
|
| 52 |
+
Start(ctx)
|
| 53 |
+
require.Nil(t, err)
|
| 54 |
+
|
| 55 |
+
defer func() {
|
| 56 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 57 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 58 |
+
}
|
| 59 |
+
}()
|
| 60 |
+
|
| 61 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 62 |
+
|
| 63 |
+
className := "MultiTenantClass"
|
| 64 |
+
testClass := models.Class{
|
| 65 |
+
Class: className,
|
| 66 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 67 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 68 |
+
Enabled: true,
|
| 69 |
+
},
|
| 70 |
+
Properties: []*models.Property{
|
| 71 |
+
{
|
| 72 |
+
Name: "name",
|
| 73 |
+
DataType: schema.DataTypeText.PropString(),
|
| 74 |
+
},
|
| 75 |
+
},
|
| 76 |
+
}
|
| 77 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 78 |
+
helper.CreateClass(t, &testClass)
|
| 79 |
+
})
|
| 80 |
+
|
| 81 |
+
tenantNames := []string{
|
| 82 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 83 |
+
}
|
| 84 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 85 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 86 |
+
for i := range tenants {
|
| 87 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 88 |
+
}
|
| 89 |
+
helper.CreateTenants(t, className, tenants)
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
tenantObjects := []*models.Object{
|
| 93 |
+
{
|
| 94 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 95 |
+
Class: className,
|
| 96 |
+
Properties: map[string]interface{}{
|
| 97 |
+
"name": tenantNames[0],
|
| 98 |
+
},
|
| 99 |
+
Tenant: tenantNames[0],
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 103 |
+
Class: className,
|
| 104 |
+
Properties: map[string]interface{}{
|
| 105 |
+
"name": tenantNames[1],
|
| 106 |
+
},
|
| 107 |
+
Tenant: tenantNames[1],
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 111 |
+
Class: className,
|
| 112 |
+
Properties: map[string]interface{}{
|
| 113 |
+
"name": tenantNames[2],
|
| 114 |
+
},
|
| 115 |
+
Tenant: tenantNames[2],
|
| 116 |
+
},
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
defer func() {
|
| 120 |
+
helper.DeleteClass(t, className)
|
| 121 |
+
}()
|
| 122 |
+
|
| 123 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 124 |
+
for _, obj := range tenantObjects {
|
| 125 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 126 |
+
}
|
| 127 |
+
})
|
| 128 |
+
|
| 129 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 130 |
+
for i, obj := range tenantObjects {
|
| 131 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 132 |
+
require.Nil(t, err)
|
| 133 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 134 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
|
| 138 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 139 |
+
tenants := []*models.Tenant{}
|
| 140 |
+
for i := range tenantNames {
|
| 141 |
+
tenants = append(tenants, &models.Tenant{
|
| 142 |
+
Name: tenantNames[i],
|
| 143 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 144 |
+
})
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
helper.UpdateTenants(t, className, tenants)
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 151 |
+
resp, err := helper.GetTenants(t, className)
|
| 152 |
+
require.Nil(t, err)
|
| 153 |
+
for _, tn := range resp.Payload {
|
| 154 |
+
for i := range tenantNames {
|
| 155 |
+
if tn.Name == tenantNames[i] {
|
| 156 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 157 |
+
break
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
})
|
| 162 |
+
|
| 163 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 164 |
+
for i := range tenantObjects {
|
| 165 |
+
_, err = helper.TenantObject(t, tenantObjects[i].Class, tenantObjects[i].ID, tenantNames[i])
|
| 166 |
+
require.NotNil(t, err)
|
| 167 |
+
}
|
| 168 |
+
})
|
| 169 |
+
|
| 170 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 171 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 172 |
+
resp, err := helper.GetTenants(t, className)
|
| 173 |
+
require.Nil(t, err)
|
| 174 |
+
for _, tn := range resp.Payload {
|
| 175 |
+
for i := range tenantNames {
|
| 176 |
+
if tn.Name == tenantNames[i] {
|
| 177 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 178 |
+
break
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 183 |
+
})
|
| 184 |
+
|
| 185 |
+
t.Run("updating tenant status to HOT", func(t *testing.T) {
|
| 186 |
+
tenants := []*models.Tenant{}
|
| 187 |
+
for i := range tenantNames {
|
| 188 |
+
tenants = append(tenants, &models.Tenant{
|
| 189 |
+
Name: tenantNames[i],
|
| 190 |
+
ActivityStatus: models.TenantActivityStatusHOT,
|
| 191 |
+
})
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
helper.UpdateTenants(t, className, tenants)
|
| 195 |
+
})
|
| 196 |
+
|
| 197 |
+
t.Run("verify tenant status HOT", func(t *testing.T) {
|
| 198 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 199 |
+
resp, err := helper.GetTenants(t, className)
|
| 200 |
+
require.Nil(t, err)
|
| 201 |
+
for _, tn := range resp.Payload {
|
| 202 |
+
for i := range tenantNames {
|
| 203 |
+
if tn.Name == tenantNames[i] {
|
| 204 |
+
assert.Equal(at, models.TenantActivityStatusHOT, tn.ActivityStatus)
|
| 205 |
+
break
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusHOT))
|
| 210 |
+
})
|
| 211 |
+
|
| 212 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 213 |
+
for i, obj := range tenantObjects {
|
| 214 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 215 |
+
require.Nil(t, err)
|
| 216 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 217 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 218 |
+
}
|
| 219 |
+
})
|
| 220 |
+
|
| 221 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 222 |
+
tenants := []*models.Tenant{}
|
| 223 |
+
for i := range tenantNames {
|
| 224 |
+
tenants = append(tenants, &models.Tenant{
|
| 225 |
+
Name: tenantNames[i],
|
| 226 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 227 |
+
})
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
helper.UpdateTenants(t, className, tenants)
|
| 231 |
+
})
|
| 232 |
+
|
| 233 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 234 |
+
resp, err := helper.GetTenants(t, className)
|
| 235 |
+
require.Nil(t, err)
|
| 236 |
+
for _, tn := range resp.Payload {
|
| 237 |
+
for i := range tenantNames {
|
| 238 |
+
if tn.Name == tenantNames[i] {
|
| 239 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 240 |
+
break
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
})
|
| 245 |
+
|
| 246 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 247 |
+
for i := range tenantObjects {
|
| 248 |
+
_, err = helper.TenantObject(t, tenantObjects[i].Class, tenantObjects[i].ID, tenantNames[i])
|
| 249 |
+
require.NotNil(t, err)
|
| 250 |
+
}
|
| 251 |
+
})
|
| 252 |
+
})
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
func Test_AutoTenantActivation(t *testing.T) {
|
| 256 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 257 |
+
defer cancel()
|
| 258 |
+
t.Log("pre-instance env setup")
|
| 259 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 260 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 261 |
+
|
| 262 |
+
compose, err := docker.New().
|
| 263 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 264 |
+
WithText2VecContextionary().
|
| 265 |
+
With3NodeCluster().
|
| 266 |
+
Start(ctx)
|
| 267 |
+
require.Nil(t, err)
|
| 268 |
+
|
| 269 |
+
defer func() {
|
| 270 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 271 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 272 |
+
}
|
| 273 |
+
}()
|
| 274 |
+
|
| 275 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 276 |
+
|
| 277 |
+
className := "MultiTenantClass"
|
| 278 |
+
testClass := models.Class{
|
| 279 |
+
Class: className,
|
| 280 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 281 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 282 |
+
Enabled: true,
|
| 283 |
+
AutoTenantActivation: true,
|
| 284 |
+
},
|
| 285 |
+
Properties: []*models.Property{
|
| 286 |
+
{
|
| 287 |
+
Name: "name",
|
| 288 |
+
DataType: schema.DataTypeText.PropString(),
|
| 289 |
+
},
|
| 290 |
+
},
|
| 291 |
+
}
|
| 292 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 293 |
+
helper.CreateClass(t, &testClass)
|
| 294 |
+
})
|
| 295 |
+
|
| 296 |
+
tenantNames := []string{
|
| 297 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 298 |
+
}
|
| 299 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 300 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 301 |
+
for i := range tenants {
|
| 302 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 303 |
+
}
|
| 304 |
+
helper.CreateTenants(t, className, tenants)
|
| 305 |
+
})
|
| 306 |
+
|
| 307 |
+
tenantObjects := []*models.Object{
|
| 308 |
+
{
|
| 309 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 310 |
+
Class: className,
|
| 311 |
+
Properties: map[string]interface{}{
|
| 312 |
+
"name": tenantNames[0],
|
| 313 |
+
},
|
| 314 |
+
Tenant: tenantNames[0],
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 318 |
+
Class: className,
|
| 319 |
+
Properties: map[string]interface{}{
|
| 320 |
+
"name": tenantNames[1],
|
| 321 |
+
},
|
| 322 |
+
Tenant: tenantNames[1],
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 326 |
+
Class: className,
|
| 327 |
+
Properties: map[string]interface{}{
|
| 328 |
+
"name": tenantNames[2],
|
| 329 |
+
},
|
| 330 |
+
Tenant: tenantNames[2],
|
| 331 |
+
},
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
defer func() {
|
| 335 |
+
helper.DeleteClass(t, className)
|
| 336 |
+
}()
|
| 337 |
+
|
| 338 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 339 |
+
for _, obj := range tenantObjects {
|
| 340 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 341 |
+
}
|
| 342 |
+
})
|
| 343 |
+
|
| 344 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 345 |
+
for i, obj := range tenantObjects {
|
| 346 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 347 |
+
require.Nil(t, err)
|
| 348 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 349 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 350 |
+
}
|
| 351 |
+
})
|
| 352 |
+
|
| 353 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 354 |
+
tenants := []*models.Tenant{}
|
| 355 |
+
for i := range tenantNames {
|
| 356 |
+
tenants = append(tenants, &models.Tenant{
|
| 357 |
+
Name: tenantNames[i],
|
| 358 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 359 |
+
})
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
helper.UpdateTenants(t, className, tenants)
|
| 363 |
+
})
|
| 364 |
+
|
| 365 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 366 |
+
resp, err := helper.GetTenants(t, className)
|
| 367 |
+
require.Nil(t, err)
|
| 368 |
+
for _, tn := range resp.Payload {
|
| 369 |
+
for i := range tenantNames {
|
| 370 |
+
if tn.Name == tenantNames[i] {
|
| 371 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 372 |
+
break
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
})
|
| 377 |
+
|
| 378 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 379 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 380 |
+
resp, err := helper.GetTenants(t, className)
|
| 381 |
+
require.Nil(t, err)
|
| 382 |
+
for _, tn := range resp.Payload {
|
| 383 |
+
for i := range tenantNames {
|
| 384 |
+
if tn.Name == tenantNames[i] {
|
| 385 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 386 |
+
break
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 391 |
+
})
|
| 392 |
+
|
| 393 |
+
objectsToCreate := []*models.Object{
|
| 394 |
+
{
|
| 395 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 396 |
+
Class: className,
|
| 397 |
+
Properties: map[string]interface{}{
|
| 398 |
+
"name": tenantNames[0],
|
| 399 |
+
},
|
| 400 |
+
Tenant: tenantNames[0],
|
| 401 |
+
},
|
| 402 |
+
{
|
| 403 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 404 |
+
Class: className,
|
| 405 |
+
Properties: map[string]interface{}{
|
| 406 |
+
"name": tenantNames[1],
|
| 407 |
+
},
|
| 408 |
+
Tenant: tenantNames[1],
|
| 409 |
+
},
|
| 410 |
+
{
|
| 411 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 412 |
+
Class: className,
|
| 413 |
+
Properties: map[string]interface{}{
|
| 414 |
+
"name": tenantNames[2],
|
| 415 |
+
},
|
| 416 |
+
Tenant: tenantNames[2],
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
Class: className,
|
| 420 |
+
Properties: map[string]interface{}{
|
| 421 |
+
"name": tenantNames[0],
|
| 422 |
+
},
|
| 423 |
+
Tenant: tenantNames[0],
|
| 424 |
+
},
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 428 |
+
for i, obj := range objectsToCreate {
|
| 429 |
+
res, err := helper.CreateObjectWithResponse(t, obj)
|
| 430 |
+
if err != nil {
|
| 431 |
+
oe := &objects.ObjectsCreateUnprocessableEntity{}
|
| 432 |
+
as := errors.As(err, &oe)
|
| 433 |
+
require.True(t, as)
|
| 434 |
+
t.Log(oe.Payload.Error[0])
|
| 435 |
+
t.Log(oe.Error())
|
| 436 |
+
t.Log(oe.Payload)
|
| 437 |
+
}
|
| 438 |
+
require.Nil(t, err)
|
| 439 |
+
|
| 440 |
+
if obj.ID == "" {
|
| 441 |
+
// Some of the test objects were created without ID
|
| 442 |
+
objectsToCreate[i].ID = res.ID
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
})
|
| 446 |
+
|
| 447 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 448 |
+
for _, obj := range objectsToCreate {
|
| 449 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, obj.Tenant)
|
| 450 |
+
require.Nil(t, err)
|
| 451 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 452 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 453 |
+
}
|
| 454 |
+
})
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
func Test_ConcurrentFreezeUnfreeze(t *testing.T) {
|
| 458 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 459 |
+
defer cancel()
|
| 460 |
+
t.Log("pre-instance env setup")
|
| 461 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 462 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 463 |
+
|
| 464 |
+
compose, err := docker.New().
|
| 465 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 466 |
+
WithText2VecContextionary().
|
| 467 |
+
With3NodeCluster().
|
| 468 |
+
Start(ctx)
|
| 469 |
+
require.Nil(t, err)
|
| 470 |
+
|
| 471 |
+
defer func() {
|
| 472 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 473 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 474 |
+
}
|
| 475 |
+
}()
|
| 476 |
+
|
| 477 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 478 |
+
|
| 479 |
+
className := "MultiTenantClass"
|
| 480 |
+
testClass := models.Class{
|
| 481 |
+
Class: className,
|
| 482 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 483 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 484 |
+
Enabled: true,
|
| 485 |
+
},
|
| 486 |
+
Properties: []*models.Property{
|
| 487 |
+
{
|
| 488 |
+
Name: "name",
|
| 489 |
+
DataType: schema.DataTypeText.PropString(),
|
| 490 |
+
},
|
| 491 |
+
},
|
| 492 |
+
}
|
| 493 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 494 |
+
helper.CreateClass(t, &testClass)
|
| 495 |
+
})
|
| 496 |
+
|
| 497 |
+
defer func() {
|
| 498 |
+
helper.DeleteClass(t, className)
|
| 499 |
+
}()
|
| 500 |
+
|
| 501 |
+
tenantNames := []string{
|
| 502 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 503 |
+
}
|
| 504 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 505 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 506 |
+
for i := range tenants {
|
| 507 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 508 |
+
}
|
| 509 |
+
helper.CreateTenants(t, className, tenants)
|
| 510 |
+
})
|
| 511 |
+
|
| 512 |
+
tenantObjects := []*models.Object{
|
| 513 |
+
{
|
| 514 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 515 |
+
Class: className,
|
| 516 |
+
Properties: map[string]interface{}{
|
| 517 |
+
"name": tenantNames[0],
|
| 518 |
+
},
|
| 519 |
+
Tenant: tenantNames[0],
|
| 520 |
+
},
|
| 521 |
+
{
|
| 522 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 523 |
+
Class: className,
|
| 524 |
+
Properties: map[string]interface{}{
|
| 525 |
+
"name": tenantNames[1],
|
| 526 |
+
},
|
| 527 |
+
Tenant: tenantNames[1],
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
ID: strfmt.UUID(uuid.NewString()),
|
| 531 |
+
Class: className,
|
| 532 |
+
Properties: map[string]interface{}{
|
| 533 |
+
"name": tenantNames[2],
|
| 534 |
+
},
|
| 535 |
+
Tenant: tenantNames[2],
|
| 536 |
+
},
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 540 |
+
for _, obj := range tenantObjects {
|
| 541 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 542 |
+
}
|
| 543 |
+
})
|
| 544 |
+
|
| 545 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 546 |
+
for i, obj := range tenantObjects {
|
| 547 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 548 |
+
require.Nil(t, err)
|
| 549 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 550 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 551 |
+
}
|
| 552 |
+
})
|
| 553 |
+
|
| 554 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 555 |
+
tenants := []*models.Tenant{}
|
| 556 |
+
for i := range tenantNames {
|
| 557 |
+
tenants = append(tenants, &models.Tenant{
|
| 558 |
+
Name: tenantNames[i],
|
| 559 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 560 |
+
})
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
for idx := 0; idx < 5; idx++ {
|
| 564 |
+
go helper.UpdateTenants(t, className, tenants)
|
| 565 |
+
}
|
| 566 |
+
})
|
| 567 |
+
|
| 568 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 569 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 570 |
+
resp, err := helper.GetTenants(t, className)
|
| 571 |
+
require.Nil(t, err)
|
| 572 |
+
for _, tn := range resp.Payload {
|
| 573 |
+
for i := range tenantNames {
|
| 574 |
+
if tn.Name == tenantNames[i] {
|
| 575 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 576 |
+
break
|
| 577 |
+
}
|
| 578 |
+
}
|
| 579 |
+
}
|
| 580 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 581 |
+
})
|
| 582 |
+
|
| 583 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 584 |
+
for i := range tenantObjects {
|
| 585 |
+
_, err = helper.TenantObject(t, tenantObjects[i].Class, tenantObjects[i].ID, tenantNames[i])
|
| 586 |
+
require.NotNil(t, err)
|
| 587 |
+
}
|
| 588 |
+
})
|
| 589 |
+
|
| 590 |
+
t.Run("updating tenant status to HOT", func(t *testing.T) {
|
| 591 |
+
tenants := []*models.Tenant{}
|
| 592 |
+
for i := range tenantNames {
|
| 593 |
+
tenants = append(tenants, &models.Tenant{
|
| 594 |
+
Name: tenantNames[i],
|
| 595 |
+
ActivityStatus: models.TenantActivityStatusHOT,
|
| 596 |
+
})
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
for idx := 0; idx < 5; idx++ {
|
| 600 |
+
go helper.UpdateTenants(t, className, tenants)
|
| 601 |
+
}
|
| 602 |
+
})
|
| 603 |
+
|
| 604 |
+
t.Run("verify tenant status HOT", func(t *testing.T) {
|
| 605 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 606 |
+
resp, err := helper.GetTenants(t, className)
|
| 607 |
+
require.Nil(t, err)
|
| 608 |
+
for _, tn := range resp.Payload {
|
| 609 |
+
for i := range tenantNames {
|
| 610 |
+
if tn.Name == tenantNames[i] {
|
| 611 |
+
assert.Equal(at, models.TenantActivityStatusHOT, tn.ActivityStatus)
|
| 612 |
+
break
|
| 613 |
+
}
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusHOT))
|
| 617 |
+
})
|
| 618 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/offload-s3/offload_upload_test.go
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"fmt"
|
| 17 |
+
"testing"
|
| 18 |
+
"time"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/stretchr/testify/require"
|
| 22 |
+
"github.com/weaviate/weaviate/client/objects"
|
| 23 |
+
"github.com/weaviate/weaviate/cluster/types"
|
| 24 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 25 |
+
"github.com/weaviate/weaviate/entities/schema"
|
| 26 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 27 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
func Test_UploadS3Journey(t *testing.T) {
|
| 31 |
+
t.Run("happy path with RF 2 upload to s3 provider", func(t *testing.T) {
|
| 32 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 33 |
+
defer cancel()
|
| 34 |
+
t.Log("pre-instance env setup")
|
| 35 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 36 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 37 |
+
|
| 38 |
+
compose, err := docker.New().
|
| 39 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 40 |
+
WithText2VecContextionary().
|
| 41 |
+
With3NodeCluster().
|
| 42 |
+
Start(ctx)
|
| 43 |
+
require.Nil(t, err)
|
| 44 |
+
|
| 45 |
+
defer func() {
|
| 46 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 47 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 48 |
+
}
|
| 49 |
+
}()
|
| 50 |
+
|
| 51 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 52 |
+
|
| 53 |
+
className := "MultiTenantClass"
|
| 54 |
+
testClass := models.Class{
|
| 55 |
+
Class: className,
|
| 56 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 2},
|
| 57 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 58 |
+
Enabled: true,
|
| 59 |
+
},
|
| 60 |
+
Properties: []*models.Property{
|
| 61 |
+
{
|
| 62 |
+
Name: "name",
|
| 63 |
+
DataType: schema.DataTypeText.PropString(),
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
}
|
| 67 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 68 |
+
helper.CreateClass(t, &testClass)
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
+
tenantNames := []string{
|
| 72 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 73 |
+
}
|
| 74 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 75 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 76 |
+
for i := range tenants {
|
| 77 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 78 |
+
}
|
| 79 |
+
helper.CreateTenants(t, className, tenants)
|
| 80 |
+
})
|
| 81 |
+
|
| 82 |
+
tenantObjects := []*models.Object{
|
| 83 |
+
{
|
| 84 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 85 |
+
Class: className,
|
| 86 |
+
Properties: map[string]interface{}{
|
| 87 |
+
"name": tenantNames[0],
|
| 88 |
+
},
|
| 89 |
+
Tenant: tenantNames[0],
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 93 |
+
Class: className,
|
| 94 |
+
Properties: map[string]interface{}{
|
| 95 |
+
"name": tenantNames[1],
|
| 96 |
+
},
|
| 97 |
+
Tenant: tenantNames[1],
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 101 |
+
Class: className,
|
| 102 |
+
Properties: map[string]interface{}{
|
| 103 |
+
"name": tenantNames[2],
|
| 104 |
+
},
|
| 105 |
+
Tenant: tenantNames[2],
|
| 106 |
+
},
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
defer func() {
|
| 110 |
+
helper.DeleteClass(t, className)
|
| 111 |
+
}()
|
| 112 |
+
|
| 113 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 114 |
+
for _, obj := range tenantObjects {
|
| 115 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
|
| 119 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 120 |
+
for i, obj := range tenantObjects {
|
| 121 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 122 |
+
require.Nil(t, err)
|
| 123 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 124 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 125 |
+
}
|
| 126 |
+
})
|
| 127 |
+
|
| 128 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 129 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 130 |
+
{
|
| 131 |
+
Name: tenantNames[0],
|
| 132 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 133 |
+
},
|
| 134 |
+
})
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 138 |
+
resp, err := helper.GetTenants(t, className)
|
| 139 |
+
require.Nil(t, err)
|
| 140 |
+
for _, tn := range resp.Payload {
|
| 141 |
+
if tn.Name == tenantNames[0] {
|
| 142 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 143 |
+
break
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
})
|
| 147 |
+
|
| 148 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 149 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 150 |
+
require.NotNil(t, err)
|
| 151 |
+
})
|
| 152 |
+
|
| 153 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 154 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 155 |
+
resp, err := helper.GetTenants(t, className)
|
| 156 |
+
require.Nil(t, err)
|
| 157 |
+
for _, tn := range resp.Payload {
|
| 158 |
+
if tn.Name == tenantNames[0] {
|
| 159 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 160 |
+
break
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
+
t.Run("add objects to frozen tenant shall fail", func(t *testing.T) {
|
| 167 |
+
t.Run("add frozen tenant objects", func(t *testing.T) {
|
| 168 |
+
for _, obj := range tenantObjects {
|
| 169 |
+
obj.Tenant = tenantNames[0]
|
| 170 |
+
params := objects.NewObjectsCreateParams().WithBody(obj)
|
| 171 |
+
_, err := helper.Client(t).Objects.ObjectsCreate(params, nil)
|
| 172 |
+
require.NotNil(t, err)
|
| 173 |
+
}
|
| 174 |
+
})
|
| 175 |
+
|
| 176 |
+
tenantRefs := []*models.Object{
|
| 177 |
+
{
|
| 178 |
+
ID: "169b62a7-ef1c-481d-8fb0-27f11716bde7",
|
| 179 |
+
Class: className,
|
| 180 |
+
Properties: map[string]interface{}{
|
| 181 |
+
"name": tenantNames[0],
|
| 182 |
+
"mutableProp": "ref#0",
|
| 183 |
+
},
|
| 184 |
+
Tenant: tenantNames[0],
|
| 185 |
+
},
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
t.Run("add frozen tenant object references", func(t *testing.T) {
|
| 189 |
+
for i, obj := range tenantObjects {
|
| 190 |
+
ref := &models.SingleRef{Beacon: helper.NewBeacon(className, tenantRefs[0].ID)}
|
| 191 |
+
params := objects.NewObjectsClassReferencesCreateParams().
|
| 192 |
+
WithClassName(className).WithID(obj.ID).WithBody(ref).WithPropertyName("refProp").WithTenant(&tenantNames[i])
|
| 193 |
+
_, err := helper.Client(t).Objects.ObjectsClassReferencesCreate(params, nil)
|
| 194 |
+
require.NotNil(t, err)
|
| 195 |
+
}
|
| 196 |
+
})
|
| 197 |
+
})
|
| 198 |
+
})
|
| 199 |
+
|
| 200 |
+
t.Run("node is down while RF is 3, one weaviate node is down", func(t *testing.T) {
|
| 201 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 202 |
+
defer cancel()
|
| 203 |
+
t.Log("pre-instance env setup")
|
| 204 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 205 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 206 |
+
|
| 207 |
+
compose, err := docker.New().
|
| 208 |
+
WithOffloadS3("weaviate-offload", "us-west-1").
|
| 209 |
+
WithText2VecContextionary().
|
| 210 |
+
With3NodeCluster().
|
| 211 |
+
Start(ctx)
|
| 212 |
+
require.Nil(t, err)
|
| 213 |
+
|
| 214 |
+
defer func() {
|
| 215 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 216 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 217 |
+
}
|
| 218 |
+
}()
|
| 219 |
+
|
| 220 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 221 |
+
|
| 222 |
+
className := "MultiTenantClass"
|
| 223 |
+
testClass := models.Class{
|
| 224 |
+
Class: className,
|
| 225 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 3},
|
| 226 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 227 |
+
Enabled: true,
|
| 228 |
+
},
|
| 229 |
+
Properties: []*models.Property{
|
| 230 |
+
{
|
| 231 |
+
Name: "name",
|
| 232 |
+
DataType: schema.DataTypeText.PropString(),
|
| 233 |
+
},
|
| 234 |
+
},
|
| 235 |
+
}
|
| 236 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 237 |
+
helper.CreateClass(t, &testClass)
|
| 238 |
+
})
|
| 239 |
+
|
| 240 |
+
tenantNames := []string{
|
| 241 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 242 |
+
}
|
| 243 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 244 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 245 |
+
for i := range tenants {
|
| 246 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 247 |
+
}
|
| 248 |
+
helper.CreateTenants(t, className, tenants)
|
| 249 |
+
})
|
| 250 |
+
|
| 251 |
+
tenantObjects := []*models.Object{
|
| 252 |
+
{
|
| 253 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 254 |
+
Class: className,
|
| 255 |
+
Properties: map[string]interface{}{
|
| 256 |
+
"name": tenantNames[0],
|
| 257 |
+
},
|
| 258 |
+
Tenant: tenantNames[0],
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 262 |
+
Class: className,
|
| 263 |
+
Properties: map[string]interface{}{
|
| 264 |
+
"name": tenantNames[1],
|
| 265 |
+
},
|
| 266 |
+
Tenant: tenantNames[1],
|
| 267 |
+
},
|
| 268 |
+
{
|
| 269 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 270 |
+
Class: className,
|
| 271 |
+
Properties: map[string]interface{}{
|
| 272 |
+
"name": tenantNames[2],
|
| 273 |
+
},
|
| 274 |
+
Tenant: tenantNames[2],
|
| 275 |
+
},
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 279 |
+
for _, obj := range tenantObjects {
|
| 280 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 281 |
+
}
|
| 282 |
+
})
|
| 283 |
+
|
| 284 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 285 |
+
for i, obj := range tenantObjects {
|
| 286 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 287 |
+
require.Nil(t, err)
|
| 288 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 289 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 290 |
+
}
|
| 291 |
+
})
|
| 292 |
+
|
| 293 |
+
t.Run("StopNode-2", func(t *testing.T) {
|
| 294 |
+
require.Nil(t, compose.Stop(ctx, compose.GetWeaviateNode2().Name(), nil))
|
| 295 |
+
})
|
| 296 |
+
|
| 297 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 298 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 299 |
+
{
|
| 300 |
+
Name: tenantNames[0],
|
| 301 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 302 |
+
},
|
| 303 |
+
})
|
| 304 |
+
})
|
| 305 |
+
|
| 306 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 307 |
+
resp, err := helper.GetTenants(t, className)
|
| 308 |
+
require.Nil(t, err)
|
| 309 |
+
|
| 310 |
+
for _, tn := range resp.Payload {
|
| 311 |
+
if tn.Name == tenantNames[0] {
|
| 312 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 313 |
+
break
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
})
|
| 317 |
+
|
| 318 |
+
t.Run("StartNode-2", func(t *testing.T) {
|
| 319 |
+
require.Nil(t, compose.Start(ctx, compose.GetWeaviateNode2().Name()))
|
| 320 |
+
})
|
| 321 |
+
|
| 322 |
+
t.Run("verify tenant does not exists", func(t *testing.T) {
|
| 323 |
+
_, err = helper.TenantObject(t, tenantObjects[0].Class, tenantObjects[0].ID, tenantNames[0])
|
| 324 |
+
require.NotNil(t, err)
|
| 325 |
+
})
|
| 326 |
+
|
| 327 |
+
t.Run("verify tenant status", func(t *testing.T) {
|
| 328 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 329 |
+
resp, err := helper.GetTenants(t, className)
|
| 330 |
+
require.Nil(t, err)
|
| 331 |
+
for _, tn := range resp.Payload {
|
| 332 |
+
if tn.Name == tenantNames[0] {
|
| 333 |
+
assert.Equal(at, models.TenantActivityStatusFROZEN, tn.ActivityStatus)
|
| 334 |
+
break
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusFROZEN))
|
| 338 |
+
})
|
| 339 |
+
})
|
| 340 |
+
|
| 341 |
+
t.Run("unhappy path with RF 3, cloud provider is down", func(t *testing.T) {
|
| 342 |
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
| 343 |
+
defer cancel()
|
| 344 |
+
|
| 345 |
+
t.Log("pre-instance env setup")
|
| 346 |
+
t.Setenv(envS3AccessKey, s3BackupJourneyAccessKey)
|
| 347 |
+
t.Setenv(envS3SecretKey, s3BackupJourneySecretKey)
|
| 348 |
+
|
| 349 |
+
compose, err := docker.New().
|
| 350 |
+
WithOffloadS3("offloading", "us-west-1").
|
| 351 |
+
WithWeaviateEnv("OFFLOAD_TIMEOUT", "2").
|
| 352 |
+
WithText2VecContextionary().
|
| 353 |
+
With3NodeCluster().
|
| 354 |
+
Start(ctx)
|
| 355 |
+
require.Nil(t, err)
|
| 356 |
+
|
| 357 |
+
defer func() {
|
| 358 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 359 |
+
t.Fatalf("failed to terminate test containers: %s", err.Error())
|
| 360 |
+
}
|
| 361 |
+
}()
|
| 362 |
+
|
| 363 |
+
helper.SetupClient(compose.GetWeaviate().URI())
|
| 364 |
+
|
| 365 |
+
className := "MultiTenantClass"
|
| 366 |
+
testClass := models.Class{
|
| 367 |
+
Class: className,
|
| 368 |
+
ReplicationConfig: &models.ReplicationConfig{Factor: 3},
|
| 369 |
+
MultiTenancyConfig: &models.MultiTenancyConfig{
|
| 370 |
+
Enabled: true,
|
| 371 |
+
},
|
| 372 |
+
Properties: []*models.Property{
|
| 373 |
+
{
|
| 374 |
+
Name: "name",
|
| 375 |
+
DataType: schema.DataTypeText.PropString(),
|
| 376 |
+
},
|
| 377 |
+
},
|
| 378 |
+
}
|
| 379 |
+
t.Run("create class with multi-tenancy enabled", func(t *testing.T) {
|
| 380 |
+
helper.CreateClass(t, &testClass)
|
| 381 |
+
})
|
| 382 |
+
|
| 383 |
+
tenantNames := []string{
|
| 384 |
+
"Tenant1", "Tenant2", "Tenant3",
|
| 385 |
+
}
|
| 386 |
+
t.Run("create tenants", func(t *testing.T) {
|
| 387 |
+
tenants := make([]*models.Tenant, len(tenantNames))
|
| 388 |
+
for i := range tenants {
|
| 389 |
+
tenants[i] = &models.Tenant{Name: tenantNames[i]}
|
| 390 |
+
}
|
| 391 |
+
helper.CreateTenants(t, className, tenants)
|
| 392 |
+
})
|
| 393 |
+
|
| 394 |
+
tenantObjects := []*models.Object{
|
| 395 |
+
{
|
| 396 |
+
ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c",
|
| 397 |
+
Class: className,
|
| 398 |
+
Properties: map[string]interface{}{
|
| 399 |
+
"name": tenantNames[0],
|
| 400 |
+
},
|
| 401 |
+
Tenant: tenantNames[0],
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
ID: "831ae1d0-f441-44b1-bb2a-46548048e26f",
|
| 405 |
+
Class: className,
|
| 406 |
+
Properties: map[string]interface{}{
|
| 407 |
+
"name": tenantNames[1],
|
| 408 |
+
},
|
| 409 |
+
Tenant: tenantNames[1],
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59",
|
| 413 |
+
Class: className,
|
| 414 |
+
Properties: map[string]interface{}{
|
| 415 |
+
"name": tenantNames[2],
|
| 416 |
+
},
|
| 417 |
+
Tenant: tenantNames[2],
|
| 418 |
+
},
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
t.Run("add tenant objects", func(t *testing.T) {
|
| 422 |
+
for _, obj := range tenantObjects {
|
| 423 |
+
assert.Nil(t, helper.CreateObject(t, obj))
|
| 424 |
+
}
|
| 425 |
+
})
|
| 426 |
+
|
| 427 |
+
t.Run("verify object creation", func(t *testing.T) {
|
| 428 |
+
for i, obj := range tenantObjects {
|
| 429 |
+
resp, err := helper.TenantObject(t, obj.Class, obj.ID, tenantNames[i])
|
| 430 |
+
require.Nil(t, err)
|
| 431 |
+
assert.Equal(t, obj.Class, resp.Class)
|
| 432 |
+
assert.Equal(t, obj.Properties, resp.Properties)
|
| 433 |
+
}
|
| 434 |
+
})
|
| 435 |
+
|
| 436 |
+
t.Run("updating tenant status", func(t *testing.T) {
|
| 437 |
+
helper.UpdateTenants(t, className, []*models.Tenant{
|
| 438 |
+
{
|
| 439 |
+
Name: tenantNames[0],
|
| 440 |
+
ActivityStatus: models.TenantActivityStatusFROZEN,
|
| 441 |
+
},
|
| 442 |
+
})
|
| 443 |
+
})
|
| 444 |
+
|
| 445 |
+
t.Run("verify tenant status FREEZING", func(t *testing.T) {
|
| 446 |
+
resp, err := helper.GetTenants(t, className)
|
| 447 |
+
require.Nil(t, err)
|
| 448 |
+
|
| 449 |
+
for _, tn := range resp.Payload {
|
| 450 |
+
if tn.Name == tenantNames[0] {
|
| 451 |
+
require.Equal(t, types.TenantActivityStatusFREEZING, tn.ActivityStatus)
|
| 452 |
+
break
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
})
|
| 456 |
+
|
| 457 |
+
t.Run("terminate Minio", func(t *testing.T) {
|
| 458 |
+
require.Nil(t, compose.TerminateContainer(ctx, docker.MinIO))
|
| 459 |
+
})
|
| 460 |
+
|
| 461 |
+
t.Run("verify tenant status HOT", func(xt *testing.T) {
|
| 462 |
+
assert.EventuallyWithT(t, func(at *assert.CollectT) {
|
| 463 |
+
resp, err := helper.GetTenants(xt, className)
|
| 464 |
+
require.Nil(t, err)
|
| 465 |
+
|
| 466 |
+
for _, tn := range resp.Payload {
|
| 467 |
+
if tn.Name == tenantNames[0] {
|
| 468 |
+
assert.Equal(at, models.TenantActivityStatusHOT, tn.ActivityStatus)
|
| 469 |
+
break
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
}, 5*time.Second, time.Second, fmt.Sprintf("tenant was never %s", models.TenantActivityStatusHOT))
|
| 473 |
+
})
|
| 474 |
+
})
|
| 475 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/qna-transformers/qna_test.go
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"encoding/json"
|
| 16 |
+
"fmt"
|
| 17 |
+
"os"
|
| 18 |
+
"testing"
|
| 19 |
+
|
| 20 |
+
"github.com/stretchr/testify/assert"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
|
| 24 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/books"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
func Test_QnATransformers(t *testing.T) {
|
| 28 |
+
helper.SetupClient(os.Getenv(weaviateEndpoint))
|
| 29 |
+
// Contextionary with QnA module config present
|
| 30 |
+
booksClass := books.ClassContextionaryVectorizerWithQnATransformers()
|
| 31 |
+
helper.CreateClass(t, booksClass)
|
| 32 |
+
defer helper.DeleteClass(t, booksClass.Class)
|
| 33 |
+
// Contextionary without QnA module config present
|
| 34 |
+
booksWithoutQnAConfig := "BooksWithoutConfig"
|
| 35 |
+
booksWithoutQnAConfigClass := books.ClassContextionaryVectorizerWithName(booksWithoutQnAConfig)
|
| 36 |
+
helper.CreateClass(t, booksWithoutQnAConfigClass)
|
| 37 |
+
defer helper.DeleteClass(t, booksWithoutQnAConfigClass.Class)
|
| 38 |
+
// Text2VecTransformers with QnA module config present
|
| 39 |
+
booksTransformers := "BooksTransformers"
|
| 40 |
+
booksTransformersClass := books.ClassTransformersVectorizerWithQnATransformersWithName(booksTransformers)
|
| 41 |
+
helper.CreateClass(t, booksTransformersClass)
|
| 42 |
+
defer helper.DeleteClass(t, booksTransformersClass.Class)
|
| 43 |
+
// Text2VecTransformers without QnA module config present
|
| 44 |
+
booksTransformersWithoutQnAConfig := "BooksTransformersWithoutConfig"
|
| 45 |
+
booksTransformersWithoutQnAConfigClass := books.ClassTransformersVectorizerWithName(booksTransformersWithoutQnAConfig)
|
| 46 |
+
helper.CreateClass(t, booksTransformersWithoutQnAConfigClass)
|
| 47 |
+
defer helper.DeleteClass(t, booksTransformersWithoutQnAConfigClass.Class)
|
| 48 |
+
|
| 49 |
+
t.Run("add data to Books schema", func(t *testing.T) {
|
| 50 |
+
bookObjects := []*models.Object{}
|
| 51 |
+
bookObjects = append(bookObjects, books.Objects()...)
|
| 52 |
+
bookObjects = append(bookObjects, books.ObjectsWithName(booksWithoutQnAConfig)...)
|
| 53 |
+
bookObjects = append(bookObjects, books.ObjectsWithName(booksTransformers)...)
|
| 54 |
+
bookObjects = append(bookObjects, books.ObjectsWithName(booksTransformersWithoutQnAConfig)...)
|
| 55 |
+
for _, book := range bookObjects {
|
| 56 |
+
helper.CreateObject(t, book)
|
| 57 |
+
helper.AssertGetObjectEventually(t, book.Class, book.ID)
|
| 58 |
+
}
|
| 59 |
+
})
|
| 60 |
+
|
| 61 |
+
t.Run("ask", func(t *testing.T) {
|
| 62 |
+
for _, class := range []*models.Class{booksClass, booksWithoutQnAConfigClass, booksTransformersClass, booksTransformersWithoutQnAConfigClass} {
|
| 63 |
+
t.Run(class.Class, func(t *testing.T) {
|
| 64 |
+
query := `
|
| 65 |
+
{
|
| 66 |
+
Get {
|
| 67 |
+
%s(
|
| 68 |
+
ask: {
|
| 69 |
+
question: "Who is Dune's author?"
|
| 70 |
+
}
|
| 71 |
+
limit: 1
|
| 72 |
+
){
|
| 73 |
+
title
|
| 74 |
+
_additional {
|
| 75 |
+
answer {
|
| 76 |
+
hasAnswer
|
| 77 |
+
property
|
| 78 |
+
result
|
| 79 |
+
startPosition
|
| 80 |
+
endPosition
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
`
|
| 87 |
+
result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, fmt.Sprintf(query, class.Class))
|
| 88 |
+
books := result.Get("Get", class.Class).AsSlice()
|
| 89 |
+
expected := []interface{}{
|
| 90 |
+
map[string]interface{}{
|
| 91 |
+
"title": "Dune",
|
| 92 |
+
"_additional": map[string]interface{}{
|
| 93 |
+
"answer": map[string]interface{}{
|
| 94 |
+
"endPosition": json.Number("74"),
|
| 95 |
+
"hasAnswer": true,
|
| 96 |
+
"property": "description",
|
| 97 |
+
"result": "frank herbert",
|
| 98 |
+
"startPosition": json.Number("61"),
|
| 99 |
+
},
|
| 100 |
+
},
|
| 101 |
+
},
|
| 102 |
+
}
|
| 103 |
+
assert.ElementsMatch(t, expected, books)
|
| 104 |
+
})
|
| 105 |
+
}
|
| 106 |
+
})
|
| 107 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/qna-transformers/setup_test.go
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/pkg/errors"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const weaviateEndpoint = "WEAVIATE_ENDPOINT"
|
| 24 |
+
|
| 25 |
+
func TestMain(m *testing.M) {
|
| 26 |
+
ctx := context.Background()
|
| 27 |
+
compose, err := docker.New().
|
| 28 |
+
WithWeaviate().
|
| 29 |
+
WithText2VecContextionary().
|
| 30 |
+
WithText2VecTransformers().
|
| 31 |
+
WithQnATransformers().
|
| 32 |
+
Start(ctx)
|
| 33 |
+
if err != nil {
|
| 34 |
+
panic(errors.Wrapf(err, "cannot start"))
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
os.Setenv(weaviateEndpoint, compose.GetWeaviate().URI())
|
| 38 |
+
code := m.Run()
|
| 39 |
+
|
| 40 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 41 |
+
panic(errors.Wrapf(err, "cannot terminate"))
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
os.Exit(code)
|
| 45 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/ref2vec-centroid/centroid_test.go
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"os"
|
| 16 |
+
"testing"
|
| 17 |
+
|
| 18 |
+
"github.com/go-openapi/strfmt"
|
| 19 |
+
"github.com/stretchr/testify/assert"
|
| 20 |
+
"github.com/weaviate/weaviate/entities/models"
|
| 21 |
+
"github.com/weaviate/weaviate/entities/schema/crossref"
|
| 22 |
+
"github.com/weaviate/weaviate/test/helper"
|
| 23 |
+
"github.com/weaviate/weaviate/test/helper/sample-schema/articles"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
func TestCentroid(t *testing.T) {
|
| 27 |
+
helper.SetupClient(os.Getenv(weaviateEndpoint))
|
| 28 |
+
|
| 29 |
+
paragraphClass := articles.ParagraphsClass()
|
| 30 |
+
articleClass := articles.ArticlesClass()
|
| 31 |
+
articleClass.ModuleConfig = map[string]interface{}{
|
| 32 |
+
"ref2vec-centroid": map[string]interface{}{
|
| 33 |
+
"referenceProperties": []string{"hasParagraphs"},
|
| 34 |
+
},
|
| 35 |
+
}
|
| 36 |
+
articleClass.Vectorizer = "ref2vec-centroid"
|
| 37 |
+
|
| 38 |
+
helper.CreateClass(t, paragraphClass)
|
| 39 |
+
helper.CreateClass(t, articleClass)
|
| 40 |
+
|
| 41 |
+
defer func() {
|
| 42 |
+
helper.DeleteClass(t, articleClass.Class)
|
| 43 |
+
helper.DeleteClass(t, paragraphClass.Class)
|
| 44 |
+
}()
|
| 45 |
+
|
| 46 |
+
para1 := articles.NewParagraph().
|
| 47 |
+
WithVector([]float32{2, 4, 6}).
|
| 48 |
+
WithContents(
|
| 49 |
+
"Anyone who cares about JDM engines knows about the RB26.")
|
| 50 |
+
helper.CreateObject(t, para1.Object())
|
| 51 |
+
|
| 52 |
+
para2 := articles.NewParagraph().
|
| 53 |
+
WithVector([]float32{4, 6, 8}).
|
| 54 |
+
WithContents(
|
| 55 |
+
"It is best known for its use in the legendary Skyline GT-R.")
|
| 56 |
+
helper.CreateObject(t, para2.Object())
|
| 57 |
+
|
| 58 |
+
t.Run("create object with references", func(t *testing.T) {
|
| 59 |
+
t.Run("with one reference", func(t *testing.T) {
|
| 60 |
+
article := articles.NewArticle().
|
| 61 |
+
WithTitle("Popularity of the Nissan RB26DETT").
|
| 62 |
+
WithReferences(&models.SingleRef{
|
| 63 |
+
Beacon: newBeacon(para1.Class, para1.ID),
|
| 64 |
+
})
|
| 65 |
+
helper.CreateObject(t, article.Object())
|
| 66 |
+
defer helper.DeleteObject(t, article.Object())
|
| 67 |
+
|
| 68 |
+
res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 69 |
+
assert.EqualValues(t, para1.Vector, res.Vector)
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
t.Run("with multiple references", func(t *testing.T) {
|
| 73 |
+
article := articles.NewArticle().
|
| 74 |
+
WithTitle("Popularity of the Nissan RB26DETT").
|
| 75 |
+
WithReferences(
|
| 76 |
+
&models.SingleRef{Beacon: newBeacon(para1.Class, para1.ID)},
|
| 77 |
+
&models.SingleRef{Beacon: newBeacon(para2.Class, para2.ID)},
|
| 78 |
+
)
|
| 79 |
+
helper.CreateObject(t, article.Object())
|
| 80 |
+
defer helper.DeleteObject(t, article.Object())
|
| 81 |
+
|
| 82 |
+
res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 83 |
+
expectedVec := []float32{3, 5, 7}
|
| 84 |
+
assert.EqualValues(t, expectedVec, res.Vector)
|
| 85 |
+
})
|
| 86 |
+
})
|
| 87 |
+
|
| 88 |
+
t.Run("create object and PUT references", func(t *testing.T) {
|
| 89 |
+
article := articles.NewArticle().
|
| 90 |
+
WithTitle("Popularity of the Nissan RB26DETT")
|
| 91 |
+
|
| 92 |
+
helper.CreateObject(t, article.Object())
|
| 93 |
+
defer helper.DeleteObject(t, article.Object())
|
| 94 |
+
|
| 95 |
+
res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 96 |
+
assert.Nil(t, res.Vector)
|
| 97 |
+
assert.Equal(t, article.ID, res.ID)
|
| 98 |
+
|
| 99 |
+
article.WithReferences(
|
| 100 |
+
&models.SingleRef{Beacon: newBeacon(para1.Class, para1.ID)},
|
| 101 |
+
&models.SingleRef{Beacon: newBeacon(para2.Class, para2.ID)},
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
helper.UpdateObject(t, article.Object())
|
| 105 |
+
|
| 106 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 107 |
+
assert.Equal(t, article.ID, res.ID)
|
| 108 |
+
expectedVec := []float32{3, 5, 7}
|
| 109 |
+
assert.EqualValues(t, expectedVec, res.Vector)
|
| 110 |
+
})
|
| 111 |
+
|
| 112 |
+
t.Run("create object with references, remove references", func(t *testing.T) {
|
| 113 |
+
ref1 := &models.SingleRef{Beacon: newBeacon(para1.Class, para1.ID)}
|
| 114 |
+
ref2 := &models.SingleRef{Beacon: newBeacon(para2.Class, para2.ID)}
|
| 115 |
+
|
| 116 |
+
article := articles.NewArticle().
|
| 117 |
+
WithTitle("Popularity of the Nissan RB26DETT").
|
| 118 |
+
WithReferences(ref1, ref2)
|
| 119 |
+
helper.CreateObject(t, article.Object())
|
| 120 |
+
defer helper.DeleteObject(t, article.Object())
|
| 121 |
+
|
| 122 |
+
res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 123 |
+
expectedVec := []float32{3, 5, 7}
|
| 124 |
+
assert.EqualValues(t, expectedVec, res.Vector)
|
| 125 |
+
|
| 126 |
+
helper.DeleteReference(t, article.Object(), ref2, "hasParagraphs")
|
| 127 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 128 |
+
assert.EqualValues(t, para1.Vector, res.Vector)
|
| 129 |
+
|
| 130 |
+
helper.DeleteReference(t, article.Object(), ref1, "hasParagraphs")
|
| 131 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 132 |
+
assert.Nil(t, res.Vector)
|
| 133 |
+
})
|
| 134 |
+
|
| 135 |
+
t.Run("create object add references, remove references", func(t *testing.T) {
|
| 136 |
+
ref1 := &models.SingleRef{Beacon: newBeacon(para1.Class, para1.ID)}
|
| 137 |
+
ref2 := &models.SingleRef{Beacon: newBeacon(para2.Class, para2.ID)}
|
| 138 |
+
|
| 139 |
+
article := articles.NewArticle().
|
| 140 |
+
WithTitle("Popularity of the Nissan RB26DETT")
|
| 141 |
+
helper.CreateObject(t, article.Object())
|
| 142 |
+
defer helper.DeleteObject(t, article.Object())
|
| 143 |
+
|
| 144 |
+
res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 145 |
+
assert.Nil(t, res.Vector)
|
| 146 |
+
|
| 147 |
+
helper.AddReference(t, article.Object(), ref1, "hasParagraphs")
|
| 148 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 149 |
+
assert.EqualValues(t, para1.Vector, res.Vector)
|
| 150 |
+
|
| 151 |
+
helper.AddReference(t, article.Object(), ref2, "hasParagraphs")
|
| 152 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 153 |
+
assert.EqualValues(t, []float32{3, 5, 7}, res.Vector)
|
| 154 |
+
|
| 155 |
+
helper.DeleteReference(t, article.Object(), ref1, "hasParagraphs")
|
| 156 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 157 |
+
assert.EqualValues(t, para2.Vector, res.Vector)
|
| 158 |
+
|
| 159 |
+
helper.DeleteReference(t, article.Object(), ref2, "hasParagraphs")
|
| 160 |
+
res = helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 161 |
+
assert.Nil(t, res.Vector)
|
| 162 |
+
})
|
| 163 |
+
|
| 164 |
+
t.Run("batch create objects", func(t *testing.T) {
|
| 165 |
+
ref1 := &models.SingleRef{Beacon: newBeacon(para1.Class, para1.ID)}
|
| 166 |
+
ref2 := &models.SingleRef{Beacon: newBeacon(para2.Class, para2.ID)}
|
| 167 |
+
|
| 168 |
+
article1 := articles.NewArticle().
|
| 169 |
+
WithTitle("Popularity of the Nissan RB26DETT").
|
| 170 |
+
WithReferences(ref1, ref2)
|
| 171 |
+
defer helper.DeleteObject(t, article1.Object())
|
| 172 |
+
|
| 173 |
+
article2 := articles.NewArticle().
|
| 174 |
+
WithTitle("A Nissan RB Origin Story").
|
| 175 |
+
WithReferences(ref1, ref2)
|
| 176 |
+
defer helper.DeleteObject(t, article2.Object())
|
| 177 |
+
|
| 178 |
+
batch := []*models.Object{article1.Object(), article2.Object()}
|
| 179 |
+
helper.CreateObjectsBatch(t, batch)
|
| 180 |
+
|
| 181 |
+
res := helper.AssertGetObject(t, article1.Class, article1.ID, "vector")
|
| 182 |
+
assert.EqualValues(t, []float32{3, 5, 7}, res.Vector)
|
| 183 |
+
res = helper.AssertGetObject(t, article2.Class, article2.ID, "vector")
|
| 184 |
+
assert.EqualValues(t, []float32{3, 5, 7}, res.Vector)
|
| 185 |
+
})
|
| 186 |
+
|
| 187 |
+
// TODO: Uncomment when batch refs supports centroid re-calc
|
| 188 |
+
//t.Run("batch create references", func(t *testing.T) {
|
| 189 |
+
// article := articles.NewArticle().
|
| 190 |
+
// WithTitle("Popularity of the Nissan RB26DETT")
|
| 191 |
+
// defer helper.DeleteObject(t, article.Object())
|
| 192 |
+
//
|
| 193 |
+
// refs := []*models.BatchReference{
|
| 194 |
+
// {
|
| 195 |
+
// From: strfmt.URI(crossref.NewSource("Article", "hasParagraphs", article.ID).String()),
|
| 196 |
+
// To: strfmt.URI(crossref.NewLocalhost("Paragraph", para1.ID).String()),
|
| 197 |
+
// },
|
| 198 |
+
// {
|
| 199 |
+
// From: strfmt.URI(crossref.NewSource("Article", "hasParagraphs", article.ID).String()),
|
| 200 |
+
// To: strfmt.URI(crossref.NewLocalhost("Paragraph", para2.ID).String()),
|
| 201 |
+
// },
|
| 202 |
+
// }
|
| 203 |
+
//
|
| 204 |
+
// helper.AddReferences(t, refs)
|
| 205 |
+
// res := helper.AssertGetObject(t, article.Class, article.ID, "vector")
|
| 206 |
+
// assert.EqualValues(t, []float32{3, 5, 7}, res.Vector)
|
| 207 |
+
//})
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
func newBeacon(className string, id strfmt.UUID) strfmt.URI {
|
| 211 |
+
return crossref.New("localhost", className, id).SingleRef().Beacon
|
| 212 |
+
}
|
platform/dbops/binaries/weaviate-src/test/modules/ref2vec-centroid/setup_test.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 13 |
+
|
| 14 |
+
import (
|
| 15 |
+
"context"
|
| 16 |
+
"os"
|
| 17 |
+
"testing"
|
| 18 |
+
|
| 19 |
+
"github.com/pkg/errors"
|
| 20 |
+
"github.com/weaviate/weaviate/test/docker"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const weaviateEndpoint = "WEAVIATE_ENDPOINT"
|
| 24 |
+
|
| 25 |
+
func TestMain(m *testing.M) {
|
| 26 |
+
ctx := context.Background()
|
| 27 |
+
compose, err := docker.New().
|
| 28 |
+
WithWeaviate().WithRef2VecCentroid().
|
| 29 |
+
Start(ctx)
|
| 30 |
+
if err != nil {
|
| 31 |
+
panic(errors.Wrapf(err, "cannot start"))
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
os.Setenv(weaviateEndpoint, compose.GetWeaviate().URI())
|
| 35 |
+
code := m.Run()
|
| 36 |
+
|
| 37 |
+
if err := compose.Terminate(ctx); err != nil {
|
| 38 |
+
panic(errors.Wrapf(err, "cannot terminate"))
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
os.Exit(code)
|
| 42 |
+
}
|