生产级 RAG API 集成在 Rust 中。采用 HNSW 稠密向量和 BM25 稀疏匹配的混合搜索、交叉编码器重排、基于布局的文档提取等技术。
生产级 RAG API 集成在 Rust 中。采用 HNSW 稠密向量和 BM25 稀疏匹配的混合搜索、交叉编码器重排、基于布局的文档提取等技术。
Benchmarked on 3,045 questions from Open RAG Bench (academic papers, 1,000 PDFs, 57,347 chunks). LLM-as-judge evaluation using qwen-3-235b. Infrastructure running on VastAI RTX 4090 (USA region).
… Time to First Token (TTFT)
──────────────────────────────────────────────────────────
With Reranker ████████████████████████████ 279ms
Without Reranker ████████████████████ 181ms
Total Response Time
──────────────────────────────────────────────────────────
With Reranker ████████████████████████████████████████████████████████████ 883ms
Without Reranker ██████████████████████████████████████ 511ms| Metric | With Reranker | Without Reranker |
|---|---|---|
| Pass rate | 94.5% | 91.6% |
| Avg TTFT | 279ms | 181ms |
| Avg total response | 883ms | 511ms |
| Failed | 167 / 3,024 | 253 / 3,020 |
| LLM | Cerebras qwen-3-235b |
Cerebras qwen-3-235b |
| Embeddings | Jina v5 nano (768-dim) | Jina v5 nano (768-dim) |
| Search | Hybrid HNSW + BM25 + RRF | Hybrid HNSW + BM25 + RRF |
| Reranker | Jina Reranker v3 | Disabled |
| Retrieval | 20 → top 3 after reranking | Top 3 from Milvus |
| Infra | VastAI RTX 4090 (USA) | VastAI RTX 4090 (USA) |
Reranking adds ~100ms TTFT and ~370ms total but improves accuracy by +2.9 percentage points and cuts failures by 34%. Without reranking, you get sub-200ms TTFT — choose your tradeoff.
RustyRAG is built for scenarios where both speed and accuracy matter:
If your RAG pipeline adds 2-3 seconds of latency, users won't use it. RustyRAG keeps the full pipeline — retrieval, reranking, and generation — under 1 second.
… File (.pdf, .docx, .pptx, .xlsx, .html, .txt, .zip)
│
├─ 1. Extract ──────────────────► Docling (layout-aware, tables, OCR)
│
├─ 2. Describe images ──────────► Groq Llama 4 Scout (vision, 17B)
│
├─ 3. Chunk ────────────────────► Sentence-boundary-aware splitting
│
├─ 4. Contextual prefix (opt-in) ► LLM generates 1-2 sentence context
│
├─ 5. Embed ────────────────────► Jina v5 nano (768-dim vectors)
│
└─ 6. Insert ───────────────────► Milvus (dense HNSW + BM25 index)Hybrid search retrieves 20 candidates using two complementary signals — dense vectors (semantic meaning) and BM25 (exact keyword matching). But vector similarity and keyword overlap are rough proxies. The cross-encoder reranker reads each candidate alongside the query as a single sequence and produces a precise relevance score. This promotes the most relevant chunks and demotes false positives, improving answer quality by +2.9% without increasing LLM context size.
git clone https://github.com/AlphaCorp-AI/RustyRAG
cd rustyrag
cp .env.example .envEdit .env with your API keys:
GROQ_API_KEY=gsk_your-groq-key-here
CEREBRAS_API_KEY=csk_your-cerebras-key-heredocker compose up -dThis starts Docling (document extraction), Jina embeddings (TEI), cross-encoder reranker (TEI), and Milvus 2.5 locally.
cargo build --release
cargo run --releaseThe server starts at http://127.0.0.1:8080.
Upload a PDF, ask a question, and watch tokens stream back with source citations.
| Format | Extension | Extraction Method |
|---|---|---|
| Plain text | .txt |
Direct UTF-8 read |
.pdf |
Docling (layout-aware, tables, OCR) | |
| Word | .docx |
Docling |
| PowerPoint | .pptx |
Docling |
| Excel | .xlsx |
Docling |
| HTML | .html |
Docling |
| ZIP archive | .zip |
Unpacked, each entry processed individually |
Docling provides:
All endpoints live under /api/v1. Interactive docs at /swagger-ui/.
| Method | Endpoint | Description |
|---|---|---|
POST |
/documents/upload |
Upload files — extract, chunk, embed, store in Milvus |
POST |
/documents/search |
Semantic search across embedded documents |
GET |
/documents/backup |
Download full collection as gzip-compressed JSON |
| Method | Endpoint | Description |
|---|---|---|
GET |
/llms |
List supported models with provider names |
POST |
/chat-rag |
RAG: hybrid search, rerank, generate answer |
POST |
/chat-rag/stream |
SSE-streamed RAG (sources event + LLM tokens + timing) |
| Method | Endpoint | Description |
|---|---|---|
POST |
/evals/run |
Run evaluation benchmark (3,045 questions) and download results as JSON |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Liveness check |
Every search hit and RAG source returns:
| Field | Type | Description |
|---|---|---|
id |
i64 | Milvus document ID |
file_name |
string | Original uploaded filename |
file_size |
i64 | File size in bytes |
chunk_index |
i64 | Position of chunk within the file |
page_number |
i64 | Page the chunk came from (0 if unknown) |
score |
f32 | Relevance score (from reranker or cosine similarity) |
text |
string | Chunk content |
RustyRAG uses Groq and Cerebras for their low-latency inference hardware. Both expose OpenAI-compatible APIs.
llama-3.1-8b-instantllama-3.3-70b-versatileopenai/gpt-oss-120bopenai/gpt-oss-20bllama3.1-8bgpt-oss-120bqwen-3-235b-a22b-instruct-2507zai-glm-4.7meta-llama/llama-4-scout-17b-16e-instruct (Groq) — describes images found inside documents| Variable | Description |
|---|---|
HOST |
Server bind address |
PORT |
Server port |
GROQ_API_KEY |
Groq API key (also used for vision model) |
CEREBRAS_API_KEY |
Cerebras API key |
| Variable | Default | Description |
|---|---|---|
MILVUS_URL |
http://localhost:19530 |
Milvus REST API |
EMBEDDING_API_URL |
http://localhost:7997/v1/embeddings |
Embedding endpoint |
EMBEDDING_MODEL |
jinaai/jina-embeddings-v5-text-nano-retrieval |
Embedding model |
RERANKER_API_URL |
(empty = disabled) | TEI reranker endpoint |
DOCLING_URL |
http://localhost:5001 |
Docling extraction API |
VISION_MODEL |
meta-llama/llama-4-scout-17b-16e-instruct |
Vision model for images |
| Variable | Default | Description |
|---|---|---|
RETRIEVAL_LIMIT |
20 |
Chunks fetched from Milvus before reranking |
RERANK_TOP_N |
3 |
Chunks kept after reranking |
CHUNK_SIZE |
2000 |
Max characters per chunk |
CHUNK_OVERLAP |
200 |
Overlap between chunks |
EMBEDDING_DIMENSION |
768 |
Vector dimensionality |
CORS_ALLOWED_ORIGINS |
(empty = permissive) | Comma-separated allowed origins |
See .env.example for the full list including Milvus index tuning and contextual retrieval options.
All services run via Docker Compose:
| Service | Image | Port | Role |
|---|---|---|---|
| Embeddings | text-embeddings-inference:cuda-1.9 |
7997 | Jina v5 nano (768-dim) |
| Reranker | text-embeddings-inference:cuda-1.9 |
7998 | Jina Reranker v3 |
| Docling | docling-serve-cu128:v1.14.3 |
5001 | Document extraction (PDF/DOCX/PPTX) |
| Milvus | milvus:v2.5.27 |
19530 | Vector DB (HNSW + BM25) |
GPU is used by embeddings, reranker, and Docling. The Rust server itself runs on CPU only.
…| Layer | Technology | Role |
|---|---|---|
| Runtime | Rust + Tokio + Actix-web 4 | Async web server |
| LLM | Groq (LPU) + Cerebras (wafer-scale) | Low-latency chat completions + SSE streaming |
| Vision | Llama 4 Scout 17B (Groq) | Image descriptions inside documents |
| Embeddings | Jina v5 text nano retrieval (TEI) | Local vectorization, 768-dim |
| Reranker | Jina Reranker v3 (TEI) | Cross-encoder reranking |
| Document extraction | Docling (IBM) | PDF/DOCX/PPTX tables, OCR, layout analysis |
| Vector DB | Milvus 2.5 (HNSW + BM25) | Hybrid dense + sparse search with RRF |
| Chunking | text-splitter crate | Semantic sentence-boundary-aware splitting |
| Docs | utoipa + Swagger UI | Auto-generated interactive API documentation |
| Infra | Docker Compose | One-command local stack |
# Development mode
cargo run
# Debug logging
RUST_LOG=debug cargo run
# Production build
cargo build --r暂无开放 Issues,或尚未同步最近议题。