Skip to content

Commit

Permalink
Add EmbedResponse type, regenerate core for 2024-10 (#83)
Browse files Browse the repository at this point in the history
## Problem
There have been a few small PRs that have gone into the `apis` repo that
we need to regenerate code for:

- pinecone-io/apis#175
- pinecone-io/apis#171

We're also returning the generated `EmbeddingsList` type for the `Embed`
method rather than a custom type like we're doing elsewhere.

## Solution
- Add new `EmbedResponse`, and `Embedding` types and return from
`Embed`. Add doc comments.
- Regenerate core SDK code from `2024-10`

## 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
Make sure CI is successful.
  • Loading branch information
austin-denoble committed Oct 23, 2024
1 parent 2e5dcbe commit 7a8dc36
Showing 5 changed files with 37 additions and 14 deletions.
8 changes: 4 additions & 4 deletions internal/gen/db_control/db_control_2024-10.oas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/gen/db_data/rest/db_data_2024-10.oas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions pinecone/client.go
Original file line number Diff line number Diff line change
@@ -1225,6 +1225,14 @@ func (c *Client) DeleteCollection(ctx context.Context, collectionName string) er
return nil
}

// InferenceService is a struct which exposes methods for interacting with the Pinecone Inference API. InferenceService
// can be accessed via the Client object through the Client.Inference namespace.
//
// [Pinecone Inference API]: https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models
type InferenceService struct {
client *inference.Client
}

// EmbedRequest holds the parameters for generating embeddings for a list of input strings.
//
// Fields:
@@ -1248,12 +1256,20 @@ type EmbedParameters struct {
Truncate string
}

// InferenceService is a struct which exposes methods for interacting with the Pinecone Inference API. InferenceService
// can be accessed via the Client object through the Client.Inference namespace.
// EmbedResponse represents holds the embeddings generated for a single input.
//
// [Pinecone Inference API]: https://docs.pinecone.io/guides/inference/understanding-inference#embedding-models
type InferenceService struct {
client *inference.Client
// Fields:
// - Data: A list of Embedding objects containing the embeddings generated for the input.
// - Model: The model used to generate the embeddings.
// - Usage: Usage statistics ([Total Tokens]) for the request.
//
// [Total Tokens]: https://docs.pinecone.io/guides/organizations/manage-cost/understanding-cost#embed
type EmbedResponse struct {
Data []Embedding `json:"data"`
Model string `json:"model"`
Usage struct {
TotalTokens *int `json:"total_tokens,omitempty"`
} `json:"usage"`
}

// Embed generates embeddings for a list of inputs using the specified model and (optional) parameters.
@@ -1298,7 +1314,7 @@ type InferenceService struct {
// } else {
// fmt.Printf("Successfull generated embeddings: %+v", res)
// }
func (i *InferenceService) Embed(ctx context.Context, in *EmbedRequest) (*inference.EmbeddingsList, error) {
func (i *InferenceService) Embed(ctx context.Context, in *EmbedRequest) (*EmbedResponse, error) {

if len(in.TextInputs) == 0 {
return nil, fmt.Errorf("TextInputs must contain at least one value")
@@ -1537,8 +1553,8 @@ func decodeIndex(resBody io.ReadCloser) (*Index, error) {
return toIndex(&idx), nil
}

func decodeEmbeddingsList(resBody io.ReadCloser) (*inference.EmbeddingsList, error) {
var embeddingsList inference.EmbeddingsList
func decodeEmbeddingsList(resBody io.ReadCloser) (*EmbedResponse, error) {
var embeddingsList EmbedResponse
err := json.NewDecoder(resBody).Decode(&embeddingsList)
if err != nil {
return nil, fmt.Errorf("failed to decode embeddings response: %w", err)
2 changes: 1 addition & 1 deletion pinecone/index_connection.go
Original file line number Diff line number Diff line change
@@ -1065,7 +1065,7 @@ func (idx *IndexConnection) StartImport(ctx context.Context, uri string, integra
}

req := db_data_rest.StartImportRequest{
Uri: &uri,
Uri: uri,
IntegrationId: integrationId,
}

7 changes: 7 additions & 0 deletions pinecone/models.go
Original file line number Diff line number Diff line change
@@ -177,6 +177,13 @@ type MetadataFilter = structpb.Struct
// [attached to, or updated for, a vector]: https://docs.pinecone.io/guides/data/filter-with-metadata#inserting-metadata-into-an-index
type Metadata = structpb.Struct

// The embedding of a single input which is returned after [generating embeddings].
//
// [generating embeddings]: https://docs.pinecone.io/guides/inference/generate-embeddings#3-generate-embeddings
type Embedding struct {
Values *[]float32 `json:"values,omitempty"`
}

// ImportStatus represents the status of an import operation.
//
// Values:

0 comments on commit 7a8dc36

Please sign in to comment.