Capabilities & guides
Embeddings & Reranking (RAG Pipeline)
Combine semantic vector recall with second-stage cross-encoder reranking for high-precision enterprise RAG.
Updated 2026-11-26 · 2 min read
Why Production RAG Uses Two-Stage Retrieval
In enterprise knowledge bases, vector similarity alone often surfaces passages that share surface vocabulary without answering the specific question. Combining dense embedding recall with cross-encoder reranking delivers millisecond corpus search alongside high-precision context grounding:
| Stage | Model Category | Representative Models | Role in Pipeline |
|---|---|---|---|
| Offline indexing | Embeddings | Qwen3 Embedding 8B, BGE-M3 | Split documents into 300–800 token chunks and store float vectors |
| Stage 1: Coarse recall | Embeddings + lexical search | Text Embedding V4, Qwen3-VL Embedding | Encode user query and retrieve Top 30–50 candidate chunks |
| Stage 2: Precision rerank | Reranking | Qwen3 Reranker 8B, BGE Reranker v2 M3 | Score query-passage pairs jointly and keep Top 3–5 relevant chunks |
| Stage 3: Grounded answer | Text & chat LLM | DeepSeek V3.2, Qwen4 Max | Synthesize a cited response strictly from the top reranked passages |
Step 1: Generate Semantic Vectors via Embeddings
The /embeddings endpoint accepts either a single string or a batch array of text passages:
emb_response = client.embeddings.create(
model="qwen3-embedding-8b",
input=[
"Instances failing three consecutive health probes are drained automatically.",
"Project API keys support monthly quota caps and IP allowlists.",
],
encoding_format="float",
)
vector_0 = emb_response.data[0].embedding
print("Vector dimension:", len(vector_0))Critical rule: Offline indexing and live query encoding must use the exact same embedding model and vector dimension. Switching from
bge-m3toqwen3-embedding-8brequires re-indexing your vector collection.
Step 2: Refine Candidates with the Rerank Endpoint
Pass the user query and retrieved documents array to /rerank to obtain relevance-ordered indices and scores:
curl --fail-with-body --request POST "${API_BASE_URL}/rerank" --header "Authorization: Bearer ${API_KEY}" --header "Content-Type: application/json" --data '{
"model": "qwen3-reranker-8b",
"query": "How do I prevent healthcheck failures during slow container cold starts?",
"top_n": 3,
"return_documents": true,
"documents": [
"Object storage buckets support cross-region replication policies.",
"Increase initialDelaySeconds for slow cold starts and verify the service binds to 0.0.0.0.",
"Access logs retain status codes and latency histograms for 14 days."
]
}'Chunking and Grounding Best Practices
- Prepend section breadcrumbs: Prefix every chunk with its document title and section heading so pronouns and tables retain context during retrieval.
- Apply a minimum score threshold: When the highest reranker score falls below your confidence floor, return a clear "not found in knowledge base" message instead of feeding irrelevant chunks to the LLM.
- Visually rich documents: Pair Qwen3.5 OCR during ingestion or use multimodal embeddings such as Qwen3-VL Embedding when diagrams carry critical facts.