Documentation
¶
Overview ¶
Package inference holds the OpenAI-compatible clients: embeddings now, reranking in a later phase.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chat ¶ added in v0.2.0
type Chat struct {
BaseURL string
APIKey string
Model string
MaxTokens int
MaxRetries int
// ExtraBody is merged into every request body (provider-specific knobs
// like chat_template_kwargs).
ExtraBody map[string]any
Client *http.Client
Logger *slog.Logger
}
Chat is a minimal OpenAI-compatible /v1/chat/completions client for index-time work (contextual retrieval). Same failure contract as the embedder: transient errors retry with backoff, everything else propagates.
func (*Chat) Complete ¶ added in v0.2.0
Complete sends one system+user exchange and returns the trimmed response.
func (*Chat) CompleteWithImage ¶ added in v0.3.0
func (c *Chat) CompleteWithImage(ctx context.Context, system, user string, image []byte, mime string) (string, error)
CompleteWithImage sends a user turn carrying an image (OpenAI content-array format with a base64 data URI). The chat model must be vision-capable.
type Embedder ¶
type Embedder struct {
BaseURL string // e.g. http://127.0.0.1:8080/v1
APIKey string
Model string
Dimensions int
BatchSize int
MaxRetries int
Client *http.Client
Logger *slog.Logger
}
Embedder calls an OpenAI-compatible /v1/embeddings endpoint.
Contract, learned the hard way: there is NO fallback vector code path. Every error propagates; callers abort the affected document and the previous index state survives. A dummy-vector fallback once tricked a dimension check into wiping an entire collection.
type Ranked ¶
Ranked is one rerank result. Score is normalized to (0,1) via sigmoid so raw cross-encoder logits stay comparable with min_score filters.
type Reranker ¶
type Reranker struct {
BaseURL string
APIKey string
Model string
Client *http.Client
Logger *slog.Logger
}
Reranker calls an OpenAI-compatible /v1/rerank endpoint (llama-server, Jina, Cohere-compatible shapes). Reranking is an enhancement: callers must degrade gracefully to fusion order when it fails.