Merge pull request #109 from svc-design/codex/refactor-project-code-structure
refactor: reorganize rag modules
This commit is contained in:
commit
f78dd07c2d
10
.github/workflows/build-and-release.yml
vendored
10
.github/workflows/build-and-release.yml
vendored
@ -21,13 +21,13 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p build
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/xcontrol-api-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/api
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/xcontrol-cli-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/cli
|
||||
- name: Upload API artifact
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/xcontrol-server-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/xcontrol-server
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/xcontrol-cli-${{ matrix.goos }}-${{ matrix.goarch }} ./client
|
||||
- name: Upload server artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: xcontrol-api-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: build/xcontrol-api-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
name: xcontrol-server-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: build/xcontrol-server-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
- name: Upload CLI artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
2
.github/workflows/deploy-xcontrol-server.yml
vendored
2
.github/workflows/deploy-xcontrol-server.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
go-version: '1.21'
|
||||
|
||||
- name: 🏗️ Build server
|
||||
run: go build ./cmd/api
|
||||
run: go build ./cmd/xcontrol-server
|
||||
|
||||
- name: 🚀 Deploy server
|
||||
run: |
|
||||
|
||||
2
Makefile
2
Makefile
@ -63,7 +63,7 @@ init-db:
|
||||
build: build-cli build-server build-homepage build-panel
|
||||
|
||||
build-cli:
|
||||
$(MAKE) -C cmd/cli build
|
||||
$(MAKE) -C client build
|
||||
|
||||
build-server:
|
||||
$(MAKE) -C server build
|
||||
|
||||
@ -12,12 +12,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
rconfig "xcontrol/internal/rag/config"
|
||||
"xcontrol/internal/rag/embed"
|
||||
"xcontrol/internal/rag/ingest"
|
||||
"xcontrol/internal/rag/store"
|
||||
rsync "xcontrol/internal/rag/sync"
|
||||
"xcontrol/server/proxy"
|
||||
rconfig "xcontrol/server/rag/config"
|
||||
"xcontrol/server/rag/embed"
|
||||
"xcontrol/server/rag/ingest"
|
||||
"xcontrol/server/rag/store"
|
||||
rsync "xcontrol/server/rag/sync"
|
||||
)
|
||||
|
||||
// main loads server RAG configuration and triggers a manual sync by
|
||||
@ -6,9 +6,9 @@ import (
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
cfgpkg "xcontrol/internal/rag/config"
|
||||
"xcontrol/internal/rag/ingest"
|
||||
"xcontrol/server/proxy"
|
||||
cfgpkg "xcontrol/server/rag/config"
|
||||
"xcontrol/server/rag/ingest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@ -78,7 +78,7 @@ func Embed(text string) ([]float32, error) { /* 调用 Embedding 模型 */ }
|
||||
## 5. 项目代码规划
|
||||
|
||||
```
|
||||
server/rag/
|
||||
internal/rag/
|
||||
├── sync/ # Git 克隆/更新
|
||||
├── ingest/ # 文档转换与分块
|
||||
├── embed/ # 向量化
|
||||
|
||||
@ -64,7 +64,7 @@
|
||||
## 6. Go 代码模块划分
|
||||
|
||||
```
|
||||
server/rag/
|
||||
internal/rag/
|
||||
├── config/ # 仓库与模型配置
|
||||
├── sync/ # GitHub 同步逻辑
|
||||
├── ingest/ # Markdown 解析与分块
|
||||
|
||||
@ -4,7 +4,7 @@ WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /xcontrol ./cmd/api
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /xcontrol ./cmd/xcontrol-server
|
||||
|
||||
FROM gcr.io/distroless/base-debian12
|
||||
WORKDIR /
|
||||
@ -3,7 +3,7 @@ package ingest
|
||||
import (
|
||||
"strings"
|
||||
|
||||
cfgpkg "xcontrol/server/rag/config"
|
||||
cfgpkg "xcontrol/internal/rag/config"
|
||||
)
|
||||
|
||||
// Chunk represents a piece of text prepared for embedding.
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
cfgpkg "xcontrol/server/rag/config"
|
||||
cfgpkg "xcontrol/internal/rag/config"
|
||||
)
|
||||
|
||||
func TestBuildChunksHeading(t *testing.T) {
|
||||
@ -8,10 +8,10 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
cfgpkg "xcontrol/server/rag/config"
|
||||
"xcontrol/server/rag/embed"
|
||||
"xcontrol/server/rag/store"
|
||||
rsync "xcontrol/server/rag/sync"
|
||||
cfgpkg "xcontrol/internal/rag/config"
|
||||
"xcontrol/internal/rag/embed"
|
||||
"xcontrol/internal/rag/store"
|
||||
rsync "xcontrol/internal/rag/sync"
|
||||
)
|
||||
|
||||
// Options control ingestion behaviour.
|
||||
@ -41,7 +41,7 @@ func IngestRepo(ctx context.Context, cfg *cfgpkg.Config, ds cfgpkg.DataSource, o
|
||||
chunkCfg := cfg.ResolveChunking()
|
||||
embCfg := cfg.ResolveEmbedding()
|
||||
|
||||
workdir := filepath.Join("server", "rag", ds.Name)
|
||||
workdir := filepath.Join("internal", "rag", ds.Name)
|
||||
if _, err := rsync.SyncRepo(ctx, ds.Repo, workdir); err != nil {
|
||||
st.Errors = append(st.Errors, err)
|
||||
return st, err
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
pgvector "github.com/pgvector/pgvector-go"
|
||||
|
||||
"xcontrol/server/rag/config"
|
||||
"xcontrol/server/rag/embed"
|
||||
"xcontrol/server/rag/store"
|
||||
"xcontrol/internal/rag/config"
|
||||
"xcontrol/internal/rag/embed"
|
||||
"xcontrol/internal/rag/store"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
@ -1,5 +1,5 @@
|
||||
APP_NAME := xcontrol-server
|
||||
MAIN_FILE := ../cmd/api/main.go
|
||||
MAIN_FILE := ../cmd/xcontrol-server/main.go
|
||||
MODULE := xcontrol
|
||||
PORT := 8080
|
||||
OS := $(shell uname -s)
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
rsync "xcontrol/server/rag/sync"
|
||||
rsync "xcontrol/internal/rag/sync"
|
||||
)
|
||||
|
||||
// registerKnowledgeRoutes sets up knowledge base endpoints.
|
||||
|
||||
@ -5,10 +5,10 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"xcontrol/internal/rag"
|
||||
rconfig "xcontrol/internal/rag/config"
|
||||
"xcontrol/internal/rag/store"
|
||||
"xcontrol/server/proxy"
|
||||
"xcontrol/server/rag"
|
||||
rconfig "xcontrol/server/rag/config"
|
||||
"xcontrol/server/rag/store"
|
||||
)
|
||||
|
||||
// ragSvc handles RAG document storage and retrieval.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user