From b5f54e741ddac5405944f35a87fcc5a16d7818ac Mon Sep 17 00:00:00 2001 From: aulorbe Date: Mon, 24 Jun 2024 16:20:29 -0700 Subject: [PATCH 01/21] Add godoc comments --- pinecone/index_connection.go | 374 +++++++++++++++++++++++++++++++++++ 1 file changed, 374 insertions(+) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index b8cb27f..28d4833 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -13,6 +13,13 @@ import ( "google.golang.org/grpc/metadata" ) +// IndexConnection holds the parameters for Pinecone IndexConnection object. +// +// Fields: +// - Namespace: The namespace of the index. +// - additionalMetadata: Additional metadata to be sent with each request. +// - dataClient: The gRPC client for the index. +// - grpcConn: The gRPC connection. type IndexConnection struct { Namespace string additionalMetadata map[string]string @@ -49,11 +56,88 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { return &idx, nil } +// Close closes the connection to a Pinecone index. +// +// Returns a pointer to an IndexConnection object and an error if the connection cannot be closed. +// +// Parameters: +// idx: The IndexConnection object. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// return +// } +// +// err = idx.Close() +// if err != nil { +// fmt.Println("Error:", err) +// } func (idx *IndexConnection) Close() error { err := idx.grpcConn.Close() return err } +// UpsertVectors indexes vectors into a Pinecone index. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - in: The vectors to index. +// +// Returns the number of vectors upserted and an error if the request fails. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// vectors := []*pinecone.Vector{ +// { +// Id: "abc-1", +// Values: []float32{1.0, 2.0}, +// }, +// } +// +// count, err := idx.UpsertVectors(ctx, vectors) +// if err != nil { +// fmt.Println("Error:", err) +// } else { +// fmt.Printf("Successfully upserted %d vector(s)!\n", count) +// } func (idx *IndexConnection) UpsertVectors(ctx context.Context, in []*Vector) (uint32, error) { vectors := make([]*data.Vector, len(in)) for i, v := range in { @@ -72,11 +156,51 @@ func (idx *IndexConnection) UpsertVectors(ctx context.Context, in []*Vector) (ui return res.UpsertedCount, nil } +// FetchVectorsResponse holds the parameters for the FetchVectorsResponse object, +// which is returned by the FetchVectors method. +// +// Fields: +// - Vectors: The vectors fetched. +// - Usage: The usage information for the request. type FetchVectorsResponse struct { Vectors map[string]*Vector `json:"vectors,omitempty"` Usage *Usage `json:"usage,omitempty"` } +// FetchVectors fetches vectors by ID from a Pinecone index. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - ids: The IDs of the vectors to fetch. +// +// Returns a pointer to any fetched vectors and an error if the request fails. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// res, err := idx.FetchVectors(ctx, []string{"abc-1"}) +// if err != nil { +// fmt.Println("Error:", err) +// } +// fmt.Println(res) func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*FetchVectorsResponse, error) { req := &data.FetchRequest{ Ids: ids, @@ -99,18 +223,75 @@ func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*Fe }, nil } +// ListVectorsRequest holds the parameters for the ListVectorsRequest object, +// which is passed into the ListVectors method. +// +// Fields: +// - Prefix: The prefix by which to filter. +// - Limit: The maximum number of vectors to return. +// - PaginationToken: The token for paginating through results. type ListVectorsRequest struct { Prefix *string Limit *uint32 PaginationToken *string } +// ListVectorsResponse holds the parameters for the ListVectorsResponse object, +// which is returned by the ListVectors method. +// +// Fields: +// - VectorIds: The IDs of the returned vectors. +// - Usage: The usage information for the request. +// - NextPaginationToken: The token for paginating through results. type ListVectorsResponse struct { VectorIds []*string `json:"vector_ids,omitempty"` Usage *Usage `json:"usage,omitempty"` NextPaginationToken *string `json:"next_pagination_token,omitempty"` } +// ListVectors lists vectors in a Pinecone index. You can filter vectors by prefix, +// limit the number of vectors returned, and paginate through results. +// +// Returns a pointer to a ListVectorsResponse object and an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - in: A ListVectorsRequest object with the parameters for the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// prefix := "abc" +// limit := uint32(10) +// +// res, err := idx.ListVectors(ctx, &pinecone.ListVectorsRequest{ +// Prefix: &prefix, +// Limit: &limit, +// }) +// +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// fmt.Println(res) func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequest) (*ListVectorsResponse, error) { req := &data.ListRequest{ Prefix: in.Prefix, @@ -135,6 +316,16 @@ func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequ }, nil } +// QueryByVectorValuesRequest holds the parameters for the QueryByVectorValuesRequest object, +// which is passed into the QueryByVectorValues method. +// +// Fields: +// - Vector: The vector for which you want to grab nearest neighbors. +// - TopK: The number of vectors to return. +// - Filter: The filter to apply to your query. +// - IncludeValues: Whether to include the values of the vectors in the response. +// - IncludeMetadata: Whether to include the metadata associated with the vectors in the response. +// - SparseValues: The sparse values of the query vector, if applicable. type QueryByVectorValuesRequest struct { Vector []float32 TopK uint32 @@ -144,11 +335,62 @@ type QueryByVectorValuesRequest struct { SparseValues *SparseValues } +// QueryVectorsResponse holds the parameters for the QueryVectorsResponse object, +// which is returned by the QueryByVectorValues method. +// +// Fields: +// - Matches: The vectors (nearest neighbors) that are most similar to the query vector. +// - Usage: The usage information for the request. type QueryVectorsResponse struct { Matches []*ScoredVector `json:"matches,omitempty"` Usage *Usage `json:"usage,omitempty"` } +// QueryByVectorValues queries a Pinecone index for vectors ( +// nearest neighbors) that are most similar to a provided query vector. +// +// Returns a pointer to a QueryVectorsResponse object and an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// - allowing for the request to be canceled or to timeout according to the context's deadline. +// in: A QueryByVectorValuesRequest object with the parameters for the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// queryVector := []float32{1.0, 2.0} +// topK := uint32(10) +// +// res, err := idx.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ +// Vector: queryVector, +// TopK: topK, // number of vectors (nearest neighbors) you want returned +// IncludeValues: true, +// IncludeMetadata: true, +// }) +// +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// fmt.Println(res) func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Namespace: idx.Namespace, @@ -163,6 +405,16 @@ func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryBy return idx.query(ctx, req) } +// QueryByVectorIdRequest holds the parameters for the QueryByVectorIdRequest object, +// which is passed into the QueryByVectorId method. +// +// Fields: +// - VectorId: The ID of the vector for which you want to grab nearest neighbors. +// - TopK: The number of vectors to return. +// - Filter: The filter to apply to your query. +// - IncludeValues: Whether to include the values of the vectors in the response. +// - IncludeMetadata: Whether to include the metadata associated with the vectors in the response. +// - SparseValues: The sparse values of the query vector, if applicable. type QueryByVectorIdRequest struct { VectorId string TopK uint32 @@ -172,6 +424,51 @@ type QueryByVectorIdRequest struct { SparseValues *SparseValues } +// QueryByVectorId uses a vector ID to query a Pinecone index and retrieve vectors ( +// nearest neighbors) that are most similar to the provided ID's underlying vector. +// +// Returns a pointer to a QueryVectorsResponse object and an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - in: A QueryByVectorIdRequest object with the parameters for the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// vectorId := "abc-1" +// topK := uint32(10) +// +// res, err := idx.QueryByVectorId(ctx, &pinecone.QueryByVectorIdRequest{ +// VectorId: vectorId, +// TopK: topK, // number of vectors (nearest neighbors) you want returned +// IncludeValues: true, +// IncludeMetadata: true, +// }) index +// +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// fmt.Println(res) func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVectorIdRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Id: in.VectorId, @@ -186,6 +483,39 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect return idx.query(ctx, req) } +// DeleteVectorsById deletes vectors by ID from a Pinecone index. +// +// Returns an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - ids: IDs of the vectors you want to delete. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// err = idx.DeleteVectorsById(ctx, []string{"abc-1"}) +// if err != nil { +// fmt.Println("Error:", err) +// } func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) error { req := data.DeleteRequest{ Ids: ids, @@ -195,6 +525,50 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) return idx.delete(ctx, &req) } +// DeleteVectorsByFilter deletes vectors from a Pinecone index, given a filter. +// +// Returns an error if the request fails. +// +// Note: DeleteVectorsByFilter is only available on pods-based indexes. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - filter: The filter to apply to the deletion. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// metadataFilter := map[string]interface{}{ +// "genre": "classical", +// } +// +// filter, err := structpb.NewStruct(metadataFilter) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// err = idx.DeleteVectorsByFilter(ctx, filter) +// if err != nil { +// fmt.Println("Error:", err) +// } func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *Filter) error { req := data.DeleteRequest{ Filter: filter, From 47a24106364234c4c571dd991eeeb6af42719bcc Mon Sep 17 00:00:00 2001 From: aulorbe Date: Mon, 24 Jun 2024 17:51:11 -0700 Subject: [PATCH 02/21] Save work --- pinecone/index_connection.go | 162 +++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 28d4833..26fcb7b 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -578,6 +578,38 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F return idx.delete(ctx, &req) } +// DeleteAllVectorsInNamespace deletes all vectors in a specific namespace. +// +// Returns an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idxWithNamespace, err := pc.IndexWithNamespace(idxs[0].Host, "test-namespace") +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// err = idxWithNamespace.DeleteAllVectorsInNamespace(ctx) +// if err != nil { +// fmt.Println("Error:", err) +// } func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) error { req := data.DeleteRequest{ Namespace: idx.Namespace, @@ -587,6 +619,14 @@ func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) err return idx.delete(ctx, &req) } +// UpdateVectorRequest holds the parameters for the UpdateVectorRequest object, +// which is passed into the UpdateVector method. +// +// Fields: +// - Id: The ID of the vector to update. +// - Values: The values with which you want to update the vector. +// - SparseValues: The sparse values with which you want to update the vector. +// - Metadata: The metadata with which you want to update the vector. type UpdateVectorRequest struct { Id string Values []float32 @@ -594,6 +634,42 @@ type UpdateVectorRequest struct { Metadata *Metadata } +// UpdateVector updates a vector in a Pinecone index by ID. +// +// Returns an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - in: An UpdateVectorRequest object with the parameters for the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// err = idx.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ +// Id: "abc-1", +// Values: []float32{7.0, 8.0}, +// }) +// if err != nil { +// fmt.Println("Error:", err) +// } func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error { req := &data.UpdateRequest{ Id: in.Id, @@ -607,6 +683,14 @@ func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRe return err } +// DescribeIndexStatsResponse holds the parameters for the DescribeIndexStatsResponse object, +// which is returned by the DescribeIndexStats method. +// +// Fields: +// - Dimension: The dimension of the index. +// - IndexFullness: The fullness level of the index. Note: only available on pods-based indexes. +// - TotalVectorCount: The total number of vectors in the index. +// - Namespaces: The namespace(s) in the index. type DescribeIndexStatsResponse struct { Dimension uint32 `json:"dimension"` IndexFullness float32 `json:"index_fullness"` @@ -614,10 +698,88 @@ type DescribeIndexStatsResponse struct { Namespaces map[string]*NamespaceSummary `json:"namespaces,omitempty"` } +// DescribeIndexStats returns statistics about a Pinecone index. +// +// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// res, err := idx.DescribeIndexStats(ctx) +// if err != nil { +// fmt.Println("Error:", err) +// } +// fmt.Println(res) func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIndexStatsResponse, error) { return idx.DescribeIndexStatsFiltered(ctx, nil) } +// DescribeIndexStatsFiltered returns statistics about a Pinecone index, filtered by a given filter. +// +// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. +// +// Note: DescribeIndexStatsFiltered is only available on pods-based indexes. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - filter: The filter to apply to the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// metadataFilter := map[string]interface{}{ +// "genre": "classical", +// } +// +// filter, err := structpb.NewStruct(metadataFilter) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// res, err := idx.DescribeIndexStatsFiltered(ctx, filter) +// if err != nil { +// fmt.Println("Error:", err) +// } +// fmt.Println(res) func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, filter *Filter) (*DescribeIndexStatsResponse, error) { req := &data.DescribeIndexStatsRequest{ Filter: filter, From da99ab89e8a4306f2f685f8c48f2aff4d8a821ee Mon Sep 17 00:00:00 2001 From: aulorbe Date: Tue, 25 Jun 2024 10:44:55 -0700 Subject: [PATCH 03/21] Remove docstring for method we will probs deprecate --- pinecone/index_connection.go | 45 ------------------------------------ 1 file changed, 45 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 26fcb7b..f0ef92d 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -735,51 +735,6 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn return idx.DescribeIndexStatsFiltered(ctx, nil) } -// DescribeIndexStatsFiltered returns statistics about a Pinecone index, filtered by a given filter. -// -// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. -// -// Note: DescribeIndexStatsFiltered is only available on pods-based indexes. -// -// Parameters: -// - ctx: A context.Context object controls the request's lifetime, -// allowing for the request to be canceled or to timeout according to the context's deadline. -// - filter: The filter to apply to the request. -// -// Example: -// ctx := context.Background() -// -// clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), -// SourceTag: "your_source_identifier", // optional -// } -// -// pc, err := pinecone.NewClient(clientParams) -// if err != nil { -// log.Fatalf("Failed to create Client: %v", err) -// } -// -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) -// if err != nil { -// fmt.Println("Error:", err) -// } -// -// metadataFilter := map[string]interface{}{ -// "genre": "classical", -// } -// -// filter, err := structpb.NewStruct(metadataFilter) -// if err != nil { -// fmt.Println("Error:", err) -// } -// -// res, err := idx.DescribeIndexStatsFiltered(ctx, filter) -// if err != nil { -// fmt.Println("Error:", err) -// } -// fmt.Println(res) func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, filter *Filter) (*DescribeIndexStatsResponse, error) { req := &data.DescribeIndexStatsRequest{ Filter: filter, From 8c9872975c0d11a77ad9e4b55a920f47cd74cb17 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Tue, 25 Jun 2024 15:07:22 -0700 Subject: [PATCH 04/21] Revert "Remove docstring for method we will probs deprecate" This reverts commit da99ab89e8a4306f2f685f8c48f2aff4d8a821ee. --- pinecone/index_connection.go | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index f0ef92d..26fcb7b 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -735,6 +735,51 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn return idx.DescribeIndexStatsFiltered(ctx, nil) } +// DescribeIndexStatsFiltered returns statistics about a Pinecone index, filtered by a given filter. +// +// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. +// +// Note: DescribeIndexStatsFiltered is only available on pods-based indexes. +// +// Parameters: +// - ctx: A context.Context object controls the request's lifetime, +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - filter: The filter to apply to the request. +// +// Example: +// ctx := context.Background() +// +// clientParams := pinecone.NewClientParams{ +// ApiKey: getEnvVars("PINECONE_API_KEY"), +// SourceTag: "your_source_identifier", // optional +// } +// +// pc, err := pinecone.NewClient(clientParams) +// if err != nil { +// log.Fatalf("Failed to create Client: %v", err) +// } +// +// idxs, err := pc.ListIndexes(ctx) +// +// idx, err := pc.Index(idxs[0].Host) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// metadataFilter := map[string]interface{}{ +// "genre": "classical", +// } +// +// filter, err := structpb.NewStruct(metadataFilter) +// if err != nil { +// fmt.Println("Error:", err) +// } +// +// res, err := idx.DescribeIndexStatsFiltered(ctx, filter) +// if err != nil { +// fmt.Println("Error:", err) +// } +// fmt.Println(res) func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, filter *Filter) (*DescribeIndexStatsResponse, error) { req := &data.DescribeIndexStatsRequest{ Filter: filter, From 9218dc6773b4724054df50a5743bf70b1609a708 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Tue, 25 Jun 2024 20:11:38 -0700 Subject: [PATCH 05/21] Address Austin comments, round 1 --- pinecone/index_connection.go | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 26fcb7b..8d006b4 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -13,11 +13,11 @@ import ( "google.golang.org/grpc/metadata" ) -// IndexConnection holds the parameters for Pinecone IndexConnection object. +// IndexConnection holds the parameters for a Pinecone IndexConnection object. // // Fields: -// - Namespace: The namespace of the index. -// - additionalMetadata: Additional metadata to be sent with each request. +// - Namespace: The namespace where index operations will be performed. +// - additionalMetadata: Additional metadata to be sent with each RPC request. // - dataClient: The gRPC client for the index. // - grpcConn: The gRPC connection. type IndexConnection struct { @@ -56,18 +56,15 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { return &idx, nil } -// Close closes the connection to a Pinecone index. +// Close closes the grpc.ClientConn to a Pinecone index. // -// Returns a pointer to an IndexConnection object and an error if the connection cannot be closed. -// -// Parameters: -// idx: The IndexConnection object. +// Returns an error if the connection cannot be closed, otherwise returns nil. // // Example: // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -96,20 +93,20 @@ func (idx *IndexConnection) Close() error { return err } -// UpsertVectors indexes vectors into a Pinecone index. +// UpsertVectors upserts vectors into a Pinecone index. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, // allowing for the request to be canceled or to timeout according to the context's deadline. // - in: The vectors to index. // -// Returns the number of vectors upserted and an error if the request fails. +// Returns the number of vectors upserted or an error if the request fails. // // Example: // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -119,6 +116,9 @@ func (idx *IndexConnection) Close() error { // } // // idxs, err := pc.ListIndexes(ctx) +// if err != nil { +// fmt.Println("Error:", err) +// } // // idx, err := pc.Index(idxs[0].Host) // if err != nil { @@ -180,7 +180,7 @@ type FetchVectorsResponse struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -263,7 +263,7 @@ type ListVectorsResponse struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -320,7 +320,7 @@ func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequ // which is passed into the QueryByVectorValues method. // // Fields: -// - Vector: The vector for which you want to grab nearest neighbors. +// - Vector: The vector to which you want to grab similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. @@ -339,15 +339,14 @@ type QueryByVectorValuesRequest struct { // which is returned by the QueryByVectorValues method. // // Fields: -// - Matches: The vectors (nearest neighbors) that are most similar to the query vector. +// - Matches: The vectors that are most similar to the query vector. // - Usage: The usage information for the request. type QueryVectorsResponse struct { Matches []*ScoredVector `json:"matches,omitempty"` Usage *Usage `json:"usage,omitempty"` } -// QueryByVectorValues queries a Pinecone index for vectors ( -// nearest neighbors) that are most similar to a provided query vector. +// QueryByVectorValues queries a Pinecone index for vectors that are most similar to a provided query vector. // // Returns a pointer to a QueryVectorsResponse object and an error if the request fails. // @@ -360,7 +359,7 @@ type QueryVectorsResponse struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -381,7 +380,7 @@ type QueryVectorsResponse struct { // // res, err := idx.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ // Vector: queryVector, -// TopK: topK, // number of vectors (nearest neighbors) you want returned +// TopK: topK, // number of vectors to be returned // IncludeValues: true, // IncludeMetadata: true, // }) @@ -409,7 +408,7 @@ func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryBy // which is passed into the QueryByVectorId method. // // Fields: -// - VectorId: The ID of the vector for which you want to grab nearest neighbors. +// - VectorId: The ID of the vector to which you want to grab similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. @@ -424,8 +423,8 @@ type QueryByVectorIdRequest struct { SparseValues *SparseValues } -// QueryByVectorId uses a vector ID to query a Pinecone index and retrieve vectors ( -// nearest neighbors) that are most similar to the provided ID's underlying vector. +// QueryByVectorId uses a vector ID to query a Pinecone index and retrieve vectors that are most similar to the +// provided ID's underlying vector. // // Returns a pointer to a QueryVectorsResponse object and an error if the request fails. // @@ -438,7 +437,7 @@ type QueryByVectorIdRequest struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -459,7 +458,7 @@ type QueryByVectorIdRequest struct { // // res, err := idx.QueryByVectorId(ctx, &pinecone.QueryByVectorIdRequest{ // VectorId: vectorId, -// TopK: topK, // number of vectors (nearest neighbors) you want returned +// TopK: topK, // number of vectors you want returned // IncludeValues: true, // IncludeMetadata: true, // }) index @@ -485,7 +484,7 @@ 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. +// Returns an error if the request fails, otherwise returns nil. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -496,7 +495,7 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -527,7 +526,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // DeleteVectorsByFilter deletes vectors from a Pinecone index, given a filter. // -// Returns an error if the request fails. +// Returns an error if the request fails, otherwise returns nil. // // Note: DeleteVectorsByFilter is only available on pods-based indexes. // @@ -540,7 +539,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -580,7 +579,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // DeleteAllVectorsInNamespace deletes all vectors in a specific namespace. // -// Returns an error if the request fails. +// Returns an error if the request fails, otherwise returns nil. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -590,7 +589,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -647,7 +646,7 @@ type UpdateVectorRequest struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -710,7 +709,7 @@ type DescribeIndexStatsResponse struct { // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // @@ -750,7 +749,7 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // ctx := context.Background() // // clientParams := pinecone.NewClientParams{ -// ApiKey: getEnvVars("PINECONE_API_KEY"), +// ApiKey: "YOUR_API_KEY", // SourceTag: "your_source_identifier", // optional // } // From 0d64ed2a20f4b4b572b984556e7f2001669722b3 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Tue, 25 Jun 2024 20:13:08 -0700 Subject: [PATCH 06/21] Change wording of nearest neighbors replacement --- pinecone/index_connection.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 8d006b4..56aba8c 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -320,7 +320,7 @@ func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequ // which is passed into the QueryByVectorValues method. // // Fields: -// - Vector: The vector to which you want to grab similar vectors. +// - Vector: The ID of the vector for which you want to find similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. @@ -408,7 +408,7 @@ func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryBy // which is passed into the QueryByVectorId method. // // Fields: -// - VectorId: The ID of the vector to which you want to grab similar vectors. +// - VectorId: The ID of the vector for which you want to find similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. From fbd7fcb375eef8694c5a2f959d8da910f8c9e8b7 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Tue, 25 Jun 2024 20:18:12 -0700 Subject: [PATCH 07/21] Change ListIndexes to DescribeIndex call --- pinecone/index_connection.go | 58 +++++++++--------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 56aba8c..8f56169 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -73,17 +73,11 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } // -// idx, err := pc.Index(idxs[0].Host) -// if err != nil { -// fmt.Println("Error:", err) -// return -// } -// // err = idx.Close() // if err != nil { // fmt.Println("Error:", err) @@ -115,12 +109,7 @@ func (idx *IndexConnection) Close() error { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// if err != nil { -// fmt.Println("Error:", err) -// } -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -189,9 +178,7 @@ type FetchVectorsResponse struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -272,9 +259,7 @@ type ListVectorsResponse struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -368,9 +353,7 @@ type QueryVectorsResponse struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -446,9 +429,7 @@ type QueryByVectorIdRequest struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -504,9 +485,7 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -548,9 +527,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -577,6 +554,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F return idx.delete(ctx, &req) } +// TODO: make sure this one is correct w/the namespace stuff // DeleteAllVectorsInNamespace deletes all vectors in a specific namespace. // // Returns an error if the request fails, otherwise returns nil. @@ -598,14 +576,12 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idxWithNamespace, err := pc.IndexWithNamespace(idxs[0].Host, "test-namespace") +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } // -// err = idxWithNamespace.DeleteAllVectorsInNamespace(ctx) +// err = idx.DeleteAllVectorsInNamespace(ctx) // if err != nil { // fmt.Println("Error:", err) // } @@ -655,9 +631,7 @@ type UpdateVectorRequest struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -718,9 +692,7 @@ type DescribeIndexStatsResponse struct { // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } @@ -758,9 +730,7 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // log.Fatalf("Failed to create Client: %v", err) // } // -// idxs, err := pc.ListIndexes(ctx) -// -// idx, err := pc.Index(idxs[0].Host) +// idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { // fmt.Println("Error:", err) // } From 701270dcb34dd81151bf19169cce0c29ca740750 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 10:23:35 -0700 Subject: [PATCH 08/21] Got DescribeIndexStatsFiltere to work + clean up examples --- pinecone/index_connection.go | 89 ++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 13 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 8f56169..213195b 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -78,7 +78,12 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { // fmt.Println("Error:", err) // } // -// err = idx.Close() +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// log.Fatalf("Failed to create IndexConnection: %v", err) +// } +// +// err = idxConnection.Close() // if err != nil { // fmt.Println("Error:", err) // } @@ -114,6 +119,11 @@ func (idx *IndexConnection) Close() error { // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // vectors := []*pinecone.Vector{ // { // Id: "abc-1", @@ -121,7 +131,7 @@ func (idx *IndexConnection) Close() error { // }, // } // -// count, err := idx.UpsertVectors(ctx, vectors) +// count, err := idxConnection.UpsertVectors(ctx, vectors) // if err != nil { // fmt.Println("Error:", err) // } else { @@ -183,7 +193,12 @@ type FetchVectorsResponse struct { // fmt.Println("Error:", err) // } // -// res, err := idx.FetchVectors(ctx, []string{"abc-1"}) +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// +// res, err := idxConnection.FetchVectors(ctx, []string{"abc-1"}) // if err != nil { // fmt.Println("Error:", err) // } @@ -264,10 +279,15 @@ type ListVectorsResponse struct { // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // prefix := "abc" // limit := uint32(10) // -// res, err := idx.ListVectors(ctx, &pinecone.ListVectorsRequest{ +// res, err := idxConnection.ListVectors(ctx, &pinecone.ListVectorsRequest{ // Prefix: &prefix, // Limit: &limit, // }) @@ -358,10 +378,15 @@ type QueryVectorsResponse struct { // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // queryVector := []float32{1.0, 2.0} // topK := uint32(10) // -// res, err := idx.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ +// res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ // Vector: queryVector, // TopK: topK, // number of vectors to be returned // IncludeValues: true, @@ -434,10 +459,15 @@ type QueryByVectorIdRequest struct { // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // vectorId := "abc-1" // topK := uint32(10) // -// res, err := idx.QueryByVectorId(ctx, &pinecone.QueryByVectorIdRequest{ +// res, err := idxConnection.QueryByVectorId(ctx, &pinecone.QueryByVectorIdRequest{ // VectorId: vectorId, // TopK: topK, // number of vectors you want returned // IncludeValues: true, @@ -490,7 +520,12 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // fmt.Println("Error:", err) // } // -// err = idx.DeleteVectorsById(ctx, []string{"abc-1"}) +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("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) // } @@ -532,6 +567,11 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // metadataFilter := map[string]interface{}{ // "genre": "classical", // } @@ -541,7 +581,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // fmt.Println("Error:", err) // } // -// err = idx.DeleteVectorsByFilter(ctx, filter) +// err = idxConnection.DeleteVectorsByFilter(ctx, filter) // if err != nil { // fmt.Println("Error:", err) // } @@ -581,7 +621,12 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // fmt.Println("Error:", err) // } // -// err = idx.DeleteAllVectorsInNamespace(ctx) +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// +// err = idxConnection.DeleteAllVectorsInNamespace(ctx) // if err != nil { // fmt.Println("Error:", err) // } @@ -636,7 +681,12 @@ type UpdateVectorRequest struct { // fmt.Println("Error:", err) // } // -// err = idx.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// +// err = idxConnection.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ // Id: "abc-1", // Values: []float32{7.0, 8.0}, // }) @@ -697,7 +747,12 @@ type DescribeIndexStatsResponse struct { // fmt.Println("Error:", err) // } // -// res, err := idx.DescribeIndexStats(ctx) +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// +// res, err := idxConnection.DescribeIndexStats(ctx) // if err != nil { // fmt.Println("Error:", err) // } @@ -735,6 +790,11 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // fmt.Println("Error:", err) // } // +// idxConnection, err := pc.Index(idx.Host) +// if err != nil { +// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// } +// // metadataFilter := map[string]interface{}{ // "genre": "classical", // } @@ -744,11 +804,14 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // fmt.Println("Error:", err) // } // -// res, err := idx.DescribeIndexStatsFiltered(ctx, filter) +// res, err := idxConnection.DescribeIndexStatsFiltered(ctx, filter) // if err != nil { // fmt.Println("Error:", err) // } -// fmt.Println(res) +// +// for name, summary := range res.Namespaces { +// fmt.Printf("Namespace: \"%s\", has %d vector(s) that match the given filter\n", name, summary.VectorCount) +// } func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, filter *Filter) (*DescribeIndexStatsResponse, error) { req := &data.DescribeIndexStatsRequest{ Filter: filter, From a56beb686e7ec4604b528578f0448302f1216bab Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 10:50:16 -0700 Subject: [PATCH 09/21] Clean up FetchVectors example code --- pinecone/index_connection.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 213195b..dab5a64 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -133,7 +133,7 @@ func (idx *IndexConnection) Close() error { // // count, err := idxConnection.UpsertVectors(ctx, vectors) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Failed to upsert vectors:", err) // } else { // fmt.Printf("Successfully upserted %d vector(s)!\n", count) // } @@ -173,7 +173,7 @@ type FetchVectorsResponse struct { // allowing for the request to be canceled or to timeout according to the context's deadline. // - ids: The IDs of the vectors to fetch. // -// Returns a pointer to any fetched vectors and an error if the request fails. +// Returns a pointer to any fetched vectors or an error if the request fails. // // Example: // ctx := context.Background() @@ -202,7 +202,11 @@ type FetchVectorsResponse struct { // if err != nil { // fmt.Println("Error:", err) // } -// fmt.Println(res) +// if len(res.Vectors) != 0 { +// fmt.Println(res) +// } else { +// fmt.Println("No vectors found") +// } func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*FetchVectorsResponse, error) { req := &data.FetchRequest{ Ids: ids, From a4fc1536ca793bfe90a48685f0435e905fc7a154 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 11:03:15 -0700 Subject: [PATCH 10/21] Finalize QueryByVectorValues example code --- pinecone/index_connection.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index dab5a64..9bbe15e 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -398,10 +398,12 @@ type QueryVectorsResponse struct { // }) // // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Error encountered when querying by vector:", err) // } // -// fmt.Println(res) +// for _, match := range res.Matches { +// fmt.Printf("Match vector `%s`, with score %f ", match.Vector.Id, match.Score) +// } func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Namespace: idx.Namespace, From 4a80530225a5e7d575185835dcdf895e2d910924 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 12:11:30 -0700 Subject: [PATCH 11/21] Finish QueryByVectorId --- pinecone/index_connection.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 9bbe15e..3f6d4f0 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -402,7 +402,7 @@ type QueryVectorsResponse struct { // } // // for _, match := range res.Matches { -// fmt.Printf("Match vector `%s`, with score %f ", match.Vector.Id, match.Score) +// fmt.Printf("Match vector `%s`, with score %f\n", match.Vector.Id, match.Score) // } func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ @@ -440,7 +440,11 @@ type QueryByVectorIdRequest struct { // QueryByVectorId uses a vector ID to query a Pinecone index and retrieve vectors that are most similar to the // provided ID's underlying vector. // -// Returns a pointer to a QueryVectorsResponse object and an error if the request fails. +// Returns a pointer to a QueryVectorsResponse object or an error if the request fails. +// +// Note: QueryByVectorId executes a nearest neighbors search, +// meaning that unless TopK=1 in the QueryByVectorIdRequest object, +// it will return 2+ vectors. The vector with a score of 1.0 is the vector with the same ID as the query vector. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -481,10 +485,12 @@ type QueryByVectorIdRequest struct { // }) index // // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Error encountered when querying by vector ID `%s`. Error: %s", id, err) // } // -// fmt.Println(res) +// for _, match := range res.Matches { +// fmt.Printf("Match vector with ID `%s`, with score %f\n", match.Vector.Id, match.Score) +// } func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVectorIdRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Id: in.VectorId, From 4f33fa341ae8c5f40d7b214e179558ae78b6aaf5 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 12:18:38 -0700 Subject: [PATCH 12/21] Finish DeleteVectorsById --- pinecone/index_connection.go | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 3f6d4f0..6a6e74a 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -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" @@ -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 } @@ -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") @@ -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() @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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, @@ -524,7 +527,7 @@ 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") @@ -532,15 +535,15 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // 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, @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") From 2919e027146e8c9d609cd18b2c56bb27a7ace3c6 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 12:28:46 -0700 Subject: [PATCH 13/21] Finish ListVectors --- pinecone/index_connection.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 6a6e74a..d80131a 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -256,7 +256,9 @@ type ListVectorsResponse struct { // ListVectors lists vectors in a Pinecone index. You can filter vectors by prefix, // limit the number of vectors returned, and paginate through results. // -// Returns a pointer to a ListVectorsResponse object and an error if the request fails. +// Note: ListVectors is only available for Serverless indexes. +// +// Returns a pointer to a ListVectorsResponse object or an error if the request fails. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -295,10 +297,14 @@ type ListVectorsResponse struct { // }) // // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to list vectors in index: %s. Error: %s\n", idx.Name, err) // } // -// fmt.Println(res) +// if len(res.VectorIds) == 0 { +// fmt.Println("No vectors found") +// } else { +// fmt.Printf("Found %d vector(s)\n", len(res.VectorIds)) +// } func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequest) (*ListVectorsResponse, error) { req := &data.ListRequest{ Prefix: in.Prefix, @@ -355,7 +361,7 @@ type QueryVectorsResponse struct { // QueryByVectorValues queries a Pinecone index for vectors that are most similar to a provided query vector. // -// Returns a pointer to a QueryVectorsResponse object and an error if the request fails. +// Returns a pointer to a QueryVectorsResponse object or an error if the request fails. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -738,7 +744,7 @@ type DescribeIndexStatsResponse struct { // DescribeIndexStats returns statistics about a Pinecone index. // -// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. +// Returns a pointer to a DescribeIndexStatsResponse object or an error if the request fails. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -778,7 +784,7 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // DescribeIndexStatsFiltered returns statistics about a Pinecone index, filtered by a given filter. // -// Returns a pointer to a DescribeIndexStatsResponse object and an error if the request fails. +// Returns a pointer to a DescribeIndexStatsResponse object or an error if the request fails. // // Note: DescribeIndexStatsFiltered is only available on pods-based indexes. // From 1a69b185ae1c6c3fb5837555668602bf7a9cd6f1 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Wed, 26 Jun 2024 14:11:29 -0700 Subject: [PATCH 14/21] Finalizing comments --- pinecone/index_connection.go | 54 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index d80131a..031d8cd 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -114,7 +114,7 @@ func (idx *IndexConnection) Close() error { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -188,7 +188,7 @@ type FetchVectorsResponse struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -280,7 +280,7 @@ type ListVectorsResponse struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -365,8 +365,8 @@ type QueryVectorsResponse struct { // // Parameters: // - ctx: A context.Context object controls the request's lifetime, -// - allowing for the request to be canceled or to timeout according to the context's deadline. -// in: A QueryByVectorValuesRequest object with the parameters for the request. +// allowing for the request to be canceled or to timeout according to the context's deadline. +// - in: A QueryByVectorValuesRequest object with the parameters for the request. // // Example: // ctx := context.Background() @@ -383,7 +383,7 @@ type QueryVectorsResponse struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -399,7 +399,7 @@ type QueryVectorsResponse struct { // TopK: topK, // number of vectors to be returned // IncludeValues: true, // IncludeMetadata: true, -// }) +// }) // // if err != nil { // fmt.Println("Error encountered when querying by vector:", err) @@ -470,7 +470,7 @@ type QueryByVectorIdRequest struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -543,7 +543,7 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // // idxConnection, err := pc.IndexWithNamespace(idx.Host, "custom-namespace") // if err != nil { -// fmt.Printf("!! 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{id}) @@ -564,6 +564,8 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // Returns an error if the request fails, otherwise returns nil. // // Note: DeleteVectorsByFilter is only available on pods-based indexes. +// Additionally, you must instantiate an IndexWithNamespace connection in order to delete vectors in namespaces +// other than the default. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -585,7 +587,7 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -599,12 +601,12 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // // filter, err := structpb.NewStruct(metadataFilter) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Failed to create metadata filter:", err) // } // // err = idxConnection.DeleteVectorsByFilter(ctx, filter) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to delete vector(s) with filter: %+v. Error: %s\n", filter, err) // } func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *Filter) error { req := data.DeleteRequest{ @@ -615,7 +617,6 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F return idx.delete(ctx, &req) } -// TODO: make sure this one is correct w/the namespace stuff // DeleteAllVectorsInNamespace deletes all vectors in a specific namespace. // // Returns an error if the request fails, otherwise returns nil. @@ -639,7 +640,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -649,7 +650,7 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // // err = idxConnection.DeleteAllVectorsInNamespace(ctx) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to delete vectors in namespace: \"%s\". Error: %s", idxConnection.Namespace, err) // } func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) error { req := data.DeleteRequest{ @@ -677,7 +678,7 @@ type UpdateVectorRequest struct { // UpdateVector updates a vector in a Pinecone index by ID. // -// Returns an error if the request fails. +// Returns an error if the request fails, returns nil otherwise. // // Parameters: // - ctx: A context.Context object controls the request's lifetime, @@ -699,7 +700,7 @@ type UpdateVectorRequest struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -707,12 +708,14 @@ type UpdateVectorRequest struct { // fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // +// id := "abc-1" +// // err = idxConnection.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ -// Id: "abc-1", +// Id: id, // Values: []float32{7.0, 8.0}, // }) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to update vector with ID %s. Error: %s", id, err) // } func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error { req := &data.UpdateRequest{ @@ -774,10 +777,11 @@ type DescribeIndexStatsResponse struct { // } // // res, err := idxConnection.DescribeIndexStats(ctx) -// if err != nil { -// fmt.Println("Error:", err) +// if err != nil { +// fmt.Printf("Failed to describe index \"%s\". Error: %s", idx.Name, err) // } -// fmt.Println(res) +// +// fmt.Printf("%+v", *res) func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIndexStatsResponse, error) { return idx.DescribeIndexStatsFiltered(ctx, nil) } @@ -808,7 +812,7 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -822,12 +826,12 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // // filter, err := structpb.NewStruct(metadataFilter) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to create filter %+v. Error: %s", metadataFilter, err) // } // // res, err := idxConnection.DescribeIndexStatsFiltered(ctx, filter) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error: %s", idx.Name, err) // } // // for name, summary := range res.Namespaces { From 43518509bd34abf39ebf828062f6a0aecd5b59ae Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 10:16:55 -0700 Subject: [PATCH 15/21] Finalize all docstrings --- pinecone/index_connection.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 031d8cd..75a640f 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -95,7 +95,7 @@ func (idx *IndexConnection) Close() error { // Parameters: // - ctx: A context.Context object controls the request's lifetime, // allowing for the request to be canceled or to timeout according to the context's deadline. -// - in: The vectors to index. +// - in: The vectors to upsert. // // Returns the number of vectors upserted or an error if the request fails. // @@ -123,10 +123,9 @@ func (idx *IndexConnection) Close() error { // } // // vectors := []*pinecone.Vector{ -// { -// Id: "abc-1", -// Values: []float32{1.0, 2.0}, -// }, +// {Id: "abc-1", +// Values: []float32{1.0, 2.0}, +// }, // } // // count, err := idxConnection.UpsertVectors(ctx, vectors) @@ -169,7 +168,7 @@ type FetchVectorsResponse struct { // Parameters: // - ctx: A context.Context object controls the request's lifetime, // allowing for the request to be canceled or to timeout according to the context's deadline. -// - ids: The IDs of the vectors to fetch. +// - ids: The unique IDs of the vectors to fetch. // // Returns a pointer to any fetched vectors or an error if the request fails. // @@ -231,8 +230,9 @@ func (idx *IndexConnection) FetchVectors(ctx context.Context, ids []string) (*Fe // which is passed into the ListVectors method. // // Fields: -// - Prefix: The prefix by which to filter. -// - Limit: The maximum number of vectors to return. +// - Prefix: The prefix by which to filter. If unspecified, +// an empty string will be used which will list all vector ids in the namespace +// - Limit: The maximum number of vectors to return. If unspecified, the server will use a default value. // - PaginationToken: The token for paginating through results. type ListVectorsRequest struct { Prefix *string @@ -244,7 +244,7 @@ type ListVectorsRequest struct { // which is returned by the ListVectors method. // // Fields: -// - VectorIds: The IDs of the returned vectors. +// - VectorIds: The unique IDs of the returned vectors. // - Usage: The usage information for the request. // - NextPaginationToken: The token for paginating through results. type ListVectorsResponse struct { @@ -333,7 +333,7 @@ func (idx *IndexConnection) ListVectors(ctx context.Context, in *ListVectorsRequ // which is passed into the QueryByVectorValues method. // // Fields: -// - Vector: The ID of the vector for which you want to find similar vectors. +// - Vector: The query vector used to find similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. @@ -426,7 +426,7 @@ func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryBy // which is passed into the QueryByVectorId method. // // Fields: -// - VectorId: The ID of the vector for which you want to find similar vectors. +// - VectorId: The unique ID of the vector used to find similar vectors. // - TopK: The number of vectors to return. // - Filter: The filter to apply to your query. // - IncludeValues: Whether to include the values of the vectors in the response. @@ -621,6 +621,9 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // // Returns an error if the request fails, otherwise returns nil. // +// 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, // allowing for the request to be canceled or to timeout according to the context's deadline. @@ -665,7 +668,7 @@ func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) err // which is passed into the UpdateVector method. // // Fields: -// - Id: The ID of the vector to update. +// - Id: The unique ID of the vector to update. // - Values: The values with which you want to update the vector. // - SparseValues: The sparse values with which you want to update the vector. // - Metadata: The metadata with which you want to update the vector. From ab0572dc411f67d9464d624c57745783c0d027a0 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 10:29:46 -0700 Subject: [PATCH 16/21] Add metadata and sparse values to UpsertVectors docstring --- pinecone/index_connection.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 75a640f..1b46a4f 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -122,9 +122,25 @@ func (idx *IndexConnection) Close() error { // fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // +// metadataMap := map[string]interface{}{ +// "genre": "classical", +// } +// +// metadata, err := structpb.NewStruct(metadataMap) +// if err != nil { +// fmt.Println("Failed to create metadata map:", err) +// } +// +// sparseValues := pinecone.SparseValues{ +// Indices: []uint32{0, 1}, +// Values: []float32{1.0, 2.0}, +// } +// // vectors := []*pinecone.Vector{ // {Id: "abc-1", // Values: []float32{1.0, 2.0}, +// Metadata: metadata, +// SparseValues: &sparseValues, // }, // } // From f76e544a47636f389fa9225fa61bfbf9bf9647ee Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 10:36:45 -0700 Subject: [PATCH 17/21] Add metadata and sparse values to QueryByVectorValues docstring --- pinecone/index_connection.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 1b46a4f..b8ec57e 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -379,6 +379,9 @@ type QueryVectorsResponse struct { // // Returns a pointer to a QueryVectorsResponse object or an error if the request fails. // +// Note: To issue a hybrid query with both dense and sparse values, +// your index's similarity metric must be dot-product. +// // Parameters: // - ctx: A context.Context object controls the request's lifetime, // allowing for the request to be canceled or to timeout according to the context's deadline. @@ -409,10 +412,24 @@ type QueryVectorsResponse struct { // // queryVector := []float32{1.0, 2.0} // topK := uint32(10) +// metadataMap := map[string]interface{}{ +// "genre": "classical", +// } +// metadataFilter, err := structpb.NewStruct(metadataMap) +// if err != nil { +// fmt.Println("Failed to create metadata map:", err) +// } +// +// sparseValues := pinecone.SparseValues{ +// Indices: []uint32{0, 1}, +// Values: []float32{1.0, 2.0}, +// } // // res, err := idxConnection.QueryByVectorValues(ctx, &pinecone.QueryByVectorValuesRequest{ // Vector: queryVector, // TopK: topK, // number of vectors to be returned +// Filter: metadataFilter, +// SparseValues: &sparseValues, // IncludeValues: true, // IncludeMetadata: true, // }) From 5b22aae8afc5ce0d4bfa565c91efd0396a15c1e8 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 11:59:25 -0700 Subject: [PATCH 18/21] Oops missed some errors --- pinecone/index_connection.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index b8ec57e..5998c0d 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -73,7 +73,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) @@ -83,7 +83,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { // // err = idxConnection.Close() // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Failed to close index connection:", err) // } func (idx *IndexConnection) Close() error { err := idx.grpcConn.Close() @@ -213,7 +213,7 @@ type FetchVectorsResponse struct { // // res, err := idxConnection.FetchVectors(ctx, []string{"abc-1"}) // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Failed to fetch vectors, error:", err) // } // if len(res.Vectors) != 0 { // fmt.Println(res) @@ -804,7 +804,7 @@ type DescribeIndexStatsResponse struct { // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// fmt.Println("Failed to describe index:", err) // } // // idxConnection, err := pc.Index(idx.Host) From 9b7b4d528217e06d92a8e7ea4c8082c2e4ee0ba3 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 12:44:29 -0700 Subject: [PATCH 19/21] Update errors to be log.Fatalf + fix some if/else stmts --- pinecone/index_connection.go | 139 ++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 69 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 5998c0d..ff5c421 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -68,22 +68,22 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Printf("Failed to create IndexConnection: %v", err) +// log.Fatalf("Failed to create IndexConnection: %v", err) // } // // err = idxConnection.Close() // if err != nil { -// fmt.Println("Failed to close index connection:", err) +// log.Fatalf("Failed to close index connection:", err) // } func (idx *IndexConnection) Close() error { err := idx.grpcConn.Close() @@ -109,17 +109,17 @@ func (idx *IndexConnection) Close() error { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // metadataMap := map[string]interface{}{ @@ -128,7 +128,7 @@ func (idx *IndexConnection) Close() error { // // metadata, err := structpb.NewStruct(metadataMap) // if err != nil { -// fmt.Println("Failed to create metadata map:", err) +// log.Fatalf("Failed to create metadata map:", err) // } // // sparseValues := pinecone.SparseValues{ @@ -146,9 +146,9 @@ func (idx *IndexConnection) Close() error { // // count, err := idxConnection.UpsertVectors(ctx, vectors) // if err != nil { -// fmt.Println("Failed to upsert vectors:", err) +// log.Fatalf("Failed to upsert vectors:", err) // } else { -// fmt.Printf("Successfully upserted %d vector(s)!\n", count) +// log.Fatalf("Successfully upserted %d vector(s)!\n", count) // } func (idx *IndexConnection) UpsertVectors(ctx context.Context, in []*Vector) (uint32, error) { vectors := make([]*data.Vector, len(in)) @@ -198,22 +198,22 @@ type FetchVectorsResponse struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // res, err := idxConnection.FetchVectors(ctx, []string{"abc-1"}) // if err != nil { -// fmt.Println("Failed to fetch vectors, error:", err) +// log.Fatalf("Failed to fetch vectors, error:", err) // } // if len(res.Vectors) != 0 { // fmt.Println(res) @@ -291,17 +291,17 @@ type ListVectorsResponse struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // prefix := "abc" @@ -313,7 +313,7 @@ type ListVectorsResponse struct { // }) // // if err != nil { -// fmt.Printf("Failed to list vectors in index: %s. Error: %s\n", idx.Name, err) +// log.Fatalf("Failed to list vectors in index: %s. Error: %s\n", idx.Name, err) // } // // if len(res.VectorIds) == 0 { @@ -397,17 +397,17 @@ type QueryVectorsResponse struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // queryVector := []float32{1.0, 2.0} @@ -417,7 +417,7 @@ type QueryVectorsResponse struct { // } // metadataFilter, err := structpb.NewStruct(metadataMap) // if err != nil { -// fmt.Println("Failed to create metadata map:", err) +// log.Fatalf("Failed to create metadata map:", err) // } // // sparseValues := pinecone.SparseValues{ @@ -435,12 +435,12 @@ type QueryVectorsResponse struct { // }) // // if err != nil { -// fmt.Println("Error encountered when querying by vector:", err) -// } -// -// for _, match := range res.Matches { +// log.Fatalf("Error encountered when querying by vector:", err) +// } else { +// for _, match := range res.Matches { // fmt.Printf("Match vector `%s`, with score %f\n", match.Vector.Id, match.Score) -// } +// } +// } func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Namespace: idx.Namespace, @@ -498,17 +498,17 @@ type QueryByVectorIdRequest struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // vectorId := "abc-1" @@ -522,11 +522,11 @@ type QueryByVectorIdRequest struct { // }) index // // if err != nil { -// fmt.Printf("Error encountered when querying by vector ID `%s`. Error: %s", id, err) -// } -// -// for _, match := range res.Matches { -// fmt.Printf("Match vector with ID `%s`, with score %f\n", match.Vector.Id, match.Score) +// log.Fatalf("Error encountered when querying by vector ID `%s`. Error: %s", id, err) +// } else { +// for _, match := range res.Matches { +// fmt.Printf("Match vector with ID `%s`, with score %f\n", match.Vector.Id, match.Score) +// } // } func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVectorIdRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ @@ -566,22 +566,22 @@ func (idx *IndexConnection) QueryByVectorId(ctx context.Context, in *QueryByVect // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Error:", err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.IndexWithNamespace(idx.Host, "custom-namespace") // if err != nil { -// fmt.Printf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // err = idxConnection.DeleteVectorsById(ctx, []string{id}) // if err != nil { -// fmt.Printf("Failed to delete vector with ID: %s. Error: %s\n", id, err) +// log.Fatalf("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{ @@ -615,17 +615,17 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // metadataFilter := map[string]interface{}{ @@ -634,12 +634,12 @@ func (idx *IndexConnection) DeleteVectorsById(ctx context.Context, ids []string) // // filter, err := structpb.NewStruct(metadataFilter) // if err != nil { -// fmt.Println("Failed to create metadata filter:", err) +// log.Fatalf("Failed to create metadata filter:", err) // } // // err = idxConnection.DeleteVectorsByFilter(ctx, filter) // if err != nil { -// fmt.Printf("Failed to delete vector(s) with filter: %+v. Error: %s\n", filter, err) +// log.Fatalf("Failed to delete vector(s) with filter: %+v. Error: %s\n", filter, err) // } func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *Filter) error { req := data.DeleteRequest{ @@ -671,22 +671,22 @@ func (idx *IndexConnection) DeleteVectorsByFilter(ctx context.Context, filter *F // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // err = idxConnection.DeleteAllVectorsInNamespace(ctx) // if err != nil { -// fmt.Printf("Failed to delete vectors in namespace: \"%s\". Error: %s", idxConnection.Namespace, err) +// log.Fatalf("Failed to delete vectors in namespace: \"%s\". Error: %s", idxConnection.Namespace, err) // } func (idx *IndexConnection) DeleteAllVectorsInNamespace(ctx context.Context) error { req := data.DeleteRequest{ @@ -731,27 +731,28 @@ type UpdateVectorRequest struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // id := "abc-1" // // err = idxConnection.UpdateVector(ctx, &pinecone.UpdateVectorRequest{ -// Id: id, +// Id: id, // Values: []float32{7.0, 8.0}, -// }) +// } +// ) // if err != nil { -// fmt.Printf("Failed to update vector with ID %s. Error: %s", id, err) +// log.Fatalf("Failed to update vector with ID %s. Error: %s", id, err) // } func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error { req := &data.UpdateRequest{ @@ -799,25 +800,25 @@ type DescribeIndexStatsResponse struct { // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Println("Failed to describe index:", err) +// log.Fatalf("Failed to describe index:", err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // res, err := idxConnection.DescribeIndexStats(ctx) // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error: %s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error: %s", idx.Name, err) +// } else { +// log.Fatalf("%+v", *res) // } -// -// fmt.Printf("%+v", *res) func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIndexStatsResponse, error) { return idx.DescribeIndexStatsFiltered(ctx, nil) } @@ -843,17 +844,17 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // // pc, err := pinecone.NewClient(clientParams) // if err != nil { -// fmt.Printf("Failed to create Client: %v", err) +// log.Fatalf("Failed to create Client: %v", err) // } // // idx, err := pc.DescribeIndex(ctx, "your-index-name") // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error:%s", idx.Name, err) +// log.Fatalf("Failed to describe index \"%s\". Error:%s", idx.Name, err) // } // // idxConnection, err := pc.Index(idx.Host) // if err != nil { -// fmt.Println("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) +// log.Fatalf("Failed to create IndexConnection for Host: %v. Error: %v", idx.Host, err) // } // // metadataFilter := map[string]interface{}{ @@ -862,16 +863,16 @@ func (idx *IndexConnection) DescribeIndexStats(ctx context.Context) (*DescribeIn // // filter, err := structpb.NewStruct(metadataFilter) // if err != nil { -// fmt.Printf("Failed to create filter %+v. Error: %s", metadataFilter, err) +// log.Fatalf("Failed to create filter %+v. Error: %s", metadataFilter, err) // } // // res, err := idxConnection.DescribeIndexStatsFiltered(ctx, filter) // if err != nil { -// fmt.Printf("Failed to describe index \"%s\". Error: %s", idx.Name, err) -// } -// -// for name, summary := range res.Namespaces { -// fmt.Printf("Namespace: \"%s\", has %d vector(s) that match the given filter\n", name, summary.VectorCount) +// log.Fatalf("Failed to describe index \"%s\". Error: %s", idx.Name, err) +// } else { +// for name, summary := range res.Namespaces { +// fmt.Printf("Namespace: \"%s\", has %d vector(s) that match the given filter\n", name, summary.VectorCount) +// } // } func (idx *IndexConnection) DescribeIndexStatsFiltered(ctx context.Context, filter *Filter) (*DescribeIndexStatsResponse, error) { req := &data.DescribeIndexStatsRequest{ From a56297b1308c787dee85c214a0777b1cb9c392b1 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 12:47:09 -0700 Subject: [PATCH 20/21] Weird idk why this change was made; revert --- pinecone/index_connection.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index ff5c421..623b870 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/metadata" + "log" ) // IndexConnection holds the parameters for a Pinecone IndexConnection object. @@ -44,7 +45,7 @@ func newIndexConnection(in newIndexParameters) (*IndexConnection, error) { ) if err != nil { - fmt.Printf("fail to dial: %v", err) + log.Fatalf("fail to dial: %v", err) return nil, err } From 22c38dc1dd9921fd4fada0cf630a9099e2f4ad17 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Thu, 27 Jun 2024 12:48:44 -0700 Subject: [PATCH 21/21] Fix indentation --- pinecone/index_connection.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 623b870..26c8eb4 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -433,7 +433,8 @@ type QueryVectorsResponse struct { // SparseValues: &sparseValues, // IncludeValues: true, // IncludeMetadata: true, -// }) +// } +// ) // // if err != nil { // log.Fatalf("Error encountered when querying by vector:", err) @@ -441,7 +442,7 @@ type QueryVectorsResponse struct { // for _, match := range res.Matches { // fmt.Printf("Match vector `%s`, with score %f\n", match.Vector.Id, match.Score) // } -// } +// } func (idx *IndexConnection) QueryByVectorValues(ctx context.Context, in *QueryByVectorValuesRequest) (*QueryVectorsResponse, error) { req := &data.QueryRequest{ Namespace: idx.Namespace,