Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Integrated Inference #103

Merged
merged 24 commits into from
Mar 20, 2025

Conversation

austin-denoble
Copy link
Contributor

@austin-denoble austin-denoble commented Mar 7, 2025

Problem

The integrated inference API was part of the 2025-01 release, and the code has been generated for Go, but the interface has not been wired up for use in the client.

Solution

Implement Integrated Inference:

  • Add CreateIndexForModel to Client struct.
  • Add UpsertRecords and SearchRecords to IndexConnection struct.
  • Add new types for working with integrated inference:
    • CreateIndexForModelRequest, CreateIndexForModelEmbed
    • IntegratedRecord
    • SearchRecordsRequest, SearchRecordsQuery, SearchRecordsRerank, SearchRecordsVector
    • Hit, SearchRecordsResponse, SearchUsage

Note: I've included some integration test refactoring in this PR. Was running into a lot of flakiness unrelated to this change.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • 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

Following example demonstrates creating an integrated index for a specific model, upserting some records, and then searching against those records.

package main

import (
	"context"
	"fmt"
	"github.com/pinecone-io/go-pinecone/v3/pinecone"
	"log"
	"os"
)

func main() {
	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!")
	}

	index, err := pc.CreateIndexForModel(ctx, &CreateIndexForModelRequest{
		Name:   "my-integrated-index",
		Cloud:  "aws",
		Region: "us-east-1",
		Embed: 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", idx.Name)
	}

	idxConnection, err := pc.Index(pinecone.NewIndexConnParams{Host: index.Host, Namespace: "my-namespace"})

	records := []*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",
			},
		}

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

	res, err := idxConnection.SearchRecords(ctx, &SearchRecordsRequest{
			Query: SearchRecordsQuery{
				TopK: 5,
				Inputs: &map[string]interface{}{
					"text": "Disease prevention",
				},
			},
	})
	if err != nil {
			log.Fatalf("Failed to search records: %v", err)
	}
	fmt.Printf("Search results: %+v\n", res)
}

@austin-denoble austin-denoble marked this pull request as ready for review March 17, 2025 15:46
@@ -777,83 +927,6 @@ func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) err
return idx.delete(ctx, &req)
}

// [UpdateVectorRequest] holds the parameters for the [IndexConnection.UpdateVector] method.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: moved this block up so it lives with the other vector operations

@@ -109,12 +118,12 @@ func (ts *IntegrationTests) TearDownSuite() {
}

// Helper funcs
func GenerateTestIndexName() string {
func generateTestIndexName() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: realized all these helpers were being exported out of the package itself, they should be lowercase

@@ -254,6 +264,45 @@ func BuildPodTestIndex(in *Client, name string, tags IndexTags) *Index {
return podIdx
}

func retryAssertions(t *testing.T, maxRetries int, delay time.Duration, fn func() error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These helper functions are used in integration tests and are otherwise unrelated to the other changes in this PR. We were seeing a lot of test failures and I needed to add some additional logic to retry specific requests, and poll for freshness in a more targeted way.

README.md Outdated
@@ -218,6 +218,53 @@ func main() {
}
```

**Create a serverless integrated index**

Integrated inference requires a serverless index configured for a specific embedding model. You can either create a new index for a model, or configure an existing index for a model. To create an index that accepts source text and converts it to vectors automatically using an embedding model hosted by Pinecone.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is this comment complete?

To create an index that accepts source text and converts it to vectors automatically using an embedding model hosted by Pinecone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, I think I lopped something off when editing.

golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/net v0.33.0 // indirect

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, are these changes manual or done as a part of the build process?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to add context for this in the PR, thanks for flagging.

This was manual, but it was due to PRs that have been put up by dependabot: #99

There was another one opened more recently to bump to 0.36.0, but that will also require bumping the base version of Go specified in the go.mod file, so I wanted to wait for a major release to do that.

@@ -1575,6 +1688,137 @@ indicating higher relevance.
fmt.Printf("rerank response: %+v", rerankResponse)
```

### Integrated Inference

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure if you want to show the example on how to configure an index for a model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I don't think we explicitly show that anywhere else. I can add an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually missed implementing this for configure, thanks again. 👍

Copy link

@rohanshah18 rohanshah18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, lgtm!!

@austin-denoble austin-denoble merged commit b1d3f75 into main Mar 20, 2025
4 checks passed
@austin-denoble austin-denoble deleted the adenoble/implement-integrated-inference branch March 20, 2025 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants