feat: Add system information fields and localization for new engines
- Introduced new fields for keyword index engine, vector store engine, and graph database engine in the system info API response. - Updated localization files in English, Russian, and Chinese to include labels and descriptions for the new system information fields. - Enhanced the SystemInfo.vue component to display the new engine information in the settings view.
This commit is contained in:
+95
-11
@@ -1,24 +1,35 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// SystemHandler handles system-related requests
|
||||
type SystemHandler struct{}
|
||||
type SystemHandler struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewSystemHandler creates a new system handler
|
||||
func NewSystemHandler() *SystemHandler {
|
||||
return &SystemHandler{}
|
||||
func NewSystemHandler(cfg *config.Config) *SystemHandler {
|
||||
return &SystemHandler{
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// GetSystemInfoResponse defines the response structure for system info
|
||||
type GetSystemInfoResponse struct {
|
||||
Version string `json:"version"`
|
||||
CommitID string `json:"commit_id,omitempty"`
|
||||
BuildTime string `json:"build_time,omitempty"`
|
||||
GoVersion string `json:"go_version,omitempty"`
|
||||
Version string `json:"version"`
|
||||
CommitID string `json:"commit_id,omitempty"`
|
||||
BuildTime string `json:"build_time,omitempty"`
|
||||
GoVersion string `json:"go_version,omitempty"`
|
||||
KeywordIndexEngine string `json:"keyword_index_engine,omitempty"`
|
||||
VectorStoreEngine string `json:"vector_store_engine,omitempty"`
|
||||
GraphDatabaseEngine string `json:"graph_database_engine,omitempty"`
|
||||
}
|
||||
|
||||
// 编译时注入的版本信息
|
||||
@@ -33,11 +44,23 @@ var (
|
||||
func (h *SystemHandler) GetSystemInfo(c *gin.Context) {
|
||||
ctx := logger.CloneContext(c.Request.Context())
|
||||
|
||||
// Get keyword index engine from RETRIEVE_DRIVER
|
||||
keywordIndexEngine := h.getKeywordIndexEngine()
|
||||
|
||||
// Get vector store engine from config or RETRIEVE_DRIVER
|
||||
vectorStoreEngine := h.getVectorStoreEngine()
|
||||
|
||||
// Get graph database engine from NEO4J_ENABLE
|
||||
graphDatabaseEngine := h.getGraphDatabaseEngine()
|
||||
|
||||
response := GetSystemInfoResponse{
|
||||
Version: Version,
|
||||
CommitID: CommitID,
|
||||
BuildTime: BuildTime,
|
||||
GoVersion: GoVersion,
|
||||
Version: Version,
|
||||
CommitID: CommitID,
|
||||
BuildTime: BuildTime,
|
||||
GoVersion: GoVersion,
|
||||
KeywordIndexEngine: keywordIndexEngine,
|
||||
VectorStoreEngine: vectorStoreEngine,
|
||||
GraphDatabaseEngine: graphDatabaseEngine,
|
||||
}
|
||||
|
||||
logger.Info(ctx, "System info retrieved successfully")
|
||||
@@ -47,3 +70,64 @@ func (h *SystemHandler) GetSystemInfo(c *gin.Context) {
|
||||
"data": response,
|
||||
})
|
||||
}
|
||||
|
||||
// getKeywordIndexEngine returns the keyword index engine name
|
||||
func (h *SystemHandler) getKeywordIndexEngine() string {
|
||||
retrieveDriver := os.Getenv("RETRIEVE_DRIVER")
|
||||
if retrieveDriver == "" {
|
||||
return "未配置"
|
||||
}
|
||||
|
||||
drivers := strings.Split(retrieveDriver, ",")
|
||||
// Filter out engines that support keyword retrieval
|
||||
keywordEngines := []string{}
|
||||
for _, driver := range drivers {
|
||||
driver = strings.TrimSpace(driver)
|
||||
if driver == "postgres" || driver == "elasticsearch_v7" || driver == "elasticsearch_v8" {
|
||||
keywordEngines = append(keywordEngines, driver)
|
||||
}
|
||||
}
|
||||
|
||||
if len(keywordEngines) == 0 {
|
||||
return "未配置"
|
||||
}
|
||||
return strings.Join(keywordEngines, ", ")
|
||||
}
|
||||
|
||||
// getVectorStoreEngine returns the vector store engine name
|
||||
func (h *SystemHandler) getVectorStoreEngine() string {
|
||||
// First check config.yaml
|
||||
if h.cfg != nil && h.cfg.VectorDatabase != nil && h.cfg.VectorDatabase.Driver != "" {
|
||||
return h.cfg.VectorDatabase.Driver
|
||||
}
|
||||
|
||||
// Fallback to RETRIEVE_DRIVER for vector support
|
||||
retrieveDriver := os.Getenv("RETRIEVE_DRIVER")
|
||||
if retrieveDriver == "" {
|
||||
return "未配置"
|
||||
}
|
||||
|
||||
drivers := strings.Split(retrieveDriver, ",")
|
||||
// Filter out engines that support vector retrieval
|
||||
vectorEngines := []string{}
|
||||
for _, driver := range drivers {
|
||||
driver = strings.TrimSpace(driver)
|
||||
if driver == "postgres" || driver == "elasticsearch_v8" {
|
||||
vectorEngines = append(vectorEngines, driver)
|
||||
}
|
||||
}
|
||||
|
||||
if len(vectorEngines) == 0 {
|
||||
return "未配置"
|
||||
}
|
||||
return strings.Join(vectorEngines, ", ")
|
||||
}
|
||||
|
||||
// getGraphDatabaseEngine returns the graph database engine name
|
||||
func (h *SystemHandler) getGraphDatabaseEngine() string {
|
||||
neo4jEnable := strings.ToLower(os.Getenv("NEO4J_ENABLE"))
|
||||
if neo4jEnable == "true" {
|
||||
return "Neo4j"
|
||||
}
|
||||
return "未启用"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user