Documentation
¶
Overview ¶
Package llm holds the local host's LLM client machinery around the public pkg/llm contract: the observing decorator, the timeout decorator, the CallStat/StatsSink recording types, and the embedding plumbing. Provider adapters live in the claude and gollm sub-packages; the factory composes them; the LLM operations themselves live in internal/llmops.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bounded ¶ added in v0.17.0
Bounded decorates a Runner with a per-call deadline. The pkg/llm contract makes bounding a call the instance's duty — the local factory always composes this, so a host that receives its runner gets bounded calls without application knowing the number.
func Observed ¶ added in v0.17.0
Observed decorates a Runner with the local host's observability: one debug-level log line and one CallStat row per call, success or failure. Everything it records travels in the port data — Purpose in the Request, Identity and Usage in the Result, failure attribution in the typed pkg/llm error — so recording is a composition convention, not a framework hook. A nil sink logs but records nothing.
func RecordEmbedCall ¶ added in v0.8.0
RecordEmbedCall logs one embedding batch at debug level and hands its metrics to the StatsSink on ctx (if any). The embedding twin of the Observed decorator's recording: embeddings report input tokens and an item count, never output tokens or a cache breakdown. The caller supplies a fully-populated CallStat.
func WithStatsSink ¶ added in v0.7.1
WithStatsSink returns a context carrying the sink, retrieved by the embedding recording path. Chat calls record through the Observed decorator instead; the context carry remains until embeddings get the same treatment. A nil sink is permitted and makes recording a no-op.
Types ¶
type CallStat ¶ added in v0.7.1
type CallStat struct {
// Purpose names what the call was for. Chat calls carry a pkg/llm Purpose
// constant; embedding calls carry their own op names, which is why the
// field is a plain string.
Purpose string
Identity pkgllm.Identity
Usage pkgllm.Usage
// Items is the number of inputs in this call. The embedding path sets it
// (one batch = N texts) so throughput (items or tokens per second) is
// derivable from DurationMS; chat calls are single-prompt and leave it 0.
Items int
DurationMS int64
// Error is the failure text when the call did not return a result, empty
// on success. Failures are recorded because a call that times out or comes
// back unparseable is exactly what the sink exists to make countable —
// dropping it hides the brittleness it is evidence of. Such a row carries
// no tokens, and provider and model only when the failure happened past
// the point they were known.
Error string
}
CallStat is one LLM call's metrics, handed to a StatsSink for durable collection. The timestamp is added by the sink implementation. The sink owns the wire shape; this is the in-process form.
type Embedder ¶ added in v0.4.0
type Embedder interface {
// EmbedDocuments embeds texts as index-side passages, applying the
// configured DocumentTemplate. Used by the indexer at build /
// lazy-fill time.
EmbedDocuments(ctx context.Context, texts []string) ([][]float32, error)
// EmbedQueries embeds texts as retrieval-side queries, applying the
// configured QueryTemplate. Used by the search finder at query time.
EmbedQueries(ctx context.Context, texts []string) ([][]float32, error)
Dimensions() int
Fingerprint() string
// BatchSize is the per-call input cap the embedder targets. Drivers
// the indexer's outer bucketing so each Embed call corresponds to
// exactly one HTTP round-trip — progress callbacks fire per batch
// instead of "all-at-once at the end" of a giant cross-entry call.
// Larger inputs still embed correctly; the embedder splits
// internally and the indexer just sees a slower individual call.
BatchSize() int
}
Embedder turns a batch of texts into dense vectors. Implementations are thin transport adapters around an embedding service (OpenAI-compatible `/v1/embeddings`, Ollama `/api/embed`); construction is via embed.New.
The interface splits embedding into a document-side and a query-side because instruction-tuned encoders (Qwen3, E5, Nomic, BGE) want asymmetric prefixes — `passage:` on documents, `query:` on queries, or `Instruct: …\nQuery:…` only on queries. The split makes the call-site intent explicit so the wrong template can't silently slip onto the wrong side. Untemplated models (OpenAI text-embedding-3) treat both methods as equivalent.
Dimensions returns the vector length the implementation produces — must be stable across calls so the index can validate row shape.
Fingerprint is an opaque identifier for the (provider + model + truncation + document template) tuple. Used by the search index to detect rows whose embedding is stale after a configuration change. The format is implementation-defined, but implementations must guarantee that two embedders that produce distribution-comparable document vectors share a fingerprint, and two that don't, don't. The query template deliberately does NOT factor into the fingerprint — query template changes affect retrieval quality but never invalidate indexed embeddings, so they're a free-tweak knob (see EmbeddingConfig).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude implements llm.Runner by invoking the Claude CLI.
|
Package claude implements llm.Runner by invoking the Claude CLI. |
|
Package embed provides Embedder implementations for OpenAI-compatible (`/v1/embeddings`) and Ollama (`/api/embeddings`) endpoints, plus a factory that dispatches by configured provider and wraps remote providers with a rate.Limiter (paralleling the chat-runner factory).
|
Package embed provides Embedder implementations for OpenAI-compatible (`/v1/embeddings`) and Ollama (`/api/embeddings`) endpoints, plus a factory that dispatches by configured provider and wraps remote providers with a rate.Limiter (paralleling the chat-runner factory). |
|
Package factory is the local host's llm.Runner composition: it resolves model.LLMConfig — a host-private config schema that never goes public — into one composed pkg/llm Runner (provider adapter, rate-limit decorator, timeout decorator).
|
Package factory is the local host's llm.Runner composition: it resolves model.LLMConfig — a host-private config schema that never goes public — into one composed pkg/llm Runner (provider adapter, rate-limit decorator, timeout decorator). |
|
Package gollm implements llm.Runner on top of github.com/teilomillet/gollm, providing a unified adapter for Anthropic API, OpenAI, Ollama, and other providers supported by gollm.
|
Package gollm implements llm.Runner on top of github.com/teilomillet/gollm, providing a unified adapter for Anthropic API, OpenAI, Ollama, and other providers supported by gollm. |