{"uid":"cap_dIVCUj_eVjnd2dEc-P9HL","slug":"402utils-rerank-passages-by-relevance-43a8002a","name":"402utils Rerank Passages by Relevance","description":"Rerank passages by relevance to a query via Cloudflare Workers AI (@cf/baai/bge-reranker-base). Send {query, documents[] (≤50, each ≤4000 chars), topK?}; returns [{index, score}] best-first — the missing link after embed/chunk, keeping the top chunks before a costly LLM call. Score is the model's relevance score (higher = better), named as it only compares within this model. Unavailable binding → 503, unbilled.","url":"https://402utils.com/v1/rerank","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"topK":{"type":"integer","minimum":1,"description":"Return only the K best (default: all, ranked)."},"query":{"type":"string","description":"The search query (≤ 4000 chars)."},"documents":{"type":"array","items":{"type":"string"},"maxItems":50,"description":"Candidate passages to rank (≤ 50, each ≤ 4000 chars)."},"returnDocuments":{"type":"boolean","default":false,"description":"Include each ranked document's text in the results."}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.004","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.004/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_bW3pv41XYwpYedJZ-PwB6","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.004","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Reranks a list of text passages by relevance to a query using Cloudflare Workers AI BGE-Reranker, returning passages sorted best-first with relevance scores","exampleAgentPrompt":"I have these 20 passage chunks retrieved from my vector store for the query 'how does photosynthesis work' — can you rerank them by relevance and give me just the top 5 so I only send the best ones to the LLM?","exampleUseCases":null,"resultDescription":"Returns a JSON array of objects sorted best-first, each containing the original document index and a relevance score (higher = more relevant to the query). If returnDocuments is true, each object also includes the passage text. Only scores within this model are comparable to each other.","failureModes":["503 Unavailable — Cloudflare Workers AI binding not available; unbilled","Documents array exceeds 50 items — request rejected","Individual document exceeds 4000 characters — request rejected","Query exceeds 4000 characters — request rejected","topK greater than number of documents — likely returns all documents ranked","Malformed request body — validation error response"],"whenToPreferThis":"Use this endpoint as the crucial middle step in a RAG pipeline between your vector/embedding retrieval and your LLM call: after fetching many candidate chunks, rerank them to keep only the most relevant before paying for LLM tokens. Prefer this over embedding-only similarity when precision matters — cross-encoder rerankers like BGE-Reranker are significantly more accurate than cosine similarity on embeddings. Best for up to 50 passages, each up to 4000 characters.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T06:41:59.110Z","isFirstParty":false}