This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: reset-datastore (hidden) cmd + default dataset 'default'
- Loading branch information
1 parent
2c918ef
commit 98a0187
Showing
7 changed files
with
94 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gptscript-ai/knowledge/pkg/datastore" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type ClientResetDatastore struct { | ||
Client | ||
} | ||
|
||
func (s *ClientResetDatastore) Customize(cmd *cobra.Command) { | ||
cmd.Use = "reset-datastore" | ||
cmd.Short = "Reset the knowledge datastore (WARNING: this deletes all datasets and ingested data)" | ||
cmd.Args = cobra.ExactArgs(0) | ||
cmd.Hidden = true | ||
} | ||
|
||
func (s *ClientResetDatastore) Run(cmd *cobra.Command, args []string) error { | ||
dsn, vectordbPath, err := datastore.GetDatastorePaths(s.DSN, s.VectorDBConfig.VectorDBPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := os.RemoveAll(strings.TrimPrefix(dsn, "sqlite://")); err != nil { | ||
return fmt.Errorf("failed to remove database file: %w", err) | ||
} | ||
|
||
if err := os.RemoveAll(vectordbPath); err != nil { | ||
return fmt.Errorf("failed to remove vector database directory: %w", err) | ||
} | ||
|
||
fmt.Printf("Successfully reset datastore (DSN: %q, VectorDBPath: %q)\n", dsn, vectordbPath) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters