httpembedder

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 0

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

func New(cfg Config) (*Embedder, error)

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

func (e *Embedder) Close() error

Close returns nil: requests go through the shared default transport, which holds nothing for one Embedder.

func (*Embedder) Dimensions

func (e *Embedder) Dimensions() int

Dimensions returns the width of the first accepted reply, or 0 before one.

func (*Embedder) Generate

func (e *Embedder) Generate(ctx context.Context, texts []string) ([][]float32, error)

Generate embeds documents: one vector per text, in the texts' order. No texts sends no request.

func (*Embedder) GenerateQuery

func (e *Embedder) GenerateQuery(ctx context.Context, texts []string) ([][]float32, error)

GenerateQuery embeds search queries, each with the configured query prefix in front. With no prefix it sends the same request Generate does.

func (*Embedder) Model

func (e *Embedder) Model() string

Model returns the configured model name.

Jump to

Keyboard shortcuts

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