weaviate

package module
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 5 Imported by: 2

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 Run added in v0.32.0

Run creates an instance of the Weaviate container type

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"
	tcweaviate "github.com/testcontainers/testcontainers-go/modules/weaviate"
)

func main() {
	// runWeaviateContainer {
	ctx := context.Background()

	weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.29.0")
	defer func() {
		if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}
	// }

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

	fmt.Println(state.Running)

}
Output:
true
Example (ConnectWithClient)
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"time"

	"github.com/weaviate/weaviate-go-client/v5/weaviate"
	"github.com/weaviate/weaviate-go-client/v5/weaviate/grpc"

	"github.com/testcontainers/testcontainers-go"
	tcweaviate "github.com/testcontainers/testcontainers-go/modules/weaviate"
)

func main() {
	// createClientNoModules {
	ctx := context.Background()

	weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.28.7")
	defer func() {
		if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}

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

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

	connectionClient := &http.Client{}
	headers := map[string]string{
		// put here the custom API key, e.g. for OpenAPI
		"Authorization": "Bearer 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)
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"strings"
	"time"

	"github.com/weaviate/weaviate-go-client/v5/weaviate"
	"github.com/weaviate/weaviate-go-client/v5/weaviate/grpc"

	"github.com/testcontainers/testcontainers-go"
	tcweaviate "github.com/testcontainers/testcontainers-go/modules/weaviate"
)

func main() {
	// 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.WithEnv(envs),
	}

	weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.25.5", opts...)
	defer func() {
		if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}

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

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

	connectionClient := &http.Client{}
	headers := map[string]string{
		// put here the custom API key, e.g. for OpenAPI
		"Authorization": "Bearer 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 RunContainer deprecated

Deprecated: use Run instead RunContainer creates an instance of the Weaviate container type

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