Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions internal/pkg/cli/command/backup/backup_test.go

This file was deleted.

43 changes: 43 additions & 0 deletions internal/pkg/cli/command/index/backup/backup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package backup

import (
"context"

"github.com/pinecone-io/go-pinecone/v5/pinecone"
)

type mockBackupService struct {
lastCreateBackupReq *pinecone.CreateBackupParams
lastDescribeBackupId string
lastListBackupsParams *pinecone.ListBackupsParams
lastDeleteBackupId string

createBackupResp *pinecone.Backup
describeBackupResp *pinecone.Backup
listBackupsResp *pinecone.BackupList

createBackupErr error
describeBackupErr error
listBackupsErr error
deleteBackupErr error
}

func (m *mockBackupService) CreateBackup(ctx context.Context, in *pinecone.CreateBackupParams) (*pinecone.Backup, error) {
m.lastCreateBackupReq = in
return m.createBackupResp, m.createBackupErr
}

func (m *mockBackupService) DescribeBackup(ctx context.Context, backupId string) (*pinecone.Backup, error) {
m.lastDescribeBackupId = backupId
return m.describeBackupResp, m.describeBackupErr
}

func (m *mockBackupService) ListBackups(ctx context.Context, in *pinecone.ListBackupsParams) (*pinecone.BackupList, error) {
m.lastListBackupsParams = in
return m.listBackupsResp, m.listBackupsErr
}

func (m *mockBackupService) DeleteBackup(ctx context.Context, backupId string) error {
m.lastDeleteBackupId = backupId
return m.deleteBackupErr
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package backup

import (
"github.com/pinecone-io/cli/internal/pkg/cli/command/backup/restore"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/spf13/cobra"
)


var (
backupHelp = help.Long(`
Manage backups for serverless indexes. A backup is a static copy of a serverless index
that only consumes storage. It is a non-queryable representation of a set of records.
You can create a backup of a serverless index, and you can create a new index from a backup.

Use these commands to create, describe, list, and delete backups, or to
restore an index from a backup, or inspect restore jobs.
Use these commands to create, describe, list, and delete backups.

See: https://docs.pinecone.io/guides/manage-data/backups-overview
`)
)

func NewBackupCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "backup",
Short: "Manage serverless index backups",
Long: backupHelp,
Use: "backup",
Short: "Manage serverless index backups",
Long: backupHelp,
GroupID: help.GROUP_INDEX_MANAGEMENT.ID,
Example: help.Examples(`
# Create a backup for a serverless index
pc backup create --index-name my-index --name daily-backup
pc index backup create --index-name my-index --name daily-backup

# List backups for a serverless index
pc backup list --index-name my-index
pc index backup list --index-name my-index

# Restore an index from a backup
pc backup restore --id backup-123 --name restored-index
# List all backups in the project
pc index backup list

# List restore jobs
pc backup restore list
# Describe a backup
pc index backup describe --id backup-123

# Describe a restore job
pc backup restore describe --id rj-123
# Delete a backup
pc index backup delete --id backup-123
`),
}

Expand All @@ -47,7 +47,5 @@ func NewBackupCmd() *cobra.Command {
cmd.AddCommand(NewListBackupsCmd())
cmd.AddCommand(NewDeleteBackupCmd())

cmd.AddCommand(restore.NewRestoreJobCmd())

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"github.com/spf13/cobra"
)

// BackupService defines the SDK operations used by backup commands.
type BackupService interface {
CreateBackup(ctx context.Context, in *pinecone.CreateBackupParams) (*pinecone.Backup, error)
DescribeBackup(ctx context.Context, backupId string) (*pinecone.Backup, error)
ListBackups(ctx context.Context, in *pinecone.ListBackupsParams) (*pinecone.BackupList, error)
DeleteBackup(ctx context.Context, backupId string) error
CreateIndexFromBackup(ctx context.Context, in *pinecone.CreateIndexFromBackupParams) (*pinecone.CreateIndexFromBackupResponse, error)
}

type createBackupCmdOptions struct {
Expand All @@ -44,8 +44,8 @@ func NewCreateBackupCmd() *cobra.Command {
the backup later.
`),
Example: help.Examples(`
pc backup create --index-name my-index
pc backup create --index-name my-index --name nightly --description "Nightly backup"
pc index backup create --index-name my-index
pc index backup create --index-name my-index --name nightly --description "Nightly backup"
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewDeleteBackupCmd() *cobra.Command {
Use: "delete",
Short: "Delete a backup by ID",
Example: help.Examples(`
pc backup delete --id backup-123
pc index backup delete --id backup-123
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ func NewDescribeBackupCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "describe",
Short: "Describe a backup by ID",
Long: help.Long(`
Describe a backup by its ID, showing status, source index, and storage details.
`),
Example: help.Examples(`
pc backup describe --id backup-123
pc index backup describe --id backup-123
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backup

import (
"context"

"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
Expand Down Expand Up @@ -33,10 +32,10 @@ func NewListBackupsCmd() *cobra.Command {
`),
Example: help.Examples(`
# List backups for the current project
pc backup list
pc index backup list

# List backups for a specific index
pc backup list --index-name my-index --limit 10
pc index backup list --index-name my-index --limit 10
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand Down
8 changes: 8 additions & 0 deletions internal/pkg/cli/command/index/cmd.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package index

import (
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/backup"
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/collection"
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/namespace"
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/record"
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/restore"
"github.com/pinecone-io/cli/internal/pkg/cli/command/index/vector"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,5 +52,10 @@ func NewIndexCmd() *cobra.Command {
cmd.AddGroup(help.GROUP_INDEX_NAMESPACE)
cmd.AddCommand(namespace.NewNamespaceCmd())

cmd.AddGroup(help.GROUP_INDEX_MANAGEMENT)
cmd.AddCommand(backup.NewBackupCmd())
cmd.AddCommand(restore.NewRestoreCmd())
cmd.AddCommand(collection.NewCollectionCmd())

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ func NewCollectionCmd() *cobra.Command {
Use: "collection",
Short: "Work with collections (pod-based indexes only)",
Long: collectionHelp,
GroupID: help.GROUP_VECTORDB.ID,
GroupID: help.GROUP_INDEX_MANAGEMENT.ID,
Example: help.Examples(`
pc index collection list
pc index collection create --name my-collection --source my-index
pc index collection describe --name my-collection
pc index collection delete --name my-collection
`),
}

cmd.AddCommand(NewCreateCollectionCmd())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewCreateCollectionCmd() *cobra.Command {
Use: "create",
Short: "Create a collection from a pod-based index",
Example: help.Examples(`
pc collection create --name "collection-name" --source "index-source-name"
pc index collection create --name my-collection --source my-index
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand All @@ -49,20 +49,17 @@ func NewCreateCollectionCmd() *cobra.Command {
json := text.IndentJSON(collection)
fmt.Fprintln(os.Stdout, json)
} else {
describeCommand := fmt.Sprintf("pc collection describe --name %s", collection.Name)
describeCommand := fmt.Sprintf("pc index collection describe --name %s", collection.Name)
msg.SuccessMsg("Collection %s created successfully. Run %s to check status. \n\n", style.Emphasis(collection.Name), style.Code(describeCommand))
presenters.PrintDescribeCollectionTable(collection)
}
},
}

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name you want to give the collection")
_ = cmd.MarkFlagRequired("name")
cmd.Flags().StringVarP(&options.sourceIndex, "source", "s", "", "name of the index to use as the source for the collection")
_ = cmd.MarkFlagRequired("source")

// Optional flags
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewDeleteCollectionCmd() *cobra.Command {
Use: "delete",
Short: "Delete a collection",
Example: help.Examples(`
pc collection delete --name "collection-name"
pc index collection delete --name my-collection
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand All @@ -43,10 +43,8 @@ func NewDeleteCollectionCmd() *cobra.Command {
},
}

// required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of collection to delete")
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "Output result as JSON")

_ = cmd.MarkFlagRequired("name")

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewDescribeCollectionCmd() *cobra.Command {
Use: "describe",
Short: "Describe a collection by name",
Example: help.Examples(`
pc collection describe --name "collection-name"
pc index collection describe --name my-collection
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand All @@ -46,11 +46,8 @@ func NewDescribeCollectionCmd() *cobra.Command {
},
}

// required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of collection to describe")
_ = cmd.MarkFlagRequired("name")

// optional flags
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewListCollectionsCmd() *cobra.Command {
Use: "list",
Short: "See the list of collections in your project",
Example: help.Examples(`
pc collection list
pc index collection list
`),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Expand All @@ -41,7 +41,6 @@ func NewListCollectionsCmd() *cobra.Command {
exit.Error(err, "Failed to list collections")
}

// Sort results alphabetically by name
sort.SliceStable(collections, func(i, j int) bool {
return collections[i].Name < collections[j].Name
})
Expand All @@ -55,7 +54,6 @@ func NewListCollectionsCmd() *cobra.Command {
},
}

// Optional flags
cmd.Flags().BoolVarP(&options.json, "json", "j", false, "output as JSON")

return cmd
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/cli/command/index/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewConfigureIndexCmd() *cobra.Command {

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Name of index to configure")
_ = cmd.MarkFlagRequired("name")

// pods
cmd.Flags().StringVarP(&options.podType, "pod-type", "t", "", "Type of pod to use, can only upgrade when configuring")
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/cli/command/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn
return nil, err
}

// Only forward metric if explicitly set — the model has its own default and
// the flag default ("cosine") must not silently override it.
var embedMetric *pinecone.IndexMetric
if cmd.Flags().Changed("metric") {
m := pinecone.IndexMetric(options.metric)
embedMetric = &m
}

args := pinecone.CreateIndexForModelRequest{
Name: options.name,
Cloud: pinecone.Cloud(options.cloud),
Expand All @@ -270,6 +278,8 @@ func runCreateIndexCmd(ctx context.Context, cmd *cobra.Command, service CreateIn
Embed: pinecone.CreateIndexForModelEmbed{
Model: options.model,
FieldMap: toInterfaceMap(options.fieldMap),
Metric: embedMetric,
Dimension: pointerOrNil(int(options.dimension)),
ReadParameters: &readParams,
WriteParameters: &writeParams,
},
Expand Down
Loading
Loading