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.
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.
To install, simply run the following command:
go get -u github.com/nekomeowww/go-pinecone
For a complete reference of the functions and types, please refer to the godoc documentation.
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
}
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()
}
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)
}
}
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.
We welcome contributions from the Golang community! If you'd like to contribute, please follow these steps:
- Fork this repository
- Create a new branch for your changes
- Make the changes
- Commit your changes with a meaningful commit message
- Create a pull request
- Official Pinecone Index Client go-pinecone
Released under the MIT License.