Build retrieval pipelines with zen-embedding and rerank

Build high-precision semantic search by embedding documents with POST /v1/embeddings (zen-embedding) and re-scoring candidates with POST /v1/rerank.

Vector search gets recall; cross-encoder reranking gets precision. Pair POST /v1/embeddings (zen-embedding) with POST /v1/rerank (zen-reranker) before feeding context into Zen 6 or Kai.

Architecture & contract

Encode documents once and store vectors in /v1/index or /v1/base. At query time, retrieve top-50 candidates by cosine similarity, then score (query, candidate) pairs with POST /v1/rerank to select the top-5 passages.

Primary endpoint: POST /v1/embeddings · Status: shipped · Level: practitioner

Run it across all four surfaces

# Generate embeddings and rerank candidates via CLI
hanzo embeddings create --data '{"model":"zen-embedding","input":["Kai answers bounded questions with 0 output tokens.","Enso routes prompts across tiers."]}'
hanzo rerank create --data '{"model":"zen-reranker","query":"zero output tokens classification","documents":["Kai answers bounded questions with 0 output tokens.","Enso routes prompts across tiers."]}'
const headers = { Authorization: `Bearer ${process.env.HANZO_API_KEY}`, 'Content-Type': 'application/json' };
const emb = await fetch('https://api.hanzo.ai/v1/embeddings', {
  method: 'POST', headers,
  body: JSON.stringify({ model: 'zen-embedding', input: ['Kai answers bounded questions.', 'Enso routes prompts.'] }),
}).then((r) => r.json());

const ranked = await fetch('https://api.hanzo.ai/v1/rerank', {
  method: 'POST', headers,
  body: JSON.stringify({ model: 'zen-reranker', query: 'bounded classification', documents: ['Kai answers bounded questions.', 'Enso routes prompts.'] }),
}).then((r) => r.json());
console.log({ dims: emb.data?.[0]?.embedding?.length, ranked });
import os, requests

h = {"Authorization": f"Bearer {os.environ['HANZO_API_KEY']}"}
emb = requests.post("https://api.hanzo.ai/v1/embeddings", headers=h, json={"model": "zen-embedding", "input": ["Kai answers bounded questions.", "Enso routes prompts."]}).json()
ranked = requests.post("https://api.hanzo.ai/v1/rerank", headers=h, json={"model": "zen-reranker", "query": "bounded classification", "documents": ["Kai answers bounded questions.", "Enso routes prompts."]}).json()
print(len(emb["data"][0]["embedding"]), ranked)
curl -s -X POST https://api.hanzo.ai/v1/embeddings \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"zen-embedding","input":["Kai answers bounded questions with 0 output tokens.","Enso routes prompts across tiers."]}' | jq '.data | length'

curl -s -X POST https://api.hanzo.ai/v1/rerank \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"zen-reranker","query":"zero output tokens classification","documents":["Kai answers bounded questions with 0 output tokens.","Enso routes prompts across tiers."]}' | jq '.'
curl -s -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "search",
      "arguments": {"op": "post_search", "input": {"query": "Kai calibration"}}
    }
  }'

Verify the outcome

  • Assert the top reranked document matches the exact semantic target with a clearly separated relevance score.

Production guardrails

  • Never mix zen-embedding and zen-embedding-3 vectors in the same index — rebuild the index whenever upgrading embedding models.

Next steps & Hanzo University

Was this page useful?
Broken link or missing step? Drop it in #docs on Discord or open a PR.
Last updated Nov 25, 2026