Skip to content

Commit

Permalink
Fix indentation, fix idx.Name >> indexName mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
aulorbe committed Aug 2, 2024
1 parent 2cc389f commit d114a45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 100 deletions.
30 changes: 3 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,16 @@ 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,
Region: "us-east-1",
})

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)
}
Expand Down Expand Up @@ -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",
Expand Down
99 changes: 26 additions & 73 deletions pinecone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -684,28 +649,16 @@ 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,
// Region: "us-east-1",
// })
//
// 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)
// }
Expand Down

0 comments on commit d114a45

Please sign in to comment.