You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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)
- [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
Following example demonstrates creating an integrated index for a
specific model, upserting some records, and then searching against those
records.
```go
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)
}
```
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, use the `Client.CreateIndexForModel` method:
224
+
225
+
```go
226
+
package main
227
+
228
+
import (
229
+
"context"
230
+
"fmt"
231
+
"github.com/pinecone-io/go-pinecone/v3/pinecone"
232
+
"log"
233
+
"os"
234
+
)
235
+
236
+
funcmain() {
237
+
ctx:= context.Background()
238
+
239
+
clientParams:= pinecone.NewClientParams{
240
+
ApiKey: os.Getenv("PINECONE_API_KEY"),
241
+
}
242
+
243
+
pc, err:= pinecone.NewClient(clientParams)
244
+
if err != nil {
245
+
log.Fatalf("Failed to create Client: %v", err)
246
+
} else {
247
+
fmt.Println("Successfully created a new Client object!")
When using an index with integrated inference, embedding and reranking operations are tied to index operations and do not require extra steps. This allows working with an index that accepts source text and converts it to vectors automatically using an embedding model hosted by Pinecone.
1705
+
1706
+
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. See **Create a serverless integrated index** above for specifics on creating these indexes.
1707
+
1708
+
Once you have an index configured for a specific embedding model, use the `IndexConnection.UpsertRecords` method to convert your source data to embeddings and upsert them into a namespace.
1709
+
1710
+
**Upsert integrated records**
1711
+
1712
+
Note the following requirements for each record:
1713
+
1714
+
- Each record must contain a unique `_id`, which will serve as the record identifier in the index namespace.
1715
+
- Each record must contain a field with the data for embedding. This field must match the `FieldMap` specified when creating the index.
1716
+
- Any additional fields in the record will be stored in the index and can be returned in search results or used to filter search results.
"chunk_text": "Apple's first product, the Apple I, was released in 1976 and was hand-built by co-founder Steve Wozniak.",
1743
+
"category": "product",
1744
+
},
1745
+
{
1746
+
"_id": "rec2",
1747
+
"chunk_text": "Apples are a great source of dietary fiber, which supports digestion and helps maintain a healthy gut.",
1748
+
"category": "nutrition",
1749
+
},
1750
+
{
1751
+
"_id": "rec3",
1752
+
"chunk_text": "Apples originated in Central Asia and have been cultivated for thousands of years, with over 7,500 varieties available today.",
1753
+
"category": "cultivation",
1754
+
},
1755
+
{
1756
+
"_id": "rec4",
1757
+
"chunk_text": "In 2001, Apple released the iPod, which transformed the music industry by making portable music widely accessible.",
1758
+
"category": "product",
1759
+
},
1760
+
{
1761
+
"_id": "rec5",
1762
+
"chunk_text": "Apple went public in 1980, making history with one of the largest IPOs at that time.",
1763
+
"category": "milestone",
1764
+
},
1765
+
{
1766
+
"_id": "rec6",
1767
+
"chunk_text": "Rich in vitamin C and other antioxidants, apples contribute to immune health and may reduce the risk of chronic diseases.",
1768
+
"category": "nutrition",
1769
+
},
1770
+
{
1771
+
"_id": "rec7",
1772
+
"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.",
1773
+
"category": "influence",
1774
+
},
1775
+
{
1776
+
"_id": "rec8",
1777
+
"chunk_text": "The high fiber content in apples can also help regulate blood sugar levels, making them a favorable snack for people with diabetes.",
1778
+
"category": "nutrition",
1779
+
},
1780
+
}
1781
+
1782
+
err = idxConnection.UpsertRecords(ctx, records)
1783
+
if err != nil {
1784
+
log.Fatalf("Failed to upsert vectors. Error: %v", err)
1785
+
}
1786
+
```
1787
+
1788
+
**Search integrated records**
1789
+
1790
+
Use the `IndexConnection.SearchRecords` method to convert a query to a vector embedding and then search your namespace for the most semantically similar records, along with their similarity scores.
To rerank initial search results based on relevance to the query, add the rerank parameter, including the [reranking model](https://docs.pinecone.io/guides/inference/understanding-inference#reranking-models) you want to use, the number of reranked results to return, and the fields to use for reranking, if different than the main query.
1808
+
1809
+
For example, repeat the search for the 4 documents most semantically related to the query, “Disease prevention”, but this time rerank the results and return only the 2 most relevant documents:
0 commit comments