Documentation
¶
Overview ¶
Package httpembedder is an embedding.Embedder for a provider that serves the OpenAI-shaped embeddings request over HTTP, such as semembed. It is the tier 1 embedder: a product that runs such a provider passes an *Embedder to graph-embedding.
It sends one request per call and trusts only a whole reply: one non-empty vector per text, each placed by its index, all of the width the first accepted reply had, from the configured model. Any other reply is an error with no vectors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// BaseURL is the provider's API root; requests go to BaseURL + "/embeddings". For semembed
// it ends in /v1, for example "http://127.0.0.1:8081/v1". Required; http or https.
BaseURL string
// Model is the model name sent with every request. A reply naming another model is refused.
// Required.
Model string
// APIKey, when set, is sent as "Authorization: Bearer <APIKey>". A local provider needs none,
// and then no Authorization header is sent.
APIKey string
// QueryPrefix is prepended to each text GenerateQuery embeds, never to documents. Set it to
// the model's query instruction for an asymmetric model, such as "Represent this sentence for
// searching relevant passages: " for Snowflake arctic-embed. Empty sends queries raw.
QueryPrefix string
}
Config configures an Embedder.
type Embedder ¶
type Embedder struct {
// contains filtered or unexported fields
}
Embedder calls an embedding provider over HTTP. It is safe for concurrent use. The caller's context bounds each request; the Embedder sets no timeout of its own.
func New ¶
New returns an Embedder for cfg. It refuses an empty base URL or model, and a base URL that is not an absolute http or https URL with a host. It makes no request: the width is learned from the first reply, so a provider that is down at start degrades graph-embedding rather than failing it.
func (*Embedder) Close ¶
Close returns nil: requests go through the shared default transport, which holds nothing for one Embedder.
func (*Embedder) Dimensions ¶
Dimensions returns the width of the first accepted reply, or 0 before one.
func (*Embedder) Generate ¶
Generate embeds documents: one vector per text, in the texts' order. No texts sends no request.
func (*Embedder) GenerateQuery ¶
GenerateQuery embeds search queries, each with the configured query prefix in front. With no prefix it sends the same request Generate does.