diff --git a/codegen/apis b/codegen/apis index 3002f1e..9d3a41f 160000 --- a/codegen/apis +++ b/codegen/apis @@ -1 +1 @@ -Subproject commit 3002f1e62b895d2e64fba53e346ad84eb4719934 +Subproject commit 9d3a41f6ae657d9b0b818065dcdc3adf76bdb7fe diff --git a/pinecone/client.go b/pinecone/client.go index ff3845c..4b32cf3 100644 --- a/pinecone/client.go +++ b/pinecone/client.go @@ -1343,15 +1343,7 @@ func (i *InferenceService) Embed(ctx context.Context, in *EmbedRequest) (*infere return decodeEmbeddingsList(res.Body) } -// Document represents a single document to be reranked. -// -// Fields: -// - ID: (Required) The unique identifier of the document. -// - Text: (Required) The text content of the document. -type Document struct { - Id string - Text string -} +type Document map[string]string // RerankRequest holds the parameters for reranking a list of documents based on a query. // @@ -1362,23 +1354,25 @@ type Document struct { // - TopN: (Required) The number of top documents to return after reranking. // - Documents: (Required) A list of Document objects to be reranked. type RerankRequest struct { + Documents []Document Model string Query string - ReturnDocuments bool - TopN int - Documents []Document + Parameters *map[string]string + RankFields *[]string + ReturnDocuments *bool + TopN *int } -type RankResult struct { +type RerankResult struct { Document *Document `json:"document,omitempty"` Index IntegrationTests `json:"index"` Score float32 `json:"score"` } type RerankResponse struct { - Data []RankResult `json:"data,omitempty"` - Model string `json:"model,omitempty"` - Usage RerankUsage `json:"usage"` + Data []RerankResult `json:"data,omitempty"` + Model string `json:"model,omitempty"` + Usage RerankUsage `json:"usage"` } // Rerank processes the reranking of documents based on the provided query and model. @@ -1422,20 +1416,15 @@ type RerankResponse struct { // fmt.Printf("Successfully reranked documents: %+v", res) // } func (i *InferenceService) Rerank(ctx context.Context, in *RerankRequest) (*RerankResponse, error) { - - if len(in.Documents) <= 2 { - return nil, fmt.Errorf("documents must contain at least more than two value") - } - // Convert documents to the expected type convertedDocuments := make([]inference.Document, len(in.Documents)) for i, doc := range in.Documents { - convertedDocuments[i] = inference.Document{"Id": doc.Id, "Text": doc.Text} + convertedDocuments[i] = inference.Document(doc) } req := inference.RerankJSONRequestBody{ Model: in.Model, Query: in.Query, - ReturnDocuments: &in.ReturnDocuments, - TopN: &in.TopN, + ReturnDocuments: in.ReturnDocuments, + TopN: in.TopN, Documents: convertedDocuments, } res, err := i.client.Rerank(ctx, req) diff --git a/pinecone/client_test.go b/pinecone/client_test.go index f931b5a..b0a9604 100644 --- a/pinecone/client_test.go +++ b/pinecone/client_test.go @@ -316,21 +316,23 @@ func (ts *IntegrationTests) TestGenerateEmbeddingsInvalidInputs() { func (ts *IntegrationTests) TestRerankDocument() { ctx := context.Background() rerankModel := "bge-reranker-v2-m3" + topN := 4 ranking, err := ts.client.Inference.Rerank(ctx, &RerankRequest{ Model: rerankModel, - Query: "The tech company Apple is known for its innovative products like the iPhone.", - ReturnDocuments: true, - TopN: 4, + Query: "i love cats", + ReturnDocuments: nil, + TopN: &topN, + RankFields: &[]string{"text"}, Documents: []Document{ - {Id: "vec1", Text: "Apple is a popular fruit known for its sweetness and crisp texture."}, - {Id: "vec2", Text: "Many people enjoy eating apples as a healthy snack."}, - {Id: "vec3", Text: "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."}, - {Id: "vec4", Text: "An apple a day keeps the doctor away, as the saying goes."}, + {"id": "vec1", "text": "Apple is a popular fruit known for its sweetness and crisp texture."}, + {"id": "vec2", "text": "Many people enjoy eating apples as a healthy snack."}, + {"id": "vec3", "text": "Apple Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces."}, + {"id": "vec4", "text": "An apple a day keeps the doctor away, as the saying goes."}, }}) require.NoError(ts.T(), err) require.NotNil(ts.T(), ranking, "Expected reranking result to be non-nil") - require.Equal(ts.T(), 4, len(*ranking.Data), "Expected 4 rankings") + require.Equal(ts.T(), 4, len(ranking.Data), "Expected 4 rankings") } // Unit tests: