pinecone-io / go-pinecone

Pinecone.io Golang Client
Apache License 2.0
49 stars 9 forks source link

Implement Inference API #67

Closed austin-denoble closed 3 months ago

austin-denoble commented 3 months ago

Problem

The 2024-07 release of the Pinecone API included Inference operations. Currently pinecone-ts-client, pinecone-python-client, and pinecone-rust-client support Inference.

We'd like to expose the Embed operation in the Go SDK.

Solution

I followed a similar approach to how we've addressed adding inference in other SDKs. Specifically, after discussing things internally I've opted to add an Inference namespace to the Client struct to add separation between existing index management operations, and inference-related operations such as Embed. This approach is similar to the implementation in Python and TypeScript.

Type of Change

Test Plan

Added integration tests to validate calling the new client.Inference.Embed() function.

In order to test yourself you'll need to consume this branch as a dependency locally, and then call the Embed operation:

go get the branch for this PR:

go get github.com/pinecone-io/go-pinecone@adenoble/implement-inference

In your Go code:

ctx := context.Background()

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

embeddingModel := "multilingual-e5-large"
documents := []string{
    "Turkey is a classic meat to eat at American Thanksgiving."
    "Many people enjoy the beautiful mosques in Turkey."
}
docParameters := pinecone.EmbedParameters{
    InputType: "passage",
    Truncate: "END",
}

docEmbeddingsResponse, err := pc.Inference.Embed(ctx, &pinecone.EmbedRequest{
    Model: embeddingModel,
    TextInputs: documents,
    Parameters: docParameters,
})
if err != nil {
    log.Fatalf("Failed to embed documents: %v", err)
}
fmt.Printf("docs embedding response: %+v", docEmbeddingsResponse)