Skip to content

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

Python: remove unused index (#17008)

Jin Hai7c698f8e4b07
diff --git a/api/db/db_models.py b/api/db/db_models.py
index afc59ad576..b79dddc4cd 100644
--- a/api/db/db_models.py
+++ b/api/db/db_models.py
@@ -1456,6 +1456,14 @@ def alter_db_rename_column(migrator, table_name, old_column_name, new_column_nam
pass
+def alter_db_drop_index(migrator, table_name, index_name):
+ try:
+ migrate(migrator.drop_index(table_name, index_name))
+ except Exception:
+ # rename fail will lead to a weired error.
+ # logging.critical(f"Failed to rename {settings.DATABASE_TYPE.upper()}.{table_name} column {old_column_name} to {new_column_name}, error: {ex}")
+ pass
+
def ensure_model_indexes(migrator):
"""Create indexes declared by the Peewee models when they are missing."""
members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
@@ -1774,6 +1782,10 @@ def migrate_db():
alter_db_add_column(migrator, "file_commit_item", "content_after_location", CharField(max_length=512, null=True))
alter_db_add_column(migrator, "file_commit_item", "slug_kwd", CharField(max_length=512, null=True, index=True))
alter_db_add_column(migrator, "file_commit_item", "page_type_kwd", CharField(max_length=32, null=True, index=True))
+ alter_db_drop_index(migrator, "tenant_langfuse", "idx_tenant_langfuse_secret_key")
+ alter_db_drop_index(migrator, "tenant_langfuse", "idx_tenant_langfuse_public_key")
+ alter_db_drop_index(migrator, "tenant_langfuse", "idx_tenant_langfuse_host")
+
# Drop both the explicit "idx_*" name from later migrations AND the
# Peewee-auto-derived "<table-as-classname>_<col1>_<col2>" name from the
# original TenantModelInstance definition (commit dc4b82523). Databases
diff --git a/internal/admin/handler.go b/internal/admin/handler.go
index 0b53f16dc7..ae5d4aee16 100644
--- a/internal/admin/handler.go
+++ b/internal/admin/handler.go
@@ -86,8 +86,8 @@ func (h *Handler) Ping(c *gin.Context) {
// @Summary Admin Login
// @Description Admin login verification using email, only superuser can log in
// @Tags admin
-// @Accept json
-// @Produce json
+// @Accept JSON
+// @Produce JSON
// @Param request body service.EmailLoginRequest true "login info with email"
// @Success 200 {object} map[string]interface{}
// @Router /admin/login [post]
@@ -258,16 +258,24 @@ func (h *Handler) CreateUser(c *gin.Context) {
common.SuccessWithData(c, userInfo, "User created successfully")
}
-// GetUser handle get user
-func (h *Handler) GetUser(c *gin.Context) {
+func getUserName(c *gin.Context) (string, error) {
encodedUsername := c.Param("username")
username, err := common.DecodeFromBase64(encodedUsername)
if err != nil {
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
+ return "", err
}
if username == "" {
common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
+ return "", err
+ }
+ return username, nil
+}
+
+// GetUser handle get user
+func (h *Handler) GetUser(c *gin.Context) {
+ username, err := getUserName(c)
+ if err != nil {
return
}
@@ -286,14 +294,8 @@ func (h *Handler) GetUser(c *gin.Context) {
// DeleteUser handle delete user
func (h *Handler) DeleteUser(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -318,14 +320,8 @@ type ChangePasswordHTTPRequest struct {
// ChangePassword handle change password
func (h *Handler) ChangePassword(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -350,14 +346,8 @@ type UpdateActivateStatusHTTPRequest struct {
// UpdateUserActivateStatus handle update user activate status
func (h *Handler) UpdateUserActivateStatus(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -383,14 +373,8 @@ func (h *Handler) UpdateUserActivateStatus(c *gin.Context) {
// GrantAdmin handle grant admin role
func (h *Handler) GrantAdmin(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -411,14 +395,8 @@ func (h *Handler) GrantAdmin(c *gin.Context) {
// RevokeAdmin handle revoke admin role
func (h *Handler) RevokeAdmin(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -439,14 +417,8 @@ func (h *Handler) RevokeAdmin(c *gin.Context) {
// ListUserAPITokens handle get user API keys
func (h *Handler) ListUserAPITokens(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -461,14 +433,8 @@ func (h *Handler) ListUserAPITokens(c *gin.Context) {
// GenerateUserAPIToken handle generate user API key
func (h *Handler) GenerateUserAPIToken(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -647,11 +613,6 @@ func (h *Handler) ListVariables(c *gin.Context) {
variable, err := h.service.GetVariable(req.VarName)
if err != nil {
- // Check if it's an AdminException
- if adminErr, ok := err.(*AdminException); ok {
- common.ErrorWithCode(c, common.CodeBadRequest, adminErr.Message)
- return
- }
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}
@@ -707,11 +668,6 @@ func (h *Handler) SetVariable(c *gin.Context) {
}
if err := h.service.SetVariable(req.VarName, req.VarValue); err != nil {
- // Check if it's an AdminException
- if adminErr, ok := err.(*AdminException); ok {
- common.ErrorWithCode(c, common.CodeBadRequest, adminErr.Message)
- return
- }
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}
@@ -1141,7 +1097,7 @@ type ListIngestionTasksRequest struct {
Status *string `json:"status"`
}
-// ListIngestionTasks
+// ListIngestionTasks handle list ingestion tasks
func (h *Handler) ListIngestionTasks(c *gin.Context) {
var err error
var tasks []map[string]interface{}
diff --git a/internal/admin/handler_ee.go b/internal/admin/handler_ee.go
index c325599c69..36317d0595 100644
--- a/internal/admin/handler_ee.go
+++ b/internal/admin/handler_ee.go
@@ -861,14 +861,8 @@ func (h *Handler) ShowUserDatasetSummary(c *gin.Context) {
return
}
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -887,14 +881,8 @@ func (h *Handler) ShowUserDatasetSummary(c *gin.Context) {
// ShowUserSummary handle show user summary
func (h *Handler) ShowUserSummary(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -913,14 +901,8 @@ func (h *Handler) ShowUserSummary(c *gin.Context) {
// ShowUserStorage handle show user storage
func (h *Handler) ShowUserStorage(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -939,14 +921,8 @@ func (h *Handler) ShowUserStorage(c *gin.Context) {
// ShowUserQuota handle show user quota
func (h *Handler) ShowUserQuota(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -965,14 +941,8 @@ func (h *Handler) ShowUserQuota(c *gin.Context) {
// ShowUserIndex handle show user index
func (h *Handler) ShowUserIndex(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -996,14 +966,8 @@ type UpdateUserRoleHTTPRequest struct {
// UpdateUserRole handle update user role
func (h *Handler) UpdateUserRole(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1024,14 +988,8 @@ func (h *Handler) UpdateUserRole(c *gin.Context) {
// ShowUserPermission handle show user permission
func (h *Handler) ShowUserPermission(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1046,14 +1004,8 @@ func (h *Handler) ShowUserPermission(c *gin.Context) {
// ListUserDatasets handle show user datasets
func (h *Handler) ListUserDatasets(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1068,14 +1020,8 @@ func (h *Handler) ListUserDatasets(c *gin.Context) {
// ListUserAgents handle show user agents
func (h *Handler) ListUserAgents(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1090,14 +1036,8 @@ func (h *Handler) ListUserAgents(c *gin.Context) {
// ListUserChats handle show user chats
func (h *Handler) ListUserChats(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1112,14 +1052,8 @@ func (h *Handler) ListUserChats(c *gin.Context) {
// ListUserSearches handle show user searches
func (h *Handler) ListUserSearches(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1134,14 +1068,8 @@ func (h *Handler) ListUserSearches(c *gin.Context) {
// ListUserModels handle show user models
func (h *Handler) ListUserModels(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1156,14 +1084,8 @@ func (h *Handler) ListUserModels(c *gin.Context) {
// ListUserFiles handle show user files
func (h *Handler) ListUserFiles(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1178,14 +1100,8 @@ func (h *Handler) ListUserFiles(c *gin.Context) {
// ListUserProviders handle show user providers
func (h *Handler) ListUserProviders(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1662,14 +1578,8 @@ func (h *Handler) PurgeUserData(c *gin.Context) {
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
return
}
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
@@ -1758,14 +1668,8 @@ func (h *Handler) DeleteUserAPIKey(c *gin.Context) {
// ListUserAPIKeys handle list user API keys
func (h *Handler) ListUserAPIKeys(c *gin.Context) {
- encodedUsername := c.Param("username")
- username, err := common.DecodeFromBase64(encodedUsername)
+ username, err := getUserName(c)
if err != nil {
- common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
- return
- }
- if username == "" {
- common.ErrorWithCode(c, common.CodeBadRequest, "Username is required")
return
}
diff --git a/internal/admin/service.go b/internal/admin/service.go
index cf62625ec5..d9a29fe879 100644
--- a/internal/admin/service.go
+++ b/internal/admin/service.go
@@ -102,7 +102,7 @@ func (s *Service) Logout(user interface{}) error {
return nil
}
-// ListTasks
+// ListIngestionTasks list all ingestion tasks for admin user
func (s *Service) ListIngestionTasks() ([]map[string]interface{}, error) {
return s.ingestionTaskSvc.ListAllForAdmin()
}
@@ -172,12 +172,12 @@ func (s *Service) ListUsers(pageIndex, pageSize int, name, status, sort, orderBy
func (s *Service) CreateUser(username, password, role string) (map[string]interface{}, error) {
emailRegex := regexp.MustCompile(`^[\w\._-]+@([\w_-]+\.)+[\w-]{2,}$`)
if !emailRegex.MatchString(username) {
- return nil, fmt.Errorf("Invalid email address: %s!", username)
+ return nil, fmt.Errorf("invalid email address: %s", username)
}
existUser, _ := s.userDAO.GetByEmail(username)
if existUser != nil {
- return nil, fmt.Errorf("User '%s' already exists", username)
+ return nil, fmt.Errorf("user '%s' already exists", username)
}
decryptedPassword, err := common.DecryptPassword(password)
@@ -235,35 +235,35 @@ func (s *Service) CreateUser(username, password, role string) (map[string]interf
// Get default model IDs from config
cfg := server.GetConfig()
- chatMdl := ""
- embdMdl := ""
- asrMdl := ""
- img2txtMdl := ""
- rerankMdl := ""
+ chatModel := ""
+ embeddingModel := ""
+ asrModel := ""
+ vlmModel := ""
+ rerankModel := ""
parserIDs := "naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,email:Email,tag:Tag"
if cfg != nil {
- chatMdl = cfg.UserDefaultLLM.DefaultModels.ChatModel.Name
- embdMdl = cfg.UserDefaultLLM.DefaultModels.EmbeddingModel.Name
- asrMdl = cfg.UserDefaultLLM.DefaultModels.ASRModel.Name
- img2txtMdl = cfg.UserDefaultLLM.DefaultModels.Image2TextModel.Name
- rerankMdl = cfg.UserDefaultLLM.DefaultModels.RerankModel.Name
+ chatModel = cfg.UserDefaultLLM.DefaultModels.ChatModel.Name
+ embeddingModel = cfg.UserDefaultLLM.DefaultModels.EmbeddingModel.Name
+ asrModel = cfg.UserDefaultLLM.DefaultModels.ASRModel.Name
+ vlmModel = cfg.UserDefaultLLM.DefaultModels.Image2TextModel.Name
+ rerankModel = cfg.UserDefaultLLM.DefaultModels.RerankModel.Name
}
tenantStatus := "1"
tenant := &entity.Tenant{
ID: userID,
Name: &tenantName,
- LLMID: chatMdl,
- EmbdID: embdMdl,
- ASRID: asrMdl,
- Img2TxtID: img2txtMdl,
- RerankID: rerankMdl,
+ LLMID: chatModel,
+ EmbdID: embeddingModel,
+ ASRID: asrModel,
+ Img2TxtID: vlmModel,
+ RerankID: rerankModel,
ParserIDs: parserIDs,
Credit: 512,
Status: &tenantStatus,
}
- if err := tx.Create(tenant).Error; err != nil {
+ if err = tx.Create(tenant).Error; err != nil {
rollbackTx()
return nil, fmt.Errorf("failed to create tenant: %w", err)
}
@@ -365,16 +365,16 @@ func (s *Service) getInitTenantLLM(userID string) ([]*entity.TenantLLM, error) {
// Get LLMs for each unique factory
for _, factoryConfig := range uniqueFactories {
- llms, err := s.llmDAO.GetByFactory(factoryConfig.Factory)
+ models, err := s.llmDAO.GetByFactory(factoryConfig.Factory)
if err != nil {
common.Warn("failed to get LLMs for factory", zap.String("factory", factoryConfig.Factory), zap.Error(err))
continue
}
- for _, llm := range llms {
+ for _, model := range models {
// Determine API key and base URL based on model type
var apiKey, apiBase string
- switch llm.ModelType {
+ switch model.ModelType {
case entity.ModelTypeChat.String():
apiKey = factoryConfig.APIKey
apiBase = factoryConfig.BaseURL
@@ -420,12 +420,12 @@ func (s *Service) getInitTenantLLM(userID string) ([]*entity.TenantLLM, error) {
}
maxTokens := int64(8192)
- if llm.MaxTokens > 0 {
- maxTokens = llm.MaxTokens
+ if model.MaxTokens > 0 {
+ maxTokens = model.MaxTokens
}
- llmName := llm.LLMName
- modelType := llm.ModelType
+ llmName := model.LLMName
+ modelType := model.ModelType
tenantLLM := &entity.TenantLLM{
TenantID: userID,
LLMFactory: factoryConfig.Factory,
@@ -474,7 +474,7 @@ func (s *Service) GetUserDetails(username string) (map[string]interface{}, error
}, nil
}
-// DeleteUserResult
+// DeleteUserResult result of delete user operation
type DeleteUserResult struct {
Username string `json:"username"`
TenantLLMCount int `json:"tenant_llm_count"`
@@ -500,23 +500,23 @@ func (s *Service) DeleteUser(username string) (*DeleteUserResult, error) {
}
userList, err := s.userDAO.ListByEmail(username)
if err != nil || len(userList) == 0 {
- return nil, fmt.Errorf("User '%s' not found", username)
+ return nil, fmt.Errorf("user '%s' not found", username)
}
if len(userList) > 1 {
- return nil, fmt.Errorf("Exist more than 1 user: %s!", username)
+ return nil, fmt.Errorf("exist more than 1 user: %s", username)
}
user := userList[0]
// Check if user is active - cannot delete active users
if user.IsActive == "1" {
- return nil, fmt.Errorf("User '%s' is active and can't be deleted. Please deactivate the user first", username)
+ return nil, fmt.Errorf("user '%s' is active and can't be deleted. Please deactivate the user first", username)
}
// Check if user is superuser - cannot delete admin accounts
if user.IsSuperuser != nil && *user.IsSuperuser {
- return nil, fmt.Errorf("Cannot delete admin account")
+ return nil, fmt.Errorf("user '%s' is admin account and cannot be deleted", username)
}
// Get user-tenant relations
@@ -692,11 +692,11 @@ func (s *Service) DeleteUser(username string) (*DeleteUserResult, error) {
func (s *Service) ChangePassword(username, newPassword string) error {
userList, err := s.userDAO.ListByEmail(username)
if err != nil || len(userList) == 0 {
- return fmt.Errorf("User '%s' not found", username)
+ return fmt.Errorf("user '%s' not found", username)
}
if len(userList) > 1 {
- return fmt.Errorf("Exist more than 1 user: %s!", username)
+ return fmt.Errorf("exist more than 1 user: %s", username)
}
user := userList[0]
@@ -734,11 +734,11 @@ func (s *Service) ChangePassword(username, newPassword string) error {
func (s *Service) UpdateUserActivateStatus(username string, isActive bool) error {
userList, err := s.userDAO.ListByEmail(username)
if err != nil || len(userList) == 0 {
- return fmt.Errorf("User '%s' not found", username)
+ return fmt.Errorf("user '%s' not found", username)
}
if len(userList) > 1 {
- return fmt.Errorf("Exist more than 1 user: %s!", username)
+ return fmt.Errorf("exist more than 1 user: %s", username)
}
user := userList[0]
@@ -770,11 +770,11 @@ func (s *Service) UpdateUserActivateStatus(username string, isActive bool) error
func (s *Service) GrantAdmin(username string) error {
userList, err := s.userDAO.ListByEmail(username)
if err != nil || len(userList) == 0 {
- return fmt.Errorf("User '%s' not found", username)
+ return fmt.Errorf("user '%s' not found", username)
}
if len(userList) > 1 {
- return fmt.Errorf("Exist more than 1 user: %s!", username)
+ return fmt.Errorf("exist more than 1 user: %s", username)
}
user := userList[0]
@@ -802,11 +802,11 @@ func (s *Service) GrantAdmin(username string) error {
func (s *Service) RevokeAdmin(username string) error {
userList, err := s.userDAO.ListByEmail(username)
if err != nil || len(userList) == 0 {
- return fmt.Errorf("User '%s' not found", username)
+ return fmt.Errorf("user '%s' not found", username)
}
if len(userList) > 1 {
- return fmt.Errorf("Exist more than 1 user: %s!", username)
+ return fmt.Errorf("exist more than 1 user: %s", username)
}
user := userList[0]
@@ -818,7 +818,7 @@ func (s *Service) RevokeAdmin(username string) error {
isSuperuser := false
user.IsSuperuser = &isSuperuser
- if err := s.userDAO.Update(user); err != nil {
+ if err = s.userDAO.Update(user); err != nil {
return fmt.Errorf("failed to update user: %w", err)
}
@@ -1258,11 +1258,11 @@ func (s *Service) checkRAGFlowServerAlive(name string) (map[string]interface{},
func (s *Service) checkMinioAlive(name string) (map[string]interface{}, error) {
startTime := time.Now()
- // Get minio config from allConfigs
+ // Get MinIO file store config from allConfigs
var host string
var port int
var secure bool
- var verify bool = true
+ verify := true
allConfigs := server.GetAllConfigs()
for _, config := range allConfigs {
diff --git a/internal/admin/service_ee.go b/internal/admin/service_ee.go
index 37f73f29c0..7d071b8430 100644
--- a/internal/admin/service_ee.go
+++ b/internal/admin/service_ee.go
@@ -434,7 +434,7 @@ func (s *Service) ShowUserDatasetSummary(email, dataset string) (map[string]inte
return result, nil
}
-// GetUserSummary get user summary for enterprise edition
+// ShowUserSummary show user summary for enterprise edition
func (s *Service) ShowUserSummary(email string) (map[string]interface{}, error) {
// Query user by email
var user entity.User
diff --git a/internal/agent/audio/model_provider_synthesizer.go b/internal/agent/audio/model_provider_synthesizer.go
index 0809736814..a1ae930275 100644
--- a/internal/agent/audio/model_provider_synthesizer.go
+++ b/internal/agent/audio/model_provider_synthesizer.go
@@ -87,7 +87,7 @@ func SetModelProviderSynthesizer(fn ModelProviderFunc) {
type modelProviderSynthesizer struct {
fn ModelProviderFunc
- redis *redis.RedisClient
+ redis *redis.Client
}
func (m *modelProviderSynthesizer) Synthesize(ctx context.Context, req SynthesizeRequest) (*SynthesizeResponse, error) {
diff --git a/internal/engine/redis/redis.go b/internal/engine/redis/redis.go
index 2838f70766..ca44a2992d 100644
--- a/internal/engine/redis/redis.go
+++ b/internal/engine/redis/redis.go
@@ -35,12 +35,12 @@ import (
)
var (
- globalClient *RedisClient
+ globalClient *Client
once sync.Once
)
-// RedisClient wraps go-redis client with additional utility methods
-type RedisClient struct {
+// Client wraps go-redis client with additional utility methods
+type Client struct {
client *redis.Client
luaDeleteIfEqual *redis.Script
luaTokenBucket *redis.Script
@@ -48,8 +48,8 @@ type RedisClient struct {
config *server.RedisConfig
}
-// RedisMsg represents a message from Redis Stream
-type RedisMsg struct {
+// Message represents a message from Redis Stream
+type Message struct {
consumer *redis.Client
queueName string
groupName string
@@ -128,7 +128,7 @@ func Init(cfg *server.RedisConfig) error {
return
}
- globalClient = &RedisClient{
+ globalClient = &Client{
client: client,
config: cfg,
luaDeleteIfEqual: redis.NewScript(luaDeleteIfEqualScript),
@@ -145,7 +145,7 @@ func Init(cfg *server.RedisConfig) error {
}
// Get gets global Redis client instance
-func Get() *RedisClient {
+func Get() *Client {
return globalClient
}
@@ -163,7 +163,7 @@ func IsEnabled() bool {
}
// Health checks if Redis is healthy
-func (r *RedisClient) Health() bool {
+func (r *Client) Health() bool {
if r.client == nil {
return false
}
@@ -186,7 +186,7 @@ func (r *RedisClient) Health() bool {
}
// Info returns Redis server information
-func (r *RedisClient) Info() map[string]interface{} {
+func (r *Client) Info() map[string]interface{} {
if r.client == nil {
return nil
}
@@ -269,12 +269,12 @@ func parseInt(s string) int {
}
// IsAlive checks if Redis client is alive
-func (r *RedisClient) IsAlive() bool {
+func (r *Client) IsAlive() bool {
return r.client != nil
}
// Exist checks if key exists
-func (r *RedisClient) Exist(key string) (bool, error) {
+func (r *Client) Exist(key string) (bool, error) {
if r.client == nil {
return false, nil
}
@@ -288,7 +288,7 @@ func (r *RedisClient) Exist(key string) (bool, error) {
}
// Get gets value by key
-func (r *RedisClient) Get(key string) (string, error) {
+func (r *Client) Get(key string) (string, error) {
if r.client == nil {
return "", nil
}
@@ -305,7 +305,7 @@ func (r *RedisClient) Get(key string) (string, error) {
}
// SetObj sets object with JSON serialization
-func (r *RedisClient) SetObj(key string, obj interface{}, exp time.Duration) bool {
+func (r *Client) SetObj(key string, obj interface{}, exp time.Duration) bool {
if r.client == nil {
return false
}
@@ -323,7 +323,7 @@ func (r *RedisClient) SetObj(key string, obj interface{}, exp time.Duration) boo
}
// GetObj gets and unmarshals object from Redis
-func (r *RedisClient) GetObj(key string, dest interface{}) bool {
+func (r *Client) GetObj(key string, dest interface{}) bool {
if r.client == nil {
return false
}
@@ -344,7 +344,7 @@ func (r *RedisClient) GetObj(key string, dest interface{}) bool {
}
// Set sets value with expiration
-func (r *RedisClient) Set(key string, value string, exp time.Duration) bool {
+func (r *Client) Set(key string, value string, exp time.Duration) bool {
if r.client == nil {
return false
}
@@ -357,7 +357,7 @@ func (r *RedisClient) Set(key string, value string, exp time.Duration) bool {
}
// SetNX sets value only if key does not exist
-func (r *RedisClient) SetNX(key string, value string, exp time.Duration) bool {
+func (r *Client) SetNX(key string, value string, exp time.Duration) bool {
if r.client == nil {
return false
}
@@ -372,7 +372,7 @@ func (r *RedisClient) SetNX(key string, value string, exp time.Duration) bool {
// GetOrCreateSecretKey atomically retrieves an existing key or creates a new one
// Uses Redis SETNX command to ensure atomicity across multiple goroutines/processes
-func (r *RedisClient) GetOrCreateKey(key string, value string) (string, error) {
+func (r *Client) GetOrCreateKey(key string, value string) (string, error) {
if r.client == nil {
return "", nil
}
@@ -408,7 +408,7 @@ func (r *RedisClient) GetOrCreateKey(key string, value string) (string, error) {
}
// SAdd adds member to set
-func (r *RedisClient) SAdd(key string, member string) bool {
+func (r *Client) SAdd(key string, member string) bool {
if r.client == nil {
return false
}
@@ -421,7 +421,7 @@ func (r *RedisClient) SAdd(key string, member string) bool {
}
// SRem removes member from set
-func (r *RedisClient) SRem(key string, member string) bool {
+func (r *Client) SRem(key string, member string) bool {
if r.client == nil {
return false
}
@@ -434,7 +434,7 @@ func (r *RedisClient) SRem(key string, member string) bool {
}
// SMembers returns all members of a set
-func (r *RedisClient) SMembers(key string) ([]string, error) {
+func (r *Client) SMembers(key string) ([]string, error) {
if r.client == nil {
return nil, nil
}
@@ -448,7 +448,7 @@ func (r *RedisClient) SMembers(key string) ([]string, error) {
}
// SIsMember checks if member exists in set
-func (r *RedisClient) SIsMember(key string, member string) bool {
+func (r *Client) SIsMember(key string, member string) bool {
if r.client == nil {
return false
}
@@ -462,7 +462,7 @@ func (r *RedisClient) SIsMember(key string, member string) bool {
}
// ZAdd adds member with score to sorted set
-func (r *RedisClient) ZAdd(key string, member string, score float64) bool {
+func (r *Client) ZAdd(key string, member string, score float64) bool {
if r.client == nil {
return false
}
@@ -475,7 +475,7 @@ func (r *RedisClient) ZAdd(key string, member string, score float64) bool {
}
// ZCount returns count of members with score in range
-func (r *RedisClient) ZCount(key string, min, max float64) int64 {
+func (r *Client) ZCount(key string, min, max float64) int64 {
if r.client == nil {
return 0
}
@@ -489,7 +489,7 @@ func (r *RedisClient) ZCount(key string, min, max float64) int64 {
}
// ZPopMin pops minimum score members from sorted set
-func (r *RedisClient) ZPopMin(key string, count int) ([]redis.Z, error) {
+func (r *Client) ZPopMin(key string, count int) ([]redis.Z, error) {
if r.client == nil {
return nil, nil
}
@@ -503,7 +503,7 @@ func (r *RedisClient) ZPopMin(key string, count int) ([]redis.Z, error) {
}
// ZRangeByScore returns members with score in range
-func (r *RedisClient) ZRangeByScore(key string, min, max float64) ([]string, error) {
+func (r *Client) ZRangeByScore(key string, min, max float64) ([]string, error) {
if r.client == nil {
return nil, nil
}
@@ -520,7 +520,7 @@ func (r *RedisClient) ZRangeByScore(key string, min, max float64) ([]string, err
}
// ZRemRangeByScore removes members with score in range
-func (r *RedisClient) ZRemRangeByScore(key string, min, max float64) int64 {
+func (r *Client) ZRemRangeByScore(key string, min, max float64) int64 {
if r.client == nil {
return 0
}
@@ -534,7 +534,7 @@ func (r *RedisClient) ZRemRangeByScore(key string, min, max float64) int64 {
}
// IncrBy increments key by increment
-func (r *RedisClient) IncrBy(key string, increment int64) (int64, error) {
+func (r *Client) IncrBy(key string, increment int64) (int64, error) {
if r.client == nil {
return 0, nil
}
@@ -548,7 +548,7 @@ func (r *RedisClient) IncrBy(key string, increment int64) (int64, error) {
}
// DecrBy decrements key by decrement
-func (r *RedisClient) DecrBy(key string, decrement int64) (int64, error) {
+func (r *Client) DecrBy(key string, decrement int64) (int64, error) {
if r.client == nil {
return 0, nil
}
@@ -562,7 +562,7 @@ func (r *RedisClient) DecrBy(key string, decrement int64) (int64, error) {
}
// GenerateAutoIncrementID generates auto-increment ID
-func (r *RedisClient) GenerateAutoIncrementID(keyPrefix string, namespace string, increment int64, ensureMinimum *int64) int64 {
+func (r *Client) GenerateAutoIncrementID(keyPrefix string, namespace string, increment int64, ensureMinimum *int64) int64 {
if r.client == nil {
return -1
}
@@ -612,7 +612,7 @@ func (r *RedisClient) GenerateAutoIncrementID(keyPrefix string, namespace string
}
// Transaction sets key with NX flag (transaction-like behavior)
-func (r *RedisClient) Transaction(key string, value string, exp time.Duration) bool {
+func (r *Client) Transaction(key string, value string, exp time.Duration) bool {
if r.client == nil {
return false
}
@@ -628,7 +628,7 @@ func (r *RedisClient) Transaction(key string, value string, exp time.Duration) b
}
// QueueProduct produces a message to Redis Stream
-func (r *RedisClient) QueueProduct(queue string, message interface{}) bool {
+func (r *Client) QueueProduct(queue string, message interface{}) bool {
if r.client == nil {
return false
}
@@ -655,7 +655,7 @@ func (r *RedisClient) QueueProduct(queue string, message interface{}) bool {
}
// QueueConsumer consumes a message from Redis Stream
-func (r *RedisClient) QueueConsumer(queueName, groupName, consumerName string, msgID string) (*RedisMsg, error) {
+func (r *Client) QueueConsumer(queueName, groupName, consumerName string, msgID string) (*Message, error) {
if r.client == nil {
return nil, nil
}
@@ -714,7 +714,7 @@ func (r *RedisClient) QueueConsumer(queueName, groupName, consumerName string, m
json.Unmarshal([]byte(msgStr), &messageData)
}
- return &RedisMsg{
+ return &Message{
consumer: r.client,
queueName: queueName,
groupName: groupName,
@@ -726,36 +726,36 @@ func (r *RedisClient) QueueConsumer(queueName, groupName, consumerName string, m
}
// Ack acknowledges the message
-func (m *RedisMsg) Ack() bool {
+func (m *Message) Ack() bool {
if m.consumer == nil {
return false
}
ctx := context.Background()
err := m.consumer.XAck(ctx, m.queueName, m.groupName, m.msgID).Err()
if err != nil {
- common.Warn("RedisMsg Ack error", zap.Error(err))
+ common.Warn("Message Ack error", zap.Error(err))
return false
}
return true
}
// GetMessage returns the message data
-func (m *RedisMsg) GetMessage() map[string]interface{} {
+func (m *Message) GetMessage() map[string]interface{} {
return m.message
}
// GetMsgID returns the message ID
-func (m *RedisMsg) GetMsgID() string {
+func (m *Message) GetMsgID() string {
return m.msgID
}
// GetPendingMsg gets pending messages
-func (r *RedisClient) GetPendingMsg(queue, groupName string) ([]redis.XPendingExt, error) {
+func (r *Client) GetPendingMsg(queue, groupName string) ([]redis.XPendingExt, error) {
if r.client == nil {
return nil, nil
}
ctx := context.Background()
- msgs, err := r.client.XPendingExt(ctx, &redis.XPendingExtArgs{
+ messages, err := r.client.XPendingExt(ctx, &redis.XPendingExtArgs{
Stream: queue,
Group: groupName,
Start: "-",
@@ -768,11 +768,11 @@ func (r *RedisClient) GetPendingMsg(queue, groupName string) ([]redis.XPendingEx
}
return nil, err
}
- return msgs, nil
+ return messages, nil
}
-// RequeueMsg requeues a message
-func (r *RedisClient) RequeueMsg(queue, groupName, msgID string) {
+// RequeueMsg re-enqueues a message
+func (r *Client) RequeueMsg(queue, groupName, msgID string) {
if r.client == nil {
return
}
@@ -799,7 +799,7 @@ func (r *RedisClient) RequeueMsg(queue, groupName, msgID string) {
}
// QueueInfo returns queue group info
-func (r *RedisClient) QueueInfo(queue, groupName string) (map[string]interface{}, error) {
+func (r *Client) QueueInfo(queue, groupName string) (map[string]interface{}, error) {
if r.client == nil {
return nil, nil
}
@@ -829,7 +829,7 @@ func (r *RedisClient) QueueInfo(queue, groupName string) (map[string]interface{}
}
// DeleteIfEqual deletes key if its value equals expected value (atomic)
-func (r *RedisClient) DeleteIfEqual(key, expectedValue string) bool {
+func (r *Client) DeleteIfEqual(key, expectedValue string) bool {
if r.client == nil {
return false
}
@@ -843,7 +843,7 @@ func (r *RedisClient) DeleteIfEqual(key, expectedValue string) bool {
}
// Delete deletes a key
-func (r *RedisClient) Delete(key string) bool {
+func (r *Client) Delete(key string) bool {
if r.client == nil {
return false
}
@@ -856,7 +856,7 @@ func (r *RedisClient) Delete(key string) bool {
}
// Expire sets expiration on a key
-func (r *RedisClient) Expire(key string, exp time.Duration) bool {
+func (r *Client) Expire(key string, exp time.Duration) bool {
if r.client == nil {
return false
}
@@ -869,7 +869,7 @@ func (r *RedisClient) Expire(key string, exp time.Duration) bool {
}
// TTL gets remaining time to live of a key
-func (r *RedisClient) TTL(key string) time.Duration {
+func (r *Client) TTL(key string) time.Duration {
if r.client == nil {
return -2
}
@@ -884,7 +884,7 @@ func (r *RedisClient) TTL(key string) time.Duration {
// DistributedLock distributed lock implementation
type DistributedLock struct {
- client *RedisClient
+ client *Client
lockKey string
lockValue string
timeout time.Duration
@@ -944,7 +944,7 @@ func (l *DistributedLock) Release() bool {
// TokenBucket token bucket rate limiter
type TokenBucket struct {
- client *RedisClient
+ client *Client
key string
capacity float64
rate float64
@@ -985,7 +985,7 @@ func (tb *TokenBucket) Allow(cost float64) (bool, float64) {
}
// GetClient returns the underlying go-redis client for advanced usage
-func (r *RedisClient) GetClient() *redis.Client {
+func (r *Client) GetClient() *redis.Client {
return r.client
}
@@ -998,7 +998,7 @@ func (r *RedisClient) GetClient() *redis.Client {
//
// Cost is fixed at 1.0; callers wanting variable cost should compose their
// own Lua. ctx is used for both the EVALSHA round-trip and the deadline.
-func (r *RedisClient) EvalTokenBucketStrict(
+func (r *Client) EvalTokenBucketStrict(
ctx context.Context, key string, capacity, rate float64,
) (allowed bool, err error) {
if r == nil || r.client == nil {
diff --git a/internal/engine/redis/redis_test.go b/internal/engine/redis/redis_test.go
index 0aefa85b95..d3fb2006eb 100644
--- a/internal/engine/redis/redis_test.go
+++ b/internal/engine/redis/redis_test.go
@@ -25,10 +25,10 @@ import (
"github.com/redis/go-redis/v9"
)
-// newStrictTestClient wires a miniredis-backed RedisClient for
+// newStrictTestClient wires a miniredis-backed Client for
// EvalTokenBucketStrict tests. Each call gets its own miniredis instance so
// tests do not share state via the package-level globalClient.
-func newStrictTestClient(t *testing.T) (*RedisClient, *miniredis.Miniredis) {
+func newStrictTestClient(t *testing.T) (*Client, *miniredis.Miniredis) {
t.Helper()
mr, err := miniredis.Run()
if err != nil {
@@ -39,7 +39,7 @@ func newStrictTestClient(t *testing.T) (*RedisClient, *miniredis.Miniredis) {
rdb := redis.NewClient(&redis.Options{Addr: mr.Addr()})
t.Cleanup(func() { _ = rdb.Close() })
- return &RedisClient{
+ return &Client{
client: rdb,
luaDeleteIfEqual: redis.NewScript(luaDeleteIfEqualScript),
luaTokenBucket: redis.NewScript(luaTokenBucketScript),
@@ -96,7 +96,7 @@ func TestEvalTokenBucketStrict_RedisDownFailsClosed(t *testing.T) {
// The uninitialised-Redis case must NOT silently pass; it must return
// (false, error) so the webhook handler can surface 102.
func TestEvalTokenBucketStrict_NilClient(t *testing.T) {
- var r *RedisClient
+ var r *Client
ok, err := r.EvalTokenBucketStrict(context.Background(), "tb:webhook", 1, 1)
if err == nil {
t.Fatalf("expected error on nil client, got nil")
diff --git a/internal/service/connector_box_oauth_test.go b/internal/service/connector_box_oauth_test.go
index 01341aaf0e..b31af12b31 100644
--- a/internal/service/connector_box_oauth_test.go
+++ b/internal/service/connector_box_oauth_test.go
@@ -20,7 +20,7 @@ func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
func forceNilConnectorRedis(t *testing.T) {
t.Helper()
previous := connectorRedisGet
- connectorRedisGet = func() *redisengine.RedisClient { return nil }
+ connectorRedisGet = func() *redisengine.Client { return nil }
t.Cleanup(func() {
connectorRedisGet = previous
})
diff --git a/internal/service/dataset.go b/internal/service/dataset.go
index 8e36436d48..7c19621293 100644
--- a/internal/service/dataset.go
+++ b/internal/service/dataset.go
@@ -429,7 +429,7 @@ func interfaceSlice(items ...string) []interface{} {
return result
}
-func clearGraphPhaseMarkers(redisClient *redisengine.RedisClient, datasetID string) {
+func clearGraphPhaseMarkers(redisClient *redisengine.Client, datasetID string) {
if redisClient == nil || datasetID == "" {
return
}
diff --git a/internal/service/nlp/synonym.go b/internal/service/nlp/synonym.go
index d072b5116d..4f86183661 100644
--- a/internal/service/nlp/synonym.go
+++ b/internal/service/nlp/synonym.go
@@ -34,14 +34,14 @@ type Synonym struct {
lookupNum atomic.Int64
loadTm time.Time
dictionary map[string][]string
- redis RedisClient // Optional Redis client for real-time synonym loading
+ redis Client // Optional Redis client for real-time synonym loading
wordNet *WordNet
resPath string
}
-// RedisClient interface for Redis operations
+// Client interface for Redis operations
// This should be implemented by the caller if Redis support is needed
-type RedisClient interface {
+type Client interface {
Get(key string) (string, error)
}
@@ -50,7 +50,7 @@ type RedisClient interface {
// wordnetDir: path to wordnet directory (e.g., "/usr/share/infinity/resource/wordnet").
//
// If empty, WordNet will not be initialized.
-func NewSynonym(redis RedisClient, resPath string, wordnetDir string) *Synonym {
+func NewSynonym(redis Client, resPath string, wordnetDir string) *Synonym {
s := &Synonym{
loadTm: time.Now().Add(-1000000 * time.Second),
dictionary: make(map[string][]string),
diff --git a/internal/service/nlp/synonym_test.go b/internal/service/nlp/synonym_test.go
index 785204ce61..90cd45c029 100644
--- a/internal/service/nlp/synonym_test.go
+++ b/internal/service/nlp/synonym_test.go
@@ -49,7 +49,7 @@ func init() {
testSynonymWordNetDir = "../../../resource/wordnet"
}
-// MockRedisClient is a mock implementation of RedisClient for testing
+// MockRedisClient is a mock implementation of Client for testing
type MockRedisClient struct {
data map[string]string
}
diff --git a/internal/service/oauth_login.go b/internal/service/oauth_login.go
index 9ff45890c2..84035e1dce 100644
--- a/internal/service/oauth_login.go
+++ b/internal/service/oauth_login.go
@@ -79,7 +79,7 @@ type OAuthLoginInit struct {
// OAuthLoginInitiate generates a state, persists it in Redis with a TTL,
// and returns the authorization URL the browser should be redirected to.
// Mirrors the body of Python's oauth_login.
-func (s *UserService) OAuthLoginInitiate(channel string, redis *redis.RedisClient) (*OAuthLoginInit, common.ErrorCode, error) {
+func (s *UserService) OAuthLoginInitiate(channel string, redis *redis.Client) (*OAuthLoginInit, common.ErrorCode, error) {
cfg, ok := lookupOAuthConfig(channel)
if !ok {
return nil, common.CodeDataError, fmt.Errorf("%w: %s", ErrOAuthInvalidChannel, channel)
@@ -126,7 +126,7 @@ type OAuthCallbackResult struct {
// When redis is non-nil the state is also verified against and consumed
// from Redis, defending against a replay where an attacker fishes a valid
// state out of a victim's URL but does not have the cookie.
-func (s *UserService) OAuthCallback(ctx context.Context, channel, code, callbackState, expectedState string, redis *redis.RedisClient) (*OAuthCallbackResult, common.ErrorCode, error) {
+func (s *UserService) OAuthCallback(ctx context.Context, channel, code, callbackState, expectedState string, redis *redis.Client) (*OAuthCallbackResult, common.ErrorCode, error) {
cfg, ok := lookupOAuthConfig(channel)
if !ok {
return nil, common.CodeDataError, fmt.Errorf("%w: %s", ErrOAuthInvalidChannel, channel)