Skip to content

pinecone-io/go-pinecone

Repository files navigation

Warning

Under active development This SDK is pre-1.0 and should be considered unstable. Before a 1.0 release, there are no guarantees of backward compatibility between minor versions.

go-pinecone

Official Pinecone Go Client

Features

go-pinecone contains

  • gRPC bindings for Data Plane operations on Vectors
  • REST bindings for Control Plane operations on Indexes and Collections

See Pinecone API Docs for more info.

Installation

go-pinecone requires a Go version with modules support.

To add a dependency on go-pinecone:

go get github.com/pinecone-io/go-pinecone/pinecone

Usage

package main

import (
	"context"
	"fmt"
	"github.com/pinecone-io/go-pinecone/pinecone"
)

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

	pc, err := pinecone.NewClient(pinecone.NewClientParams{
		ApiKey: "api-key",
	})

	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	idxs, err := pc.ListIndexes(ctx)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	for _, index := range idxs {
		fmt.Println(index)
	}

	idx, err := pc.Index(idxs[0].Host)
	defer idx.Close()

	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	res, err := idx.DescribeIndexStats(ctx)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println(res)
}

Support

To get help using go-pinecone, reach out to [email protected].

Development

Prereqs

  1. A current version of Go (recommended 1.21+)
  2. The just command runner
  3. The protobuf-compiler

Then, execute just bootstrap to install the necessary Go packages

.env Setup

To avoid race conditions or having to wait for index creation, the tests require a project with at least one pod index and one serverless index. Copy the api key and index names to a .env file. See .env.example for a template.

API Definitions submodule

The API Definitions are in a private submodule. To checkout or update the submodules execute in the root of the project:

git submodule update --init --recursive

For working with submodules, see the Git Submodules documentation.

Just commands

just test : Executes all tests for the pinecone package

just gen : Generates Go client code from the API definitions

just docs : Generates Go docs and starts http server on localhost

just bootstrap : Installs necessary go packages for gen and docs