weaviate

package module
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WeaviateContainer

type WeaviateContainer struct {
	testcontainers.Container
}

WeaviateContainer represents the Weaviate container type used in the module

func RunContainer

func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error)

RunContainer creates an instance of the Weaviate container type

Example
// runWeaviateContainer {
ctx := context.Background()

weaviateContainer, err := tcweaviate.RunContainer(ctx, testcontainers.WithImage("semitechnologies/weaviate:1.24.5"))
if err != nil {
	log.Fatalf("failed to start container: %s", err)
}

// Clean up the container
defer func() {
	if err := weaviateContainer.Terminate(ctx); err != nil {
		log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
	}
}()
// }

state, err := weaviateContainer.State(ctx)
if err != nil {
	log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
}

fmt.Println(state.Running)
Output:

true
Example (ConnectWithClient)
// createClientNoModules {
ctx := context.Background()

weaviateContainer, err := tcweaviate.RunContainer(ctx, testcontainers.WithImage("semitechnologies/weaviate:1.23.9"))
if err != nil {
	log.Fatalf("failed to start container: %s", err)
}

defer func() {
	if err := weaviateContainer.Terminate(ctx); err != nil {
		log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
	}
}()

scheme, host, err := weaviateContainer.HttpHostAddress(ctx)
if err != nil {
	log.Fatalf("failed to get http schema and host: %s", err) // nolint:gocritic
}

grpcHost, err := weaviateContainer.GrpcHostAddress(ctx)
if err != nil {
	log.Fatalf("failed to get gRPC host: %s", err) // nolint:gocritic
}

connectionClient := &http.Client{}
headers := map[string]string{
	// put here the custom API key, e.g. for OpenAPI
	"Authorization": fmt.Sprintf("Bearer %s", "custom-api-key"),
}

cli := weaviate.New(weaviate.Config{
	Scheme: scheme,
	Host:   host,
	GrpcConfig: &grpc.Config{
		Secured: false, // set true if gRPC connection is secured
		Host:    grpcHost,
	},
	Headers:          headers,
	AuthConfig:       nil, // put here the weaviate auth.Config, if you need it
	ConnectionClient: connectionClient,
})

err = cli.WaitForWeavaite(5 * time.Second)
// }
fmt.Println(err)
Output:

<nil>
Example (ConnectWithClientWithModules)
// createClientAndModules {
ctx := context.Background()

enableModules := []string{
	"backup-filesystem",
	"text2vec-openai",
	"text2vec-cohere",
	"text2vec-huggingface",
	"generative-openai",
}
envs := map[string]string{
	"ENABLE_MODULES":         strings.Join(enableModules, ","),
	"BACKUP_FILESYSTEM_PATH": "/tmp/backups",
}

opts := []testcontainers.ContainerCustomizer{
	testcontainers.WithImage("semitechnologies/weaviate:1.24.5"),
	testcontainers.WithEnv(envs),
}

weaviateContainer, err := tcweaviate.RunContainer(ctx, opts...)
if err != nil {
	log.Fatalf("failed to start container: %s", err)
}

defer func() {
	if err := weaviateContainer.Terminate(ctx); err != nil {
		log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
	}
}()

scheme, host, err := weaviateContainer.HttpHostAddress(ctx)
if err != nil {
	log.Fatalf("failed to get http schema and host: %s", err) // nolint:gocritic
}

grpcHost, err := weaviateContainer.GrpcHostAddress(ctx)
if err != nil {
	log.Fatalf("failed to get gRPC host: %s", err) // nolint:gocritic
}

connectionClient := &http.Client{}
headers := map[string]string{
	// put here the custom API key, e.g. for OpenAPI
	"Authorization": fmt.Sprintf("Bearer %s", "custom-api-key"),
}

cli := weaviate.New(weaviate.Config{
	Scheme: scheme,
	Host:   host,
	GrpcConfig: &grpc.Config{
		Secured: false, // set true if gRPC connection is secured
		Host:    grpcHost,
	},
	Headers:          headers,
	AuthConfig:       nil, // put here the weaviate auth.Config, if you need it
	ConnectionClient: connectionClient,
})

err = cli.WaitForWeavaite(5 * time.Second)
// }
fmt.Println(err)
Output:

<nil>

func (*WeaviateContainer) GrpcHostAddress added in v0.30.0

func (c *WeaviateContainer) GrpcHostAddress(ctx context.Context) (string, error)

GrpcHostAddress returns the gRPC host of the Weaviate container. At the moment, it only supports unsecured gRPC connection.

func (*WeaviateContainer) HttpHostAddress

func (c *WeaviateContainer) HttpHostAddress(ctx context.Context) (string, string, error)

HttpHostAddress returns the schema and host of the Weaviate container. At the moment, it only supports the http scheme.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL