helix-go is a Go library for interacting with helix-db a powerful graph-vector database written in rust. It enables intuitive and type-safe access to graph-based and vector-based queries, making it ideal for building knowledge graphs, search systems, and LLM pipelines.

Installation

go get github.com/HelixDB/helix-go

Setup

To setup a simple Client to interface with a running helix instance:

import "github.com/HelixDB/helix-go"

// Create a new HelixDB client
var helixClient *helix.Client
helixClient = helix.NewClient("http://localhost:6969")

The default URL is http://localhost:6969. For cloud deployments, simply pass in the appropriate URL to the constructor.

Creating structs

You can create structs to represent the data returned from queries. This is useful for type safety and ease of use.


type GetUsersResponse struct {
	Users []struct {
		Name      string      `json:"name"`
		Age       int32       `json:"age"`
		Email     string      `json:"email"`
		CreatedAt interface{} `json:"created_at"`
		UpdatedAt interface{} `json:"updated_at"`
	} `json:"users"`
}

type CreateUserResponse struct {
	User struct {
		Name      string      `json:"name"`
		Age       int32       `json:"age"`
		Email     string      `json:"email"`
		CreatedAt interface{} `json:"created_at"`
		UpdatedAt interface{} `json:"updated_at"`
	} `json:"user"`
}

Running queries

You can run queries by passing the query name and data matching the query’s expected inputs.

// Create user data
now := time.Now()
timestamp := now.Unix()
timestamp32 := int32(timestamp)

newUser := map[string]any{
    "name":  "John",
    "age":   21,
    "email": "johndoe@email.com",
    "now":   timestamp32,
}

// Create user in Helix
var createdUser CreateUserResponse
	err := HelixClient.Query(
		"create_user",
		helix.WithData(newUser),
	).Scan(&createdUser)
	if err != nil {
		log.Fatalf("Error while creating user: %s", err)
	}

	fmt.Println("Created user:", createdUser)

// Get all users and put Helix's response in GetUsersResponse
var getUsersResponse GetUsersResponse
err = HelixClient.Query("get_users").Scan(&getUsersResponse)
if err != nil {
    log.Fatalf("Error while getting users: %s", err)
}

fmt.Println("Get users response:", getUsersResponse)

Full Code Example