Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Problem The `2024-07` release of the Pinecone API included [Inference operations](https://docs.pinecone.io/reference/api/2024-07/inference/generate-embeddings). 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. - Add new structs: `EmbedRequest`, `EmbedParameters`, and `InferenceService`. Add a new `Inference` field to `Client` which holds an `*InferenceService` value allowing users to interact with the Inference API. - Attach new `Embed` method to `InferenceService` which wraps the underlying `Embed` call on `*control.Client`, and handles massaging the input and output to match the generated types. - Add new integration tests to cover `Embed` in `client_test.go`. - Add doc comments to new code, update README to include an Inference section. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## 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: ```bash go get github.com/pinecone-io/go-pinecone@adenoble/implement-inference ``` In your Go code: ```go 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) ```
- Loading branch information