Skip to content

Commit

Permalink
fix: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chuang8511 committed Dec 9, 2024
1 parent e62fb7c commit 764b7bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
10 changes: 5 additions & 5 deletions pkg/component/data/pinecone/v0/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
package pinecone

type taskUpsertInput struct {
id string `instill:"id"`
metadata string `instill:"metadata"`
values []float64 `instill:"values"`
namespace string `instill:"namespace"`
ID string `instill:"id"`
Metadata string `instill:"metadata"`
Values []float64 `instill:"values"`
Namespace string `instill:"namespace"`
}

type taskUpsertOutput struct {
upsertedCount int64 `instill:"upserted-count"`
UpsertedCount int64 `instill:"upserted-count"`
}
33 changes: 21 additions & 12 deletions pkg/component/data/pinecone/v0/task_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package pinecone

import (
"context"
"fmt"

"github.com/instill-ai/pipeline-backend/pkg/component/base"
)

func (e *execution) upsert(ctx context.Context, job *base.Job) error {

input := &taskUpsertInput{}
if err := job.Input.ReadData(ctx, input); err != nil {
input := taskUpsertInput{}
if err := job.Input.ReadData(ctx, &input); err != nil {
err = fmt.Errorf("reading input data: %w", err)
job.Error.Error(ctx, err)
return err
}

Expand All @@ -20,40 +23,46 @@ func (e *execution) upsert(ctx context.Context, job *base.Job) error {
resp := upsertResp{}

req.SetResult(&resp).SetBody(upsertReq)

if _, err := req.Post(upsertPath); err != nil {
err = fmt.Errorf("upserting vectors: %w", err)
job.Error.Error(ctx, err)
return err
}

output := convertOutput(resp)

if err := job.Output.WriteData(ctx, output); err != nil {
err = fmt.Errorf("writing output data: %w", err)
job.Error.Error(ctx, err)
return err
}

return nil
}

func convertInput(input *taskUpsertInput) upsertReq {
func convertInput(input taskUpsertInput) upsertReq {

upsertReq := upsertReq{
Vectors: []vector{},
Namespace: input.namespace,
Namespace: input.Namespace,
}

vector := vector{
ID: input.ID,
Values: input.Values,
}

for _, v := range input.values {
upsertReq.Vectors = append(upsertReq.Vectors, vector{
ID: input.id,
Values: []float64{v},
Metadata: input.metadata,
})
if input.Metadata != "" {
vector.Metadata = input.Metadata
}

upsertReq.Vectors = append(upsertReq.Vectors, vector)

return upsertReq
}

func convertOutput(resp upsertResp) *taskUpsertOutput {
return &taskUpsertOutput{
upsertedCount: resp.RecordsUpserted,
UpsertedCount: resp.RecordsUpserted,
}
}

0 comments on commit 764b7bf

Please sign in to comment.