From d114a4597924cf12559c50f6ef7e3329180442b4 Mon Sep 17 00:00:00 2001 From: aulorbe Date: Fri, 2 Aug 2024 14:14:23 -0700 Subject: [PATCH] Fix indentation, fix idx.Name >> indexName mistake --- README.md | 30 ++------------ pinecone/client.go | 99 ++++++++++++---------------------------------- 2 files changed, 29 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 052a760..1fe53b1 100644 --- a/README.md +++ b/README.md @@ -150,20 +150,8 @@ func main() { indexName := "my-serverless-index" - indexes, err := pc.ListIndexes(ctx) - if err != nil { - log.Fatalf("Failed to list indexes: %v", err) - } - - for _, idx := range indexes { - if idx.Name == indexName { - fmt.Printf("Index \"%s\" already exists\n", indexName) - return - } - } - idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ - Name: &indexName, + Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Cloud: pinecone.Aws, @@ -171,7 +159,7 @@ func main() { }) if err != nil { - log.Fatalf("Failed to create serverless index: %s", idx.Name) + log.Fatalf("Failed to create serverless index: %s", indexName) } else { fmt.Printf("Successfully created serverless index: %s", idx.Name) } @@ -214,20 +202,8 @@ func main() { Indexed: &[]string{"title", "description"}, } - indexes, err := pc.ListIndexes(ctx) - if err != nil { - log.Fatalf("Failed to list indexes: %v", err) - } - - for _, idx := range indexes { - if idx.Name == indexName { - fmt.Printf("Index \"%s\" already exists\n", indexName) - return - } - } - idx, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{ - Name: &indexName, + Name: indexName, Dimension: 3, Metric: pinecone.Cosine, Environment: "us-west1-gcp", diff --git a/pinecone/client.go b/pinecone/client.go index 4a522e3..2e0e03e 100644 --- a/pinecone/client.go +++ b/pinecone/client.go @@ -414,20 +414,8 @@ func (c *Client) ListIndexes(ctx context.Context) ([]*Index, error) { // // indexName := "my-pod-index" // -// indexes, err := pc.ListIndexes(ctx) -// if err != nil { -// log.Fatalf("Failed to list indexes: %v", err) -// } -// -// for _, idx := range indexes { -// if idx.Name == indexName { -// fmt.Printf("Index \"%s\" already exists\n", indexName) -// return -// } -// } -// // idx, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{ -// Name: &indexName, +// Name: indexName, // Dimension: 3, // Metric: pinecone.Cosine, // Environment: "us-west1-gcp", @@ -509,20 +497,8 @@ func (req CreatePodIndexRequest) TotalCount() int { // // indexName := "my-pod-index" // -// indexes, err := pc.ListIndexes(ctx) -// if err != nil { -// log.Fatalf("Failed to list indexes: %v", err) -// } -// -// for _, idx := range indexes { -// if idx.Name == indexName { -// fmt.Printf("Index \"%s\" already exists\n", indexName) -// return -// } -// } -// // idx, err := pc.CreatePodIndex(ctx, &pinecone.CreatePodIndexRequest{ -// Name: &indexName, +// Name: indexName, // Dimension: 3, // Metric: pinecone.Cosine, // Environment: "us-west1-gcp", @@ -600,47 +576,36 @@ func (c *Client) CreatePodIndex(ctx context.Context, in *CreatePodIndexRequest) // // Example: // -// ctx := context.Background() -// -// clientParams := pinecone.NewClientParams{ -// ApiKey: "YOUR_API_KEY", -// SourceTag: "your_source_identifier", // optional -// } +// ctx := context.Background() // -// pc, err := pinecone.NewClient(clientParams) -// if err != nil { -// log.Fatalf("Failed to create Client: %v", err) -// } else { -// fmt.Println("Successfully created a new Client object!") -// } // -// indexName := "my-serverless-index" +// clientParams := pinecone.NewClientParams{ +// ApiKey: "YOUR_API_KEY", +// SourceTag: "your_source_identifier", // optional +// } // -// indexes, err := pc.ListIndexes(ctx) +// pc, err := pinecone.NewClient(clientParams) // if err != nil { -// log.Fatalf("Failed to list indexes: %v", err) +// log.Fatalf("Failed to create Client: %v", err) +// } else { +// fmt.Println("Successfully created a new Client object!") // } // -// for _, idx := range indexes { -// if idx.Name == indexName { -// fmt.Printf("Index \"%s\" already exists\n", indexName) -// return -// } -// } +// indexName := "my-serverless-index" // -// idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ -// Name: &indexName, -// Dimension: 3, -// Metric: pinecone.Cosine, -// Cloud: pinecone.Aws, -// Region: "us-east-1", -// }) +// idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ +// Name: indexName, +// Dimension: 3, +// Metric: pinecone.Cosine, +// Cloud: pinecone.Aws, +// Region: "us-east-1", +// }) // -// if err != nil { -// log.Fatalf("Failed to create serverless index: %s", idx.Name) -// } else { -// fmt.Printf("Successfully created serverless index: %s", idx.Name) -// } +// if err != nil { +// log.Fatalf("Failed to create serverless index: %s", indexName) +// } else { +// fmt.Printf("Successfully created serverless index: %s", idx.Name) +// } // // [dimensionality]: https://docs.pinecone.io/guides/indexes/choose-a-pod-type-and-size#dimensionality-of-vectors // [Serverless]: https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes @@ -684,20 +649,8 @@ type CreateServerlessIndexRequest struct { // // indexName := "my-serverless-index" // -// indexes, err := pc.ListIndexes(ctx) -// if err != nil { -// log.Fatalf("Failed to list indexes: %v", err) -// } -// -// for _, idx := range indexes { -// if idx.Name == indexName { -// fmt.Printf("Index \"%s\" already exists\n", indexName) -// return -// } -// } -// // idx, err := pc.CreateServerlessIndex(ctx, &pinecone.CreateServerlessIndexRequest{ -// Name: &indexName, +// Name: indexName, // Dimension: 3, // Metric: pinecone.Cosine, // Cloud: pinecone.Aws, @@ -705,7 +658,7 @@ type CreateServerlessIndexRequest struct { // }) // // if err != nil { -// log.Fatalf("Failed to create serverless index: %s", idx.Name) +// log.Fatalf("Failed to create serverless index: %s", indexName) // } else { // fmt.Printf("Successfully created serverless index: %s", idx.Name) // }