Skip to content

Release v2.2.0

Latest
Compare
Choose a tag to compare
@austin-denoble austin-denoble released this 07 Jan 17:01

This release includes a fix to the go.mod file which properly updates the module to include "v2": module github.com/pinecone-io/go-pinecone/v2. This allows proper installation and documentation of v2.X.X.

This release also includes features from the previous two releases (v2.0.0, and v2.1.0):

Features

Rerank

The InferenceService has a new operation called Rerank which provides users the ability to rerank documents in descending relevance-order against a given query. Reranking documents is a common "second-pass" ranking strategy broadly used in retrieval applications.

package main

import (
    "context"
    "fmt"
    "log"

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

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

    pc, err := pinecone.NewClient(pinecone.NewClientParams{
        ApiKey: "YOUR_API_KEY",
    })
    if err != nil {
        log.Fatalf("Failed to create Client: %v", err)
    }

    rerankModel := "bge-reranker-v2-m3"
    topN := 4
    returnDocuments := true
    documents := []pinecone.Document{
        {"id": "vec1", "my_field": "Apple is a popular fruit known for its sweetness and crisp texture."},
        {"id": "vec2", "my_field": "Many people enjoy eating apples as a healthy snack."},
        {"id": "vec3", "my_field": "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."},
        {"id": "vec4", "my_field": "An apple a day keeps the doctor away, as the saying goes."},
    }

    ranking, err := pc.Inference.Rerank(ctx, &pinecone.RerankRequest{
        Model:           rerankModel,
        Query:           "The tech company Apple is known for its innovative products like the iPhone.",
        ReturnDocuments: &returnDocuments,
        TopN:            &topN,
        RankFields:      &[]string{"my_field"},
        Documents:       documents,
    })
    if err != nil {
        log.Fatalf("Failed to rerank: %v", err)
    }
    fmt.Printf("Rerank result: %+v\n", ranking)
}

Import

IndexConnection now exposes additional methods for working with Import operations. An Import is a long-running, asynchronous operation that gives users the ability to import vectors directly from object storage (e.g. S3) into a Pinecone index. It is intended to be used with large-scale jobs. For small-scale jobs (e.g. <1000 vectors), we recommend continuing to use upsert.

package main

import (
    "context"
    "fmt"
    "log"

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

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

    pc, err := pinecone.NewClient(pinecone.NewClientParams{
        ApiKey: "YOUR_API_KEY",
    })
    if err != nil {
        log.Fatalf("Failed to create Client: %v", err)
    }

    idx, err := pc.DescribeIndex(ctx, "example-name")
    if err != nil {
        log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err)
    }

    idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: idx.Host})
    if err != nil {
        log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err)
    }

    uri := "s3://BUCKET_NAME/PATH/TO/DIR"
    
    // Start an import
    errorMode := "continue" // or "abort"
    importRes, err := idxConnection.StartImport(ctx, uri, nil, (*pinecone.ImportErrorMode)(&errorMode))
    if err != nil {
        log.Fatalf("Failed to start import: %v", err)
    }
    fmt.Printf("Import started with ID: %s", importRes.Id)

    // Describe an import
    importDesc, err := idxConnection.DescribeImport(ctx, importRes.Id)
    if err != nil {
        log.Fatalf("Failed to describe import: %s - %v", importRes.Id, err)
    }
    fmt.Printf("Import ID: %s, Status: %s", importDesc.Id, importDesc.Status)

    // List imports
    limit := int32(10)
    firstImportPage, err := idxConnection.ListImports(ctx, &limit, nil)
    if err != nil {
        log.Fatalf("Failed to list imports: %v", err)
    }
    fmt.Printf("First page of imports: %+v", firstImportPage.Imports)

    paginationToken := firstImportPage.NextPaginationToken
    nextImportPage, err := idxConnection.ListImports(ctx, &limit, paginationToken)
    if err != nil {
        log.Fatalf("Failed to list imports: %v", err)
    }
    fmt.Printf("Second page of imports: %+v", nextImportPage.Imports)

    // Cancel import
    err = idxConnection.CancelImport(ctx, importRes.Id)
    if err != nil {
        log.Fatalf("Failed to cancel import: %s", importRes.Id)
    }
}

Index Tags

You can now assign index tags when creating or configuring indexes. Tags are key-value pairs that you can use to categorize and identify the index.

package main

import (
    "context"
    "fmt"
    "log"

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

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

    pc, err := pinecone.NewClient(pinecone.NewClientParams{
        ApiKey: "YOUR_API_KEY",
    })

    if err != nil {
        log.Fatalf("Failed to create Client: %v", err)
    }

    // Create an index with Tags
    idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{
        Name:      "my-tagged-index",
        Dimension: 3,
        Metric:    pinecone.Cosine,
        Cloud:     pinecone.Aws,
        Region:    "us-east-1",
        Tags:       &pinecone.IndexTags{ "environment": "development" },
    })

    if err != nil {
        log.Fatalf("Failed to create index: %v", err)
    }

    // Update an index's Tags with ConfigureIndex
    idx, err = pc.ConfigureIndex(context.Background(),
		ts.idxName,
		pinecone.ConfigureIndexParams{Tags: IndexTags{"environment": "production"}})
    
    if err != nil {
        log.Fatalf("Failed to configure index: %v", err)
    }
}

What's Changed

Full Changelog: v2.1.0...v2.2.0