From 7df2c68994341965324912417391b6e88bffe2c6 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 31 Jul 2024 15:26:35 -0700 Subject: [PATCH] Update --- pinecone/client.go | 6 +++--- pinecone/index_connection.go | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pinecone/client.go b/pinecone/client.go index d0ca54b..d53a0c3 100644 --- a/pinecone/client.go +++ b/pinecone/client.go @@ -512,7 +512,7 @@ func (req CreatePodIndexRequest) TotalCount() int { func (c *Client) CreatePodIndex(ctx context.Context, in *CreatePodIndexRequest) (*Index, error) { requiredFields := []string{"Name", "Dimension", "Metric", "Environment", "PodType"} if err := utils.CheckMissingFields(in, requiredFields); err != nil { - log.Fatalln("name, dimension, metric, environment, and podtype must be included in CreatePodIndexRequest") + return nil, fmt.Errorf("name, dimension, metric, environment, and podtype must be included in CreatePodIndexRequest: %w", err) } deletionProtection := pointerOrNil(control.DeletionProtection(in.DeletionProtection)) @@ -659,7 +659,7 @@ type CreateServerlessIndexRequest struct { func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerlessIndexRequest) (*Index, error) { requiredFields := []string{"Name", "Dimension", "Metric", "Cloud", "Region"} if err := utils.CheckMissingFields(in, requiredFields); err != nil { - log.Fatalln("name, dimension, metric, cloud, and region must be included in CreateServerlessIndexRequest") + return nil, fmt.Errorf("name, dimension, metric, cloud, and region must be included in CreateServerlessIndexRequest: %w", err) } deletionProtection := pointerOrNil(control.DeletionProtection(in.DeletionProtection)) @@ -1117,7 +1117,7 @@ type CreateCollectionRequest struct { func (c *Client) CreateCollection(ctx context.Context, in *CreateCollectionRequest) (*Collection, error) { requiredFields := []string{"Name", "Source"} if err := utils.CheckMissingFields(in, requiredFields); err != nil { - log.Fatalln("name and source must be included in CreateCollectionRequest") + return nil, fmt.Errorf("name and source must be included in CreateCollectionRequest: %w", err) } req := control.CreateCollectionRequest{ diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index fca63dc..006d4ea 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -180,9 +180,13 @@ func (idx *IndexConnection) Close() error { // } func (idx *IndexConnection) UpsertVectors(ctx context.Context, in []*Vector) (uint32, error) { requiredFields := []string{"Id", "Values"} - if err := utils.CheckMissingFields(in, requiredFields); err != nil { - log.Fatalln("vectors must have at least ID and Values fields in order to be upserted") + for _, vector := range in { + if err := utils.CheckMissingFields(vector, requiredFields); err != nil { + return 0, fmt.Errorf("vectors must have at least ID and Values fields in order to be upserted: %w", err) + } + // TODO: Is it okay to return 0 here? } + // TODO: might not want to do this for each vector in the slice b/c it's inefficient... vectors := make([]*data.Vector, len(in)) for i, v := range in { @@ -839,7 +843,7 @@ type UpdateVectorRequest struct { func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error { requiredFields := []string{"Id"} if err := utils.CheckMissingFields(in, requiredFields); err != nil { - log.Fatalln("a vector ID plus at least one of Values, SparseValues, or Metadata must be provided to update a vector") + return fmt.Errorf("a vector ID plus at least one of Values, SparseValues, or Metadata must be provided to update a vector") } req := &data.UpdateRequest{