Choosing Embedding and Rerank APIs for RAG
A practical guide to selecting embedding and rerank APIs for RAG, semantic search, and knowledge-base Q&A: capability boundaries, hosted vs. self-hosted cost, Chinese token budgets, engineering constraints, evaluation, and operations.
In retrieval-augmented generation (RAG), semantic search, and knowledge-base Q&A, embeddings map documents and queries into a shared vector space, while reranking reorders candidates after initial recall. Both are commonly offered as hosted APIs or as open-weight models you deploy yourself. Selection should not stop at “is there a free quota.” Check input modalities, billing granularity, rate limits, data terms, and real token use after Chinese chunking.
Capability boundaries: what embeddings and rerankers actually do
An embedding model encodes text—and, for some services, images, audio, video, or document pages—into a fixed-length vector for approximate nearest-neighbor search. Dimension, whether vectors are normalized, and support for asymmetric query encoding all affect index layout and recall quality.
A reranker typically takes a query plus several candidate passages, returns relevance scores, and reorders them to cut noise and improve precision at K. A common pipeline is coarse retrieval (vectors or keywords) → take Top-N → rerank → pass results to a generator.
Documents and queries must use the same embedding model. When you change models, rebuild a separate index and keep the old one. Even if dimensions match, you cannot mix vector spaces; similarities are not comparable.
Hosted APIs vs. self-hosted weights: different cost structures
Open weights can be self-hosted, but compute, operations, and peak bandwidth are not free. Hosted free tiers are not unlimited: they are usually settled by account daily or monthly quotas, rate limits, or shared compute units, and can change. A personal prototype that “looks sufficient” must be judged against corpus size, query QPS, retries, and rebuilds—not marketing copy as capacity.
For sensitive corpora, read data terms first. Some free tiers may use inputs to improve models. When you use your own keys on a billed path, promotional credits may not apply. Online inference and batch offline indexing are often priced separately; do not mix those numbers.
How quotas work: is a Chinese knowledge base “enough”?
Billing usually accumulates input tokens (or equivalent compute units). Chinese character count is not token count. Chunk overlap, metadata concatenation, and query rewriting inflate input. Use a budget example as a self-check, not as a performance benchmark.
Example: first-time indexing of 10,000 chunks at about 500 tokens each, plus 1,000 queries that day at about 50 tokens each, is roughly 5.05 million input tokens. Convert using the vendor’s published “compute units per million tokens” and compare with the daily shared quota. This omits retries, multi-model parallelism, full rebuilds, and overlapping slices. Daily quotas often reset on a fixed timezone; throughput and rate limits need a separate look at the documentation.
If quota is tight, reduce overlap, control chunk length, use offline batch indexing, and cache and deduplicate on the query path.
Selection checklist: APIs and engineering constraints
- Modality: Text-only vs. image/PDF page-level encoding determines whether you need OCR and layout analysis first.
- Language and domain: General multilingual models are often usable for Chinese knowledge bases, but proper nouns and legal clauses still need evaluation on real questions.
- Dimension and index: A dimension change requires a new index. HNSW/IVF parameters vs. recall and latency need their own load tests.
- Rate limits and consistency: Free evaluation keys are often limited by rate and monthly calls—fine for prototypes, not production peaks.
- Rerank integration: Confirm max candidates, timeouts, and whether scores can be calibrated. On rerank failure, degrade to vector scores only.
- Security and compliance: Log retention, cross-border transfer, deletion rights, and “used for training or not” belong on the review sheet.
Evaluation: use your own questions, not leaderboard scores
Start with about 20 human-labeled real questions and check whether the top 5 hits contain answerable evidence. Use the same embedding for documents and queries. When changing models, compare hit rate, MRR, or nDCG on old vs. new indexes—not vector norms alone.
Chunking (fixed length, by heading/paragraph, semantic split) has a large effect on Chinese: too short loses context; too long dilutes keywords. Freeze split and overlap ratios before swapping models so variables do not confound. Evaluate rerank on a fixed first-stage candidate set, or you cannot separate recall from ranking.
Migration and operations
Changes to request fields (text arrays, truncation, task types such as retrieval.query / retrieval.document) can shift vector distributions. On migration, retain model IDs, chunking-script versions, the normalization flag, and index snapshots. Monitor latency percentiles, error codes, token use, and remaining daily quota.
Containers, object storage, logs, and alerting are enough for a gray rollout: write a new index in parallel, shift read traffic gradually, and retire the old index only after quality is confirmed.
Connecting to cloud retrieval stacks
In enterprise setups, embedding and rerank are standard retrieval-path capabilities, combined with original documents in object storage, incremental chunk jobs on a message queue, and call audit in logging. If you use model APIs and vector search on a cloud such as Baidu AI Cloud, the same engineering rules apply: unified model versions, isolated indexes, visible quotas and rate limits, and regression on a business question set—not dependence on a promotional free-quota number.
Takeaway
Embedding and rerank APIs turn semantic matching into a swappable component. Free tiers are for validating chunking and the evaluation loop. Before production, write down token budget, data terms, vector-space isolation, and fallback. Estimating one full index plus one day of queries, then checking top-5 recall on twenty real questions, reduces launch risk more than listing vendor names.
