Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go CLI: set/show cpu/memory/concurrency (#20002)

Jin Hai16de4bfcb645
diff --git a/internal/cli/cli_http.go b/internal/cli/cli_http.go
index 49c5b116ae..4d3c1a0e4a 100644
--- a/internal/cli/cli_http.go
+++ b/internal/cli/cli_http.go
@@ -329,6 +329,12 @@ func (c *CLI) ExecuteUserCommand(commandCount int, cmd *Command) (ResponseIf, er
return c.PingServerByCommand(commandCount, cmd)
case "api_set_log_level":
return c.APISetLogLevelCommand(commandCount, cmd)
+ case "api_set_cores":
+ return c.APISetCoresCommand(commandCount, cmd)
+ case "api_set_memory":
+ return c.APISetMemoryCommand(commandCount, cmd)
+ case "api_set_concurrency":
+ return c.APISetConcurrencyCommand(commandCount, cmd)
case "benchmark":
return c.RunBenchmark(commandCount, cmd)
case "api_list_datasets":
@@ -500,6 +506,12 @@ func (c *CLI) ExecuteUserCommand(commandCount int, cmd *Command) (ResponseIf, er
return c.APIShowLogLevelCommand(commandCount, cmd)
case "api_show_hardware":
return c.CommonShowHardwareCommand(commandCount, cmd)
+ case "api_show_cores":
+ return c.APIShowCoresCommand(commandCount, cmd)
+ case "api_show_memory":
+ return c.APIShowMemoryCommand(commandCount, cmd)
+ case "api_show_concurrency":
+ return c.APIShowConcurrencyCommand(commandCount, cmd)
case "api_list_api_servers":
return c.CommonListAPIServersCommand(commandCount, cmd)
case "api_list_environments":
diff --git a/internal/cli/lexer.go b/internal/cli/lexer.go
index ea8eaa3061..423d244dcb 100644
--- a/internal/cli/lexer.go
+++ b/internal/cli/lexer.go
@@ -369,6 +369,10 @@ func (l *Lexer) lookupIdent(ident string) Token {
return Token{Type: TokenSearch, Value: ident}
case "AGENT":
return Token{Type: TokenAgent, Value: ident}
+ case "CORES":
+ return Token{Type: TokenCores, Value: ident}
+ case "CONCURRENCY":
+ return Token{Type: TokenConcurrency, Value: ident}
case "MEMORY":
return Token{Type: TokenMemory, Value: ident}
case "MEMORIES":
diff --git a/internal/cli/types.go b/internal/cli/types.go
index e89ad2a8b7..93e450aed0 100644
--- a/internal/cli/types.go
+++ b/internal/cli/types.go
@@ -106,6 +106,8 @@ const (
TokenAgent
TokenMemories
TokenMemory
+ TokenCores
+ TokenConcurrency
TokenRetrieve
TokenCurrent
TokenSoft
diff --git a/internal/cli/user_command.go b/internal/cli/user_command.go
index 5d330f8d4a..9f00110bca 100644
--- a/internal/cli/user_command.go
+++ b/internal/cli/user_command.go
@@ -4130,3 +4130,170 @@ func (c *CLI) streamChatCompletions(url string, body map[string]interface{}) (Re
streamed: true,
}, nil
}
+
+func (c *CLI) APISetCoresCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
+ return nil, fmt.Errorf("API key not set. Please login first")
+ }
+
+ cores, ok := cmd.Params["cores"].(int)
+ if !ok {
+ return nil, fmt.Errorf("cores not provided")
+ }
+
+ payload := map[string]interface{}{
+ "cores": cores,
+ }
+ resp, err := httpClient.Request(commandCount, "PUT", "/system/cores", "web", nil, payload)
+ if err != nil {
+ return nil, fmt.Errorf("failed to set CPU cores: %w", err)
+ }
+
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("failed to set CPU cores: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ }
+
+ var result MessageResponse
+ if err = json.Unmarshal(resp.Body, &result); err != nil {
+ return nil, fmt.Errorf("set CPU cores failed: invalid JSON (%w)", err)
+ }
+
+ if result.Code != 0 {
+ return nil, fmt.Errorf("%s", result.Message)
+ }
+
+ result.Duration = resp.Duration
+ return &result, nil
+}
+
+func (c *CLI) APISetMemoryCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
+ return nil, fmt.Errorf("API key not set. Please login first")
+ }
+
+ memorySize, ok := cmd.Params["memory_size"].(int)
+ if !ok {
+ return nil, fmt.Errorf("memory_size not provided")
+ }
+
+ payload := map[string]interface{}{
+ "memory_size": memorySize,
+ }
+ resp, err := httpClient.Request(commandCount, "PUT", "/system/memory", "web", nil, payload)
+ if err != nil {
+ return nil, fmt.Errorf("failed to set memory: %w", err)
+ }
+
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("failed to set memory: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ }
+
+ var result MessageResponse
+ if err = json.Unmarshal(resp.Body, &result); err != nil {
+ return nil, fmt.Errorf("set memory failed: invalid JSON (%w)", err)
+ }
+
+ if result.Code != 0 {
+ return nil, fmt.Errorf("%s", result.Message)
+ }
+
+ result.Duration = resp.Duration
+ return &result, nil
+}
+
+func (c *CLI) APISetConcurrencyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
+ return nil, fmt.Errorf("API key not set. Please login first")
+ }
+
+ concurrency, ok := cmd.Params["concurrency"].(int)
+ if !ok {
+ return nil, fmt.Errorf("concurrency not provided")
+ }
+
+ payload := map[string]interface{}{
+ "concurrency": concurrency,
+ }
+ resp, err := httpClient.Request(commandCount, "PUT", "/system/concurrency", "web", nil, payload)
+ if err != nil {
+ return nil, fmt.Errorf("failed to set concurrency: %w", err)
+ }
+
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("failed to set concurrency: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ }
+
+ var result MessageResponse
+ if err = json.Unmarshal(resp.Body, &result); err != nil {
+ return nil, fmt.Errorf("set concurrency failed: invalid JSON (%w)", err)
+ }
+
+ if result.Code != 0 {
+ return nil, fmt.Errorf("%s", result.Message)
+ }
+
+ result.Duration = resp.Duration
+ return &result, nil
+}
+
+func (c *CLI) APIShowCoresCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "GET", "/system/cores", "web", nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get CPU cores: %w", err)
+ }
+
+ return HandleCommonDataResponse(resp, "get CPU cores")
+}
+
+func (c *CLI) APIShowMemoryCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "GET", "/system/memory", "web", nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get memory: %w", err)
+ }
+
+ return HandleCommonDataResponse(resp, "get memory")
+}
+
+func (c *CLI) APIShowConcurrencyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ if c.Config.CLIMode != APIMode {
+ return nil, fmt.Errorf("this command is only allowed in USER mode")
+ }
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "GET", "/system/concurrency", "web", nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get concurrency: %w", err)
+ }
+
+ return HandleCommonDataResponse(resp, "get concurrency")
+}
diff --git a/internal/cli/user_parser.go b/internal/cli/user_parser.go
index f8df9dc3d5..892ac148bd 100644
--- a/internal/cli/user_parser.go
+++ b/internal/cli/user_parser.go
@@ -633,6 +633,12 @@ func (p *Parser) parseAPIShowCommands() (*Command, error) {
return p.parseAPIShowLogCommands()
case TokenHardware:
return p.parseAPIShowHardware()
+ case TokenCores:
+ return p.parseAPIShowCores()
+ case TokenMemory:
+ return p.parseAPIShowMemory()
+ case TokenConcurrency:
+ return p.parseAPIShowConcurrency()
default:
return nil, fmt.Errorf("unknown SHOW target: %s", p.curToken.Value)
}
@@ -907,6 +913,45 @@ func (p *Parser) parseAPIShowHardware() (*Command, error) {
return cmd, nil
}
+// SHOW CORES
+func (p *Parser) parseAPIShowCores() (*Command, error) {
+ p.nextToken() // consume CORES
+ cmd := NewCommand("api_show_cores")
+
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
+// SHOW MEMORY
+func (p *Parser) parseAPIShowMemory() (*Command, error) {
+ p.nextToken() // consume MEMORY
+ cmd := NewCommand("api_show_memory")
+
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
+// SHOW CONCURRENCY
+func (p *Parser) parseAPIShowConcurrency() (*Command, error) {
+ p.nextToken() // consume CONCURRENCY
+ cmd := NewCommand("api_show_concurrency")
+
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
// endregion SHOW commands
// region CREATE commands
@@ -1931,6 +1976,12 @@ func (p *Parser) parseAPISetCommands() (*Command, error) {
return p.parseAPISetLog()
case TokenMetadata:
return p.parseDevSetMeta()
+ case TokenCores:
+ return p.parseAPISetCores()
+ case TokenMemory:
+ return p.parseAPISetMemory()
+ case TokenConcurrency:
+ return p.parseAPISetConcurrency()
default:
return nil, fmt.Errorf("unknown SET target: %s", p.curToken.Value)
}
@@ -2081,6 +2132,70 @@ func (p *Parser) parseAPISetLogLevel() (*Command, error) {
return cmd, nil
}
+// SET CORES 4;
+func (p *Parser) parseAPISetCores() (*Command, error) {
+ p.nextToken() // consume CORES
+
+ cmd := NewCommand("api_set_cores")
+
+ // Parse cores
+ cores, err := p.parseNumber()
+ if err != nil {
+ return nil, fmt.Errorf("expected cores: %w", err)
+ }
+ cmd.Params["cores"] = cores
+
+ p.nextToken()
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
+// SET MEMORY 4;
+func (p *Parser) parseAPISetMemory() (*Command, error) {
+ p.nextToken() // consume MEMORY
+
+ cmd := NewCommand("api_set_memory")
+ // Parse memory size
+ memorySize, err := p.parseNumber()
+ if err != nil {
+ return nil, fmt.Errorf("expected memory size: %w", err)
+ }
+ cmd.Params["memory_size"] = memorySize
+
+ p.nextToken()
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
+// SET CONCURRENCY 4;
+func (p *Parser) parseAPISetConcurrency() (*Command, error) {
+ p.nextToken() // consume CONCURRENCY
+
+ cmd := NewCommand("api_set_concurrency")
+ // Parse concurrency
+ concurrency, err := p.parseNumber()
+ if err != nil {
+ return nil, fmt.Errorf("expected concurrency: %w", err)
+ }
+ cmd.Params["concurrency"] = concurrency
+
+ p.nextToken()
+ // Semicolon is optional
+ if p.curToken.Type == TokenSemicolon {
+ p.nextToken()
+ }
+
+ return cmd, nil
+}
+
// endregion SET commands
// region RESET commands
diff --git a/internal/handler/system_ee.go b/internal/handler/system_ee.go
index 489f8a0486..520a27e4b7 100644
--- a/internal/handler/system_ee.go
+++ b/internal/handler/system_ee.go
@@ -30,3 +30,33 @@ import (
func (h *SystemHandler) GetEnableAdmin(c *gin.Context) {
common.ErrorWithCode(c, common.CodeNotImplemented, "EnableAdmin not implemented")
}
+
+// GetCores /api/v1/system/cores [GET]
+func (h *SystemHandler) GetCores(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Get cores not implemented")
+}
+
+// SetCores /api/v1/system/cores [PUT]
+func (h *SystemHandler) SetCores(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Set cores not implemented")
+}
+
+// GetMemory /api/v1/system/memory [GET]
+func (h *SystemHandler) GetMemory(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Get memory not implemented")
+}
+
+// SetMemory /api/v1/system/memory [PUT]
+func (h *SystemHandler) SetMemory(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Set memory not implemented")
+}
+
+// GetConcurrency /api/v1/system/concurrency [GET]
+func (h *SystemHandler) GetConcurrency(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Get concurrency not implemented")
+}
+
+// SetConcurrency /api/v1/system/concurrency [PUT]
+func (h *SystemHandler) SetConcurrency(c *gin.Context) {
+ common.ErrorWithCode(c, common.CodeNotImplemented, "Set concurrency not implemented")
+}
diff --git a/internal/router/router.go b/internal/router/router.go
index a12eeae0c3..963cc1ff5c 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -691,6 +691,13 @@ func (r *Router) Setup(engine *gin.Engine) {
}
system.GET("/hardware", r.systemHandler.GetHardwareInfo)
+
+ system.GET("/cores", r.systemHandler.GetCores)
+ system.PUT("/cores", r.systemHandler.SetCores)
+ system.GET("/memory", r.systemHandler.GetMemory)
+ system.PUT("/memory", r.systemHandler.SetMemory)
+ system.GET("/concurrency", r.systemHandler.GetConcurrency)
+ system.PUT("/concurrency", r.systemHandler.SetConcurrency)
}
// Document routes