Skip to content

Commit

Permalink
Finish DeleteVectorsById
Browse files Browse the repository at this point in the history
  • Loading branch information
aulorbe committed Jun 26, 2024
1 parent 4a80530 commit 4f33fa3
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions pinecone/index_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"crypto/tls"
"fmt"
"log"

"github.com/pinecone-io/go-pinecone/internal/gen/data"
"github.com/pinecone-io/go-pinecone/internal/useragent"
"google.golang.org/grpc"
Expand Down Expand Up @@ -46,7 +44,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) {
)

if err != nil {
log.Fatalf("fail to dial: %v", err)
fmt.Printf("fail to dial: %v", err)
return nil, err
}

Expand All @@ -70,7 +68,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand All @@ -80,7 +78,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) {
//
// idxConnection, err := pc.Index(idx.Host)
// if err != nil {
// log.Fatalf("Failed to create IndexConnection: %v", err)
// fmt.Printf("Failed to create IndexConnection: %v", err)
// }
//
// err = idxConnection.Close()
Expand Down Expand Up @@ -111,7 +109,7 @@ func (idx *IndexConnection) Close() error {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -185,7 +183,7 @@ type FetchVectorsResponse struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -275,7 +273,7 @@ type ListVectorsResponse struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -374,7 +372,7 @@ type QueryVectorsResponse struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -461,7 +459,7 @@ type QueryByVectorIdRequest struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -507,7 +505,12 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect

// DeleteVectorsById deletes vectors by ID from a Pinecone index.
//
// Returns an error if the request fails, otherwise returns nil.
// Returns an error if the request fails,
// otherwise returns nil. This method will also return nil if the passed vector ID does not exist in the index or
// namespace.
//
// Note: You must instantiate an IndexWithNamespace connection in order to delete vectors by ID in namespaces other
// than the default.
//
// Parameters:
// - ctx: A context.Context object controls the request's lifetime,
Expand All @@ -524,23 +527,23 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
// if err != nil {
// fmt.Println("Error:", err)
// }
//
// idxConnection, err := pc.Index(idx.Host)
// idxConnection, err := pc.IndexWithNamespace(idx.Host, "custom-namespace")
// if err != nil {
// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err)
// fmt.Printf("!! Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err)
// }
//
// err = idxConnection.DeleteVectorsById(ctx, []string{"abc-1"})
// if err != nil {
// fmt.Println("Error:", err)
// }
// err = idxConnection.DeleteVectorsById(ctx, []string{id})
// if err != nil {
// fmt.Printf("Failed to delete vector with ID: %s. Error: %s\n", id, err)
// }
func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) error {
req := data.DeleteRequest{
Ids: ids,
Expand Down Expand Up @@ -571,7 +574,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string)
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -625,7 +628,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -685,7 +688,7 @@ type UpdateVectorRequest struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -751,7 +754,7 @@ type DescribeIndexStatsResponse struct {
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down Expand Up @@ -794,7 +797,7 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// fmt.Printf("Failed to create Client: %v", err)
// }
//
// idx, err := pc.DescribeIndex(ctx, "your-index-name")
Expand Down

0 comments on commit 4f33fa3

Please sign in to comment.