中文 | English
Retrieval-Augmented Generation system for documents, built in Go with a Connect/gRPC API and a Next.js (Bun) frontend.
- Document pipeline: Presigned upload → PDF text extraction (Doc2X) → semantic chunking → embeddings → pgvector storage
- Hybrid retrieval: Vector search + keyword-aware rerank, then LLM summarization
- Clients: Connect/gRPC; generated Go/TypeScript stubs; Bun/Next.js demo UI with virtual scrolling
- Infra: PostgreSQL + pgvector, Redis cache, MinIO object storage
- Ops:
just genfor proto codegen via Docker,just web-*for frontend tasks
The system follows a modular architecture with clean separation of concerns:
cmd/server/ # Application entry point
internal/
├── adapters/ # Database adapters (PostgreSQL)
├── clients/ # External service clients
│ ├── base/ # Shared HTTP client utilities
│ ├── doc2x/ # Document parsing service
│ ├── embedding/ # Embedding generation
│ ├── openai/ # LLM integration
│ └── rerank/ # Document reranking
├── config/ # Configuration management
├── logger/ # Structured logging
├── redis/ # Cache layer
├── server/ # HTTP server and handlers
└── storage/ # File storage (MinIO)
- Go 1.21+ (recommended)
- PostgreSQL with pgvector
- Redis
- MinIO (or S3-compatible) for object storage
- Docker (for
just gencodegen) and Bun (for the Next.js frontend)
- Clone & Go deps
git clone https://github.com/hsn0918/rag.git
cd rag
go mod download-
Configure: copy
config.example.yamltoconfig.yamland fill in DB/Redis/MinIO/API keys. -
Generate code (requires Docker):
just gen- Run server:
go run cmd/server/main.go- Frontend (Bun + Next.js):
cd web
bun install
bun run devUse config.yaml (see config.example.yaml) or env vars:
server: host/portdatabase: PostgreSQL + pgvector DSN partsredis: host/port/authminio: endpoint/access keys/bucketservices: Doc2X, Embedding, Reranker, LLM endpoints + models/API keyschunking: chunk sizes/overlap/semantic options
Service: rag.v1.RagService
POST /rag.v1.RagService/PreUpload— presigned upload URLPOST /rag.v1.RagService/UploadPdf— process & index PDFPOST /rag.v1.RagService/GetContext— full RAG pipeline (keywords → embedding → search → rerank → summarize)POST /rag.v1.RagService/ListDocuments— cursor-paginated doc listPOST /rag.v1.RagService/DeleteDocument— delete doc and chunks
See api/rag/v1/rag.proto for message shapes; generated clients in internal/gen (Go) and web/gen (TS).
just gen— buf codegen (via Docker), fixes TS import extensionsjust web-install|web-dev|web-build|web-start|web-lint— frontend tasks (Bun)go run cmd/server/main.go— start backend
- Uses generated Connect TS client; proxy to backend via
web/next.config.mjs(/api -> BACKEND_URL). - Includes upload flow, RAG query, document list (cursor pagination, delete), keyword D3 visualization, and structured answer rendering.
-
For codegen, Docker access is required (bufbuild/buf container).
-
For embedding/rerank/LLM services, update API keys and models in
config.yaml. -
Ensure pgvector extension exists in Postgres and the DSN matches your config.
-
Database:
github.com/jackc/pgx/v5for PostgreSQL -
Vector Search:
github.com/pgvector/pgvector-gofor embeddings -
Cache:
github.com/redis/rueidisfor Redis -
Storage:
github.com/minio/minio-go/v7for object storage -
HTTP Client:
github.com/go-resty/resty/v2for external APIs -
Dependency Injection:
go.uber.org/fxfor application structure -
Logging:
log/slogfor structured logging
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the terms specified in the repository.