AI

Weaviate Go

Weaviate is a cloud-native, modular, real-time vector search engine that allows us to implement the use-case-specific features. Weaviate utilizes the vectorization technologies to group the data and finds similarities between various data points. It also provides GraphQL and RESTful APIs that provide a wide range of possibilities to query and mutate the data.

Weaviate provides a powerful Go client for Go developers which allows us to connect and interact with the Weaviate cluster using the Go programming language.

This tutorial covers the fundamentals of installing, configuring, and using this client to perform various actions on the Weaviate cluster.

Prerequisites:

  1. Golang compiler – Ensure that you install the latest Go compiler on your machine before proceeding.
  2. Weaviate server – You also need a running instance of the Weaviate server. You can set up a local cluster using Docker and Kubernetes or a cloud-hosted instance.

With the given requirements met, we can proceed to the installation process.

Install the Weaviate Go Client

The first step is installing the Weaviate Go client. You can do this using the “go get” command as shown in the following:

go get github.com/weaviate/weaviate-go-client/v4

This should download the latest stable version of the Weaviate Go client on your machine.

Connect to the Weaviate Server

To use the Weaviate client, import the client library first and create a new client object.

package main

import (
    "context"
    "fmt"
    "github.com/weaviate/weaviate-go-client/v4/weaviate"
)

func main() {}
cfg := weaviate.Config{
    Host:   "localhost:8080",
    Scheme: "http",
}
    client, err := weaviate.NewClient(cfg)
    if err != nil {
        panic(err)
    }
}

In the given example, we start by importing the required packages. In this case, we need the context, fmt, and the Weaviate packages.

Once imported, we use the Weaviate package to initialize a new client with the specified configuration.

Conclusion

We covered how you can quickly configure your Go application to connect to the Weaviate cluster.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list