Reranker
Example Code: examples/knowledge/reranker
Reranker reorders retrieved candidates to improve relevance. It can work with any vector store and is injected via knowledge.WithReranker.
Supported Rerankers
TopK (simple truncation)
The most basic reranker that returns the top K results based on retrieval scores.
| Option | Description | Required |
|---|---|---|
WithK(int) |
Number of results to return, default -1 (return all) |
No |
Cohere (SaaS rerank)
Use Cohere's rerank service.
| Option | Description | Required |
|---|---|---|
WithAPIKey(string) |
Cohere API Key | Yes |
WithModel(string) |
Model name, default rerank-english-v3.0 |
No |
WithTopN(int) |
Number of results to return | No |
WithEndpoint(string) |
Custom endpoint URL | No |
WithHTTPClient(*http.Client) |
Custom HTTP client | No |
Infinity / TEI (standard rerank API)
Terminology
- Infinity: Open-source high-performance inference engine supporting multiple Reranker models
- TEI (Text Embeddings Inference): Official Hugging Face inference engine optimized for Embeddings and Reranking
The Infinity Reranker implementation in trpc-agent-go can connect to any service compatible with the standard Rerank API, including self-hosted services using Infinity/TEI, Hugging Face Inference Endpoints, etc.
Usage
| Option | Description | Required |
|---|---|---|
WithEndpoint(string) |
Service endpoint URL | Yes |
WithModel(string) |
Model name | No |
WithTopN(int) |
Number of results to return, default -1 (return all) |
No |
WithAPIKey(string) |
API key for authenticated services | No |
WithHTTPClient(*http.Client) |
Custom HTTP client | No |
For detailed deployment methods and examples, see the examples/knowledge/reranker/infinity/ directory.
Inject into Knowledge
Notes
- Cohere requires a valid API key.
- Infinity/TEI requires a reachable endpoint and a loaded model;
WithModelis optional but should match the service model when set. - TopK has no external dependencies and suits offline or constrained environments.