diff --git a/Makefile b/Makefile index a6fd0b4..e445e1b 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ endif # Database initialization # ----------------------------------------------------------------------------- init-db: - @psql $(PG_DSN) -f docs/init.sql + @psql $(PG_DSN) -f rag-server/sql/schema.sql # ----------------------------------------------------------------------------- # Build targets @@ -89,10 +89,10 @@ init-db: build: update-homepage-manifests build-cli build-server build-homepage build-cli: - $(MAKE) -C client build + $(MAKE) -C rag-server/cmd/rag-server-cli build build-server: - $(MAKE) -C server build + $(MAKE) -C rag-server build build-homepage: $(MAKE) -C ui/homepage build SKIP_SYNC=1 @@ -107,7 +107,7 @@ update-homepage-manifests: start: start-openresty start-server start-homepage start-dl start-docs start-server: - $(MAKE) -C server start + $(MAKE) -C rag-server start start-homepage: $(MAKE) -C ui/homepage start @@ -116,7 +116,7 @@ start-homepage: stop: stop-server stop-homepage stop-openresty stop-server: - $(MAKE) -C server stop + $(MAKE) -C rag-server stop stop-homepage: $(MAKE) -C ui/homepage stop diff --git a/cmd/ingest/main.go b/cmd/ingest/main.go index 1ee18f8..52a19a2 100644 --- a/cmd/ingest/main.go +++ b/cmd/ingest/main.go @@ -8,11 +8,11 @@ import ( cfgpkg "xcontrol/internal/rag/config" "xcontrol/internal/rag/ingest" - "xcontrol/server/proxy" + "xcontrol/rag-server/proxy" ) func main() { - configPath := flag.String("config", "example/server/config/server.yaml", "config path") + configPath := flag.String("config", "rag-server/config/server.yaml", "config path") onlyRepo := flag.String("only-repo", "", "only ingest repo by name") dryRun := flag.Bool("dry-run", false, "dry run") maxFiles := flag.Int("max-files", 0, "limit number of files") diff --git a/cmd/xcontrol-server/main.go b/cmd/xcontrol-server/main.go index edf2b8b..6498122 100644 --- a/cmd/xcontrol-server/main.go +++ b/cmd/xcontrol-server/main.go @@ -16,10 +16,10 @@ import ( "gorm.io/gorm" rconfig "xcontrol/internal/rag/config" - "xcontrol/server" - "xcontrol/server/api" - "xcontrol/server/config" - "xcontrol/server/proxy" + "xcontrol/rag-server" + "xcontrol/rag-server/api" + "xcontrol/rag-server/config" + "xcontrol/rag-server/proxy" ) var ( diff --git a/docs/account-svc-plus.md b/docs/account-svc-plus.md index 3fe1f77..2b28996 100644 --- a/docs/account-svc-plus.md +++ b/docs/account-svc-plus.md @@ -27,7 +27,7 @@ - `internal/store`: 使用 `pgx` 连接 PostgreSQL,定义用户、会话、绑定等模型。 - `internal/cache`: 基于 `go-redis` 实现 token、会话的缓存与黑名单。 - `api`: 提供 `/login`、`/logout`、`/userinfo` 等 REST 接口,可按需扩展 gRPC。 -- `config`: 参照 `server/config` 风格,提供 YAML/ENV 配置解析。 +- `config`: 参照 `rag-server/config` 风格,提供 YAML/ENV 配置解析。 ## 3. 协议支持 @@ -97,7 +97,7 @@ CREATE TABLE IF NOT EXISTS sessions ( - 各模块以接口形式定义,新增认证协议只需实现 `auth.Provider` 接口并在配置中注册。 - 数据库与缓存层均预留版本迁移脚本,支持通过 `migrate` 工具升级。 - 通过 `plugins/` 目录支持业务插件,API 层暴露 Hook 以注入自定义逻辑。 -- 与现有 `xcontrol/server` 共享部分通用库(如 `config`、`logging`),保持代码风格一致。 +- 与现有 `xcontrol/rag-server` 共享部分通用库(如 `config`、`logging`),保持代码风格一致。 ## 8. 代码目录规划 diff --git a/docs/api-endpoints.md b/docs/api-endpoints.md index 21acfcb..83f8d6b 100644 --- a/docs/api-endpoints.md +++ b/docs/api-endpoints.md @@ -180,7 +180,7 @@ Expected response on success: `{"rows":1}`. If the vector database is unavailabl - **Description:** Ask the AI service for an answer. The endpoint uses [LangChainGo](https://github.com/tmc/langchaingo) to communicate with the configured model provider (e.g., OpenAI-compatible services or a local Ollama instance). Ensure the server configuration includes the proper token or local server URL. - **Body Parameters (JSON):** - `question` – Question text. -**Configuration:** In `server/config/server.yaml` the `models` section selects the LLM and embedding providers. +**Configuration:** In `rag-server/config/server.yaml` the `models` section selects the LLM and embedding providers. For local debugging with HuggingFace and Ollama: ```yaml diff --git a/docs/architecture/ai-kb-design.md b/docs/architecture/ai-kb-design.md index 34702ab..3fc8b4f 100644 --- a/docs/architecture/ai-kb-design.md +++ b/docs/architecture/ai-kb-design.md @@ -17,7 +17,7 @@ 接口示例: ```go -// server/api.go +// rag-server/api.go func RegisterRoutes(r *gin.Engine, db *pgx.Conn) { r.POST("/sync", SyncHandler) r.POST("/ask", AskHandler) diff --git a/docs/pg-vector-db-init.md b/docs/pg-vector-db-init.md index d99fa54..1e78d69 100644 --- a/docs/pg-vector-db-init.md +++ b/docs/pg-vector-db-init.md @@ -75,7 +75,7 @@ CREATE EXTENSION IF NOT EXISTS vector; -- 启用中文分词扩展(可选) CREATE EXTENSION IF NOT EXISTS zhparser; -导入初始化 SQL(例如 docs/init.sql) psql -h 127.0.0.1 -U shenlan -d shenlan -f docs/init.sql +导入初始化 SQL(例如 rag-server/sql/schema.sql) psql -h 127.0.0.1 -U shenlan -d shenlan -f rag-server/sql/schema.sql 验证扩展与表结构 psql -h 127.0.0.1 -U shenlan -d shenlan -c "\d+ documents" @@ -129,11 +129,11 @@ GRANT ALL PRIVILEGES ON DATABASE shenlan TO shenlan; ``` 6. 导入项目提供的初始化脚本 -项目在 `docs/init.sql` 中提供了建表及索引脚本,可通过 `psql` 导入: +项目在 `rag-server/sql/schema.sql` 中提供了建表及索引脚本,可通过 `psql` 导入: ```bash 退出再用 shenlan 用户运行 init.sql -psql -h 127.0.0.1 -U shenlan -d shenlan -f docs/init.sql +psql -h 127.0.0.1 -U shenlan -d shenlan -f rag-server/sql/schema.sql ``` 该脚本会: - 创建 `vector` 和 `zhparser` 扩展(如未启用)。 @@ -182,7 +182,7 @@ psql postgres://shenlan:<密码>@127.0.0.1:5432/mydb -c "\d+ documents" ## 6. 配置嵌入服务 -在 `server/config/server.yaml` 中新增 `embedding` 配置,使服务端能够对问题进行向量化检索: +在 `rag-server/config/server.yaml` 中新增 `embedding` 配置,使服务端能够对问题进行向量化检索: ```yaml global: diff --git a/internal/rag/ingest/ingest.go b/internal/rag/ingest/ingest.go index 36d3eba..633f0f0 100644 --- a/internal/rag/ingest/ingest.go +++ b/internal/rag/ingest/ingest.go @@ -12,7 +12,7 @@ import ( "xcontrol/internal/rag/embed" "xcontrol/internal/rag/store" rsync "xcontrol/internal/rag/sync" - "xcontrol/server/proxy" + "xcontrol/rag-server/proxy" ) // Options control ingestion behaviour. diff --git a/server/Makefile b/rag-server/Makefile similarity index 56% rename from server/Makefile rename to rag-server/Makefile index cb080cf..fcdfa3e 100644 --- a/server/Makefile +++ b/rag-server/Makefile @@ -3,9 +3,12 @@ MAIN_FILE := ../cmd/xcontrol-server/main.go MODULE := xcontrol PORT := 8090 OS := $(shell uname -s) +DB_URL ?= postgres://shenlan:password@127.0.0.1:5432/xserver?sslmode=disable +SCHEMA_FILE := sql/schema.sql +PSQL := psql "$(DB_URL)" -v ON_ERROR_STOP=1 export PATH := /usr/local/go/bin:$(PATH) -.PHONY: all build start stop restart clean init help dev test +.PHONY: all build start stop restart clean init help dev test init-db reinit-db drop-db all: build @@ -66,17 +69,30 @@ dev: fi clean: - @echo ">>> 清理构建产物" - rm -f $(APP_NAME) + @echo ">>> 清理构建产物" + rm -f $(APP_NAME) + +init-db: + @echo ">>> 初始化 RAG schema ($(SCHEMA_FILE))" + @$(PSQL) -f $(SCHEMA_FILE) + +drop-db: + @echo ">>> 删除 RAG schema 对象" + @$(PSQL) -c "DROP TABLE IF EXISTS public.documents CASCADE;" + +reinit-db: drop-db init-db help: - @echo " XControl Server Makefile" - @echo "" - @echo "make build 编译 server 可执行文件" - @echo "make start 后台运行 server (默认端口: $(PORT))" - @echo "make stop 停止运行 server" - @echo "make restart 重启 server" - @echo "make test 运行单元测试" - @echo "make dev 开发模式运行 (自动检测 air,如无则用 go run)" - @echo "make init 初始化依赖(自动选择国内/默认 Go 模块代理,air 可选)" - @echo "make clean 清理构建产物" + @echo " XControl Server Makefile" + @echo "" + @echo "make build 编译 server 可执行文件" + @echo "make start 后台运行 server (默认端口: $(PORT))" + @echo "make stop 停止运行 server" + @echo "make restart 重启 server" + @echo "make test 运行单元测试" + @echo "make dev 开发模式运行 (自动检测 air,如无则用 go run)" + @echo "make init 初始化依赖(自动选择国内/默认 Go 模块代理,air 可选)" + @echo "make clean 清理构建产物" + @echo "make init-db 初始化数据库 schema ($(SCHEMA_FILE))" + @echo "make drop-db 删除 RAG 相关数据库对象" + @echo "make reinit-db 重置数据库 schema (drop + init)" diff --git a/server/api/admin_settings.go b/rag-server/api/admin_settings.go similarity index 98% rename from server/api/admin_settings.go rename to rag-server/api/admin_settings.go index f1a03b1..f2c58c3 100644 --- a/server/api/admin_settings.go +++ b/rag-server/api/admin_settings.go @@ -7,7 +7,7 @@ import ( "github.com/gin-gonic/gin" - "xcontrol/server/internal/service" + "xcontrol/rag-server/internal/service" ) var allowedRoles = map[string]struct{}{ diff --git a/server/api/admin_settings_test.go b/rag-server/api/admin_settings_test.go similarity index 97% rename from server/api/admin_settings_test.go rename to rag-server/api/admin_settings_test.go index cc186da..d041e83 100644 --- a/server/api/admin_settings_test.go +++ b/rag-server/api/admin_settings_test.go @@ -11,8 +11,8 @@ import ( "gorm.io/driver/sqlite" "gorm.io/gorm" - "xcontrol/server/internal/model" - "xcontrol/server/internal/service" + "xcontrol/rag-server/internal/model" + "xcontrol/rag-server/internal/service" ) func setupAdminSettingsTestRouter(t *testing.T) *gin.Engine { diff --git a/server/api/askai.go b/rag-server/api/askai.go similarity index 100% rename from server/api/askai.go rename to rag-server/api/askai.go diff --git a/server/api/askai_config_test.go b/rag-server/api/askai_config_test.go similarity index 100% rename from server/api/askai_config_test.go rename to rag-server/api/askai_config_test.go diff --git a/server/api/askai_test.go b/rag-server/api/askai_test.go similarity index 100% rename from server/api/askai_test.go rename to rag-server/api/askai_test.go diff --git a/server/api/config.go b/rag-server/api/config.go similarity index 81% rename from server/api/config.go rename to rag-server/api/config.go index 84eed9d..8d31bda 100644 --- a/server/api/config.go +++ b/rag-server/api/config.go @@ -3,7 +3,7 @@ package api import ( "gorm.io/gorm" - "xcontrol/server/internal/service" + "xcontrol/rag-server/internal/service" ) // ConfigureServiceDB configures the internal service database connection. diff --git a/server/api/knowledge.go b/rag-server/api/knowledge.go similarity index 96% rename from server/api/knowledge.go rename to rag-server/api/knowledge.go index ef8ed3f..42ed685 100644 --- a/server/api/knowledge.go +++ b/rag-server/api/knowledge.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5" rsync "xcontrol/internal/rag/sync" - "xcontrol/server/proxy" + "xcontrol/rag-server/proxy" ) // registerKnowledgeRoutes sets up knowledge base endpoints. diff --git a/server/api/nodes.go b/rag-server/api/nodes.go similarity index 91% rename from server/api/nodes.go rename to rag-server/api/nodes.go index 0e04182..0ed65f3 100644 --- a/server/api/nodes.go +++ b/rag-server/api/nodes.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "xcontrol/server/internal/service" + "xcontrol/rag-server/internal/service" ) // registerNodeRoutes sets up node related endpoints. diff --git a/server/api/rag.go b/rag-server/api/rag.go similarity index 98% rename from server/api/rag.go rename to rag-server/api/rag.go index 968fa21..9ca86cd 100644 --- a/server/api/rag.go +++ b/rag-server/api/rag.go @@ -12,7 +12,7 @@ import ( rconfig "xcontrol/internal/rag/config" ragembed "xcontrol/internal/rag/embed" "xcontrol/internal/rag/store" - "xcontrol/server/proxy" + "xcontrol/rag-server/proxy" ) // ragService defines methods used by the RAG API. It allows tests to supply a diff --git a/server/api/rag_test.go b/rag-server/api/rag_test.go similarity index 100% rename from server/api/rag_test.go rename to rag-server/api/rag_test.go diff --git a/server/api/register.go b/rag-server/api/register.go similarity index 95% rename from server/api/register.go rename to rag-server/api/register.go index b4babf4..fd263a5 100644 --- a/server/api/register.go +++ b/rag-server/api/register.go @@ -3,7 +3,7 @@ package api import ( "github.com/gin-gonic/gin" "github.com/jackc/pgx/v5" - "xcontrol/server" + "xcontrol/rag-server" ) // RegisterRoutes returns a server.Registrar that registers all API routes. diff --git a/server/api/users.go b/rag-server/api/users.go similarity index 91% rename from server/api/users.go rename to rag-server/api/users.go index 791f92e..8d74fb4 100644 --- a/server/api/users.go +++ b/rag-server/api/users.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "xcontrol/server/internal/service" + "xcontrol/rag-server/internal/service" ) // registerUserRoutes sets up user related endpoints. diff --git a/server/cmd/agent/main.go b/rag-server/cmd/agent/main.go similarity index 50% rename from server/cmd/agent/main.go rename to rag-server/cmd/agent/main.go index 60d102e..760c417 100644 --- a/server/cmd/agent/main.go +++ b/rag-server/cmd/agent/main.go @@ -1,6 +1,6 @@ package main -import "xcontrol/server/internal/agent" +import "xcontrol/rag-server/internal/agent" func main() { agent.Run() diff --git a/client/Makefile b/rag-server/cmd/rag-server-cli/Makefile similarity index 100% rename from client/Makefile rename to rag-server/cmd/rag-server-cli/Makefile diff --git a/client/main.go b/rag-server/cmd/rag-server-cli/main.go similarity index 99% rename from client/main.go rename to rag-server/cmd/rag-server-cli/main.go index f5ffd55..9728213 100644 --- a/client/main.go +++ b/rag-server/cmd/rag-server-cli/main.go @@ -20,7 +20,7 @@ import ( "xcontrol/internal/rag/ingest" "xcontrol/internal/rag/store" rsync "xcontrol/internal/rag/sync" - "xcontrol/server/proxy" + "xcontrol/rag-server/proxy" ) // main synchronizes configured repositories and ingests markdown files. diff --git a/server/config/config.go b/rag-server/config/config.go similarity index 97% rename from server/config/config.go rename to rag-server/config/config.go index 4232112..d9a898f 100644 --- a/server/config/config.go +++ b/rag-server/config/config.go @@ -175,9 +175,9 @@ type Config struct { } // Load reads the configuration file at the provided path. When path is empty, -// it defaults to server/config/server.yaml. +// it defaults to rag-server/config/server.yaml. func Load(path ...string) (*Config, error) { - p := filepath.Join("server", "config", "server.yaml") + p := filepath.Join("rag-server", "config", "server.yaml") if len(path) > 0 && path[0] != "" { p = path[0] } diff --git a/server/config/config_test.go b/rag-server/config/config_test.go similarity index 95% rename from server/config/config_test.go rename to rag-server/config/config_test.go index 02ad081..0c2b057 100644 --- a/server/config/config_test.go +++ b/rag-server/config/config_test.go @@ -13,7 +13,7 @@ func TestLoad(t *testing.T) { if err != nil { t.Fatalf("getwd: %v", err) } - // change to repository root so Load can read server/config/server.yaml + // change to repository root so Load can read rag-server/config/server.yaml if err := os.Chdir("../.."); err != nil { t.Fatalf("chdir: %v", err) } diff --git a/server/config/server-chutes-ai.yaml b/rag-server/config/server-chutes-ai.yaml similarity index 100% rename from server/config/server-chutes-ai.yaml rename to rag-server/config/server-chutes-ai.yaml diff --git a/server/config/server-chutes-qwen-ai.yaml b/rag-server/config/server-chutes-qwen-ai.yaml similarity index 100% rename from server/config/server-chutes-qwen-ai.yaml rename to rag-server/config/server-chutes-qwen-ai.yaml diff --git a/server/config/server-ollama-ai.yaml b/rag-server/config/server-ollama-ai.yaml similarity index 100% rename from server/config/server-ollama-ai.yaml rename to rag-server/config/server-ollama-ai.yaml diff --git a/server/config/server.yaml b/rag-server/config/server.yaml similarity index 100% rename from server/config/server.yaml rename to rag-server/config/server.yaml diff --git a/server/cors.go b/rag-server/cors.go similarity index 99% rename from server/cors.go rename to rag-server/cors.go index e2261d0..a2dc828 100644 --- a/server/cors.go +++ b/rag-server/cors.go @@ -12,7 +12,7 @@ import ( "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" - "xcontrol/server/config" + "xcontrol/rag-server/config" ) // UseCORS applies a restrictive CORS policy to the provided gin engine based on the diff --git a/server/internal/agent/agent.go b/rag-server/internal/agent/agent.go similarity index 100% rename from server/internal/agent/agent.go rename to rag-server/internal/agent/agent.go diff --git a/server/internal/model/admin_setting.go b/rag-server/internal/model/admin_setting.go similarity index 100% rename from server/internal/model/admin_setting.go rename to rag-server/internal/model/admin_setting.go diff --git a/server/internal/model/models.go b/rag-server/internal/model/models.go similarity index 100% rename from server/internal/model/models.go rename to rag-server/internal/model/models.go diff --git a/server/internal/service/admin_settings.go b/rag-server/internal/service/admin_settings.go similarity index 98% rename from server/internal/service/admin_settings.go rename to rag-server/internal/service/admin_settings.go index 9e00b51..5577b61 100644 --- a/server/internal/service/admin_settings.go +++ b/rag-server/internal/service/admin_settings.go @@ -7,7 +7,7 @@ import ( "gorm.io/gorm" - "xcontrol/server/internal/model" + "xcontrol/rag-server/internal/model" ) // ErrServiceDBNotInitialized indicates the service database has not been configured. diff --git a/server/internal/service/node.go b/rag-server/internal/service/node.go similarity index 85% rename from server/internal/service/node.go rename to rag-server/internal/service/node.go index b42ffc6..50e1cd5 100644 --- a/server/internal/service/node.go +++ b/rag-server/internal/service/node.go @@ -3,7 +3,7 @@ package service import ( "context" - "xcontrol/server/internal/model" + "xcontrol/rag-server/internal/model" ) func ListNodes(ctx context.Context) ([]model.Node, error) { diff --git a/server/internal/service/user.go b/rag-server/internal/service/user.go similarity index 88% rename from server/internal/service/user.go rename to rag-server/internal/service/user.go index d140706..196e4b4 100644 --- a/server/internal/service/user.go +++ b/rag-server/internal/service/user.go @@ -4,7 +4,7 @@ import ( "context" "gorm.io/gorm" - "xcontrol/server/internal/model" + "xcontrol/rag-server/internal/model" ) var db *gorm.DB diff --git a/server/internal/stats/stats.go b/rag-server/internal/stats/stats.go similarity index 100% rename from server/internal/stats/stats.go rename to rag-server/internal/stats/stats.go diff --git a/server/internal/stats/stats_test.go b/rag-server/internal/stats/stats_test.go similarity index 100% rename from server/internal/stats/stats_test.go rename to rag-server/internal/stats/stats_test.go diff --git a/server/internal/subscription/subscription.go b/rag-server/internal/subscription/subscription.go similarity index 100% rename from server/internal/subscription/subscription.go rename to rag-server/internal/subscription/subscription.go diff --git a/server/internal/xray/xray.go b/rag-server/internal/xray/xray.go similarity index 100% rename from server/internal/xray/xray.go rename to rag-server/internal/xray/xray.go diff --git a/server/migrations/0001_create_admin_settings.sql b/rag-server/migrations/0001_create_admin_settings.sql similarity index 100% rename from server/migrations/0001_create_admin_settings.sql rename to rag-server/migrations/0001_create_admin_settings.sql diff --git a/server/proxy/proxy.go b/rag-server/proxy/proxy.go similarity index 100% rename from server/proxy/proxy.go rename to rag-server/proxy/proxy.go diff --git a/server/server.go b/rag-server/server.go similarity index 100% rename from server/server.go rename to rag-server/server.go diff --git a/docs/init.sql b/rag-server/sql/schema.sql similarity index 100% rename from docs/init.sql rename to rag-server/sql/schema.sql