cohererank

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cohererank implements the rerank shape Cohere defined and almost every other vendor copied: POST {base}/rerank with {model, query, documents} answering {results: [{index, relevance_score, document}]}. A bare array of the same result objects is accepted too: self-hosted runtimes such as SGLang return that shape instead of the envelope.

Jina, Zhipu, SiliconFlow, Qianfan, GPUStack, WeKnora Cloud and any OpenAI-compatible gateway that serves rerank all speak it. Their differences — which optional fields are accepted, where the endpoint sits, what the documented ceilings are — arrive as api.RerankSettings; this package contains no vendor names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks the Cohere rerank shape to one endpoint.

func New

func New(cfg Config) *Client

New builds a client.

func (*Client) AcceptsImages

func (c *Client) AcceptsImages() bool

AcceptsImages reports whether the vendor names an image field; without one a Cohere-shaped endpoint takes text documents only.

func (*Client) BuildImageRequestBody

func (c *Client) BuildImageRequestBody(query string, images []api.EmbedImage) (map[string]any, error)

BuildImageRequestBody is the golden-test entry point for image documents. The shape has no standard image document; a vendor that extends it names the key of the object that carries one. Jina's reranker reference gives {"image": URL or base64} documents; it shows no base64 example, so the data URI its embeddings reference documents is used (unverified for rerank). The request carries images only, so text documents never change shape.

func (*Client) BuildRequestBody

func (c *Client) BuildRequestBody(query string, documents []string) (map[string]any, error)

BuildRequestBody is the golden-test entry point: it returns the exact JSON object that would be sent.

func (*Client) Rerank

func (c *Client) Rerank(ctx context.Context, query string, documents []string) ([]api.RerankResult, error)

Rerank scores documents against the query, in the order they were given.

func (*Client) RerankImages

func (c *Client) RerankImages(ctx context.Context, query string, images []api.EmbedImage) ([]api.RerankResult, error)

RerankImages scores image documents against the query; indices refer to images.

type Config

type Config struct {
	Endpoint api.Endpoint
	Settings api.RerankSettings
}

Config is everything the client needs, already resolved by the api.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL