Skip to content

Release v3.1.0

Compare
Choose a tag to compare
@austin-denoble austin-denoble released this 20 Mar 07:16
· 8 commits to main since this release

Features

Indexes with integrated inference

This release adds a new CreateIndexForModel method to the Client class, and UpsertRecords and SearchRecords to the IndexConnection class. These methods allow you to work with integrated inference, and provide a way for you to easily store your data and let us manage the process of creating embeddings. To learn about available models, see the Model Gallery.

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/pinecone-io/go-pinecone/v3/pinecone"
)

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

	clientParams := pinecone.NewClientParams{
		ApiKey: os.Getenv("PINECONE_API_KEY"),
	}

	pc, err := pinecone.NewClient(clientParams)
	if err != nil {
		log.Fatalf("Failed to create Client: %v", err)
	} else {
		fmt.Println("Successfully created a new Client object!")
	}

	// Create an integrated index
	index, err := pc.CreateIndexForModel(ctx, &pinecone.CreateIndexForModelRequest{
		Name:   "integrated-index",
		Cloud:  "aws",
		Region: "us-east-1",
		Embed: pinecone.CreateIndexForModelEmbed{
			Model:    "multilingual-e5-large",
			FieldMap: map[string]interface{}{"text": "chunk_text"},
		},
	})

	if err != nil {
		log.Fatalf("Failed to create serverless integrated index: %v", err)
	} else {
		fmt.Printf("Successfully created serverless integrated index: %s", index.Name)
	}

	idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: index.Host, Namespace: "my-namespace"})
	if err != nil {
		log.Fatalf("Failed to connect to index: %v", err)
	}

	records := []*pinecone.IntegratedRecord{
		{
			"_id":        "rec1",
			"chunk_text": "Apple's first product, the Apple I, was released in 1976 and was hand-built by co-founder Steve Wozniak.",
			"category":   "product",
		},
		{
			"_id":        "rec2",
			"chunk_text": "Apples are a great source of dietary fiber, which supports digestion and helps maintain a healthy gut.",
			"category":   "nutrition",
		},
		{
			"_id":        "rec3",
			"chunk_text": "Apples originated in Central Asia and have been cultivated for thousands of years, with over 7,500 varieties available today.",
			"category":   "cultivation",
		},
		{
			"_id":        "rec4",
			"chunk_text": "In 2001, Apple released the iPod, which transformed the music industry by making portable music widely accessible.",
			"category":   "product",
		},
		{
			"_id":        "rec5",
			"chunk_text": "Apple went public in 1980, making history with one of the largest IPOs at that time.",
			"category":   "milestone",
		},
		{
			"_id":        "rec6",
			"chunk_text": "Rich in vitamin C and other antioxidants, apples contribute to immune health and may reduce the risk of chronic diseases.",
			"category":   "nutrition",
		},
		{
			"_id":        "rec7",
			"chunk_text": "Known for its design-forward products, Apple's branding and market strategy have greatly influenced the technology sector and popularized minimalist design worldwide.",
			"category":   "influence",
		},
		{
			"_id":        "rec8",
			"chunk_text": "The high fiber content in apples can also help regulate blood sugar levels, making them a favorable snack for people with diabetes.",
			"category":   "nutrition",
		},
	}

	// Upsert text records
	err = idxConnection.UpsertRecords(ctx, records)
	if err != nil {
		log.Fatalf("Failed to upsert vectors. Error: %v", err)
	}

	// Search for relevant records and rerank results
	topN := int32(2)
	res, err := idxConnection.SearchRecords(ctx, &pinecone.SearchRecordsRequest{
		Query: pinecone.SearchRecordsQuery{
			TopK: 5,
			Inputs: &map[string]interface{}{
				"text": "Disease prevention",
			},
		},
		Rerank: &pinecone.SearchRecordsRerank{
			Model:      "bge-reranker-v2-m3",
			TopN:       &topN,
			RankFields: []string{"chunk_text"},
		},
		Fields: &[]string{"chunk_text", "category"},
	})
	if err != nil {
		log.Fatalf("Failed to search records: %v", err)
	}
	fmt.Printf("Search results: %+v\n", res)
}

What's Changed

Full Changelog: v3.0.0...v3.1.0