nekomeowww / go-pinecone

Golang API client for Pinecone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-pinecone

Go Reference Go Report Testing Building


This package is an API client for Pinecone, a SaaS vector database. With this package, users can easily perform Index and Vector data operations in Golang projects.

Introduction

Pinecone is a cloud-based vector database that enables users to store large-scale vector data and query them efficiently.

This repo aims to provide a simple and easy-to-use client for Golang users to interface with Pinecone. It supports all the operations that are available through the Pinecone API, such as creating and deleting indexes, inserting and querying vectors, and modifying index metadata, among other functionalities.

Installation

To install, simply run the following command:

go get -u github.com/nekomeowww/go-pinecone

Documentation

For a complete reference of the functions and types, please refer to the godoc documentation.

Get started

Initialize a new Pinecone client

package main

import (
    pinecone "github.com/nekomeowww/go-pinecone"
)

func main() {
    p, err := pinecone.New(
        pinecone.WithAPIKey("YOUR_API_KEY"),
        pinecone.WithEnvironment("YOUR_ACCOUNT_REGION"),
        pinecone.WithProjectName("YOUR_PROJECT_NAME"),
    )
    if err != nil {
        log.Fatal(err)
    }

    // Do something with the client
}

Enables debug and HTTP request dump

package main

import (
    pinecone "github.com/nekomeowww/go-pinecone"
)

func main() {
    p, err := pinecone.New(
        pinecone.WithAPIKey("YOUR_API_KEY"),
        pinecone.WithEnvironment("YOUR_ACCOUNT_REGION"),
        pinecone.WithProjectName("YOUR_PROJECT_NAME"),
    )
    if err != nil {
        log.Fatal(err)
    }

    // Enable debug
    p = p.Debug()
}

Establish a connection to interact with Vectors

package main

import (
    pinecone "github.com/nekomeowww/go-pinecone"
)

func main() {
    p, err := pinecone.New(
        pinecone.WithAPIKey("YOUR_API_KEY"),
        pinecone.WithEnvironment("YOUR_ACCOUNT_REGION"),
        pinecone.WithProjectName("YOUR_PROJECT_NAME"),
    )
    if err != nil {
        log.Fatal(err)
    }
}

Initialize a new Index client

Vector operations are performed on a given index, we initialize a new index client like:

package main

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

func main() {
	client, err := pinecone.NewIndexClient(
		pinecone.WithIndexName("YOUR_INDEX_NAME"),
		pinecone.WithEnvironment("YOUR_ACCOUNT_REGION"),
		pinecone.WithProjectName("YOUR_PROJECT_NAME"),
		pinecone.WithAPIKey("YOUR_API_KEY"),
	)

	if err != nil {
		log.Fatal(err)
	}
}

To describe index stats we can use:

	ctx := context.Background()

	params := pinecone.DescribeIndexStatsParams{}
	resp, err := client.DescribeIndexStats(ctx, params)
	if err != nil {
		panic(err)
	}
	for k, v := range resp.Namespaces {
		fmt.Printf("%s: %+v\n", k, v)
	}

To Upsert Vectors we do such as:

    // Use your own embedding client/library such as OpenAI embedding API
    myVectorEmbedding := embedding.New("this is a sentence I want to embed")
	
    ctx := context.Background()
    params := pinecone.UpsertVectorsParams{
        Vectors: []*pinecone.Vector{
            {
                ID: "YOUR_VECTOR_ID",
                Values: myVectorEmbedding,
                Metadata: map[string]any{"foo": "bar"}
            },
        },
    }
    resp, err := client.UpsertVectors(ctx, params)
    if err != nil {
        panic(err)
    }
    fmt.Printf("%+v\n", resp)

For a complete reference of the functions and types, please refer to the godoc documentation.

Contributing

We welcome contributions from the Golang community! If you'd like to contribute, please follow these steps:

  1. Fork this repository
  2. Create a new branch for your changes
  3. Make the changes
  4. Commit your changes with a meaningful commit message
  5. Create a pull request

Acknowledgements

License

Released under the MIT License.

About

Golang API client for Pinecone

License:MIT License


Languages

Language:Go 100.0%