Documentation
¶
Overview ¶
Package config loads lore's typed configuration with the precedence flags > env (LORE_*) > file (TOML) > defaults, and builds the slog logger. It is loaded once in the composition root and passed down as values; nothing reads configuration globally.
Index ¶
- Constants
- func DefaultDBPath() (string, error)
- func DefaultPath() (string, error)
- func NewLogger(cfg Log, w io.Writer) *slog.Logger
- func UndecodedKeys(path string) []string
- type Cache
- type Chunk
- type Config
- type Connection
- type FlagOverrides
- type Ingest
- type Log
- type Provider
- type Rerank
- type Retrieval
- type Storage
Constants ¶
const DefaultCacheTTL = 30 * 24 * time.Hour
DefaultCacheTTL is how long a cached answer stays reusable unless overridden.
const DefaultProviderTimeout = 120 * time.Second
DefaultProviderTimeout bounds each provider HTTP request unless overridden. Generous enough not to cut off long generations, finite so a hung provider can't block a non-interactive run forever.
Variables ¶
This section is empty.
Functions ¶
func DefaultDBPath ¶
DefaultDBPath is the conventional SQLite database location, alongside the config file: <user-config-dir>/lore/lore.db.
func DefaultPath ¶
DefaultPath is the conventional config location: <user-config-dir>/lore/config.toml.
func NewLogger ¶
NewLogger builds a slog.Logger writing to w (stderr in the composition root), with a text or JSON handler per cfg.Format at cfg.Level.
func UndecodedKeys ¶ added in v1.0.0
UndecodedKeys returns the keys present in the TOML file at path that lore does not recognize — a typo, or a key placed in the wrong table (e.g. a top-level api_key instead of one under [provider]). A silently ignored key otherwise behaves exactly like an unset one, so the composition root logs these as a warning to break the edit / re-run / same-error loop. An empty path, an absent file, or a decode error yields no keys (a real decode error surfaces through Resolve, which reads the same file).
Types ¶
type Cache ¶
type Cache struct {
Enabled bool
// TTL is the maximum age of a reusable cached answer. Must be positive to be
// useful (a non-positive TTL means every entry reads as expired).
TTL time.Duration
}
Cache configures the answer cache: reuse of synthesized ask/synthesize answers across runs. Off by default (opt-in); the cache self-invalidates when the question, grounding text, or model/prompt change, and TTL bounds entry age.
type Chunk ¶
type Chunk struct {
Strategy string
Size int
Overlap int
// ContextPrefix prepends a chunk's heading path to the text that is embedded
// (not stored), so the embedding captures the chunk's place in the document.
// Default on; applies to the structure strategy's markdown chunker.
ContextPrefix bool
}
Chunk configures how documents are split into retrieval units. Strategy is "structure" (heading/paragraph-aware, token-sized — default) or "fixed" (legacy fixed word windows). Size/Overlap are measured in tokens for the structure strategy and in whitespace words for fixed. These values are pinned onto a collection at creation; changing them refuses re-ingest (rebuild instead).
type Config ¶
type Config struct {
Provider Provider
Rerank Rerank
Storage Storage
Ingest Ingest
Chunk Chunk
Cache Cache
Retrieval Retrieval
Log Log
}
Config is lore's resolved configuration.
func Defaults ¶
func Defaults() Config
Defaults returns the baseline configuration before file and environment overlays. The provider defaults target OpenAI; point BaseURL elsewhere for Ollama, vLLM, LM Studio, etc.
func Load ¶
Load builds a Config from defaults, then the TOML file at path (skipped when path is empty or the file is absent), then LORE_* variables read via getenv. It is Resolve with no flag overrides.
type Connection ¶
type Connection struct {
BaseURL string
APIKey string
Auth string // "bearer" or "api-key"
Timeout time.Duration
}
Connection is one provider role's resolved HTTP connection: the endpoint, credential, auth scheme, and per-request timeout used to reach it.
type FlagOverrides ¶
type FlagOverrides struct {
LogLevel string // "" = unset; e.g. "debug", "info", "warn", "error"
LogFormat string // "" = unset; "text" or "json"
Verbose bool // true forces debug level unless LogLevel is set
}
FlagOverrides carries the command-line flag values that outrank env and file in the precedence chain. A zero field means "not set on the command line" and is left untouched; Verbose is the exception — when true it forces debug level, but an explicit LogLevel still beats it.
type Ingest ¶
type Ingest struct {
// Concurrency bounds parallel embedding during ingest. 0 means use the
// built-in default; lower it for providers with tight rate limits.
Concurrency int
}
Ingest tunes the ingestion pipeline.
type Provider ¶
type Provider struct {
BaseURL string
APIKey string
EmbedModel string
Dimensions int
ChatModel string
// Auth selects how the API key is sent: "bearer" (OpenAI default) or
// "api-key" (Azure OpenAI's header).
Auth string
// Timeout bounds each HTTP request to the provider (per attempt, so retries
// each get the full budget). Zero disables it. Guards against a hung
// provider blocking forever in non-interactive use (CI, scripts), where
// there is no SIGINT to cancel the request context.
Timeout time.Duration
// EmbedBaseURL/EmbedAPIKey/EmbedAuth/EmbedTimeout override the shared
// connection for the embedding role only; an empty (zero) field inherits the
// shared value. EmbedTimeout of 0 inherits the shared Timeout — to disable a
// timeout set the shared Timeout to 0 (both roles then inherit it).
EmbedBaseURL string
EmbedAPIKey string
EmbedAuth string
EmbedTimeout time.Duration
// ChatBaseURL/ChatAPIKey/ChatAuth/ChatTimeout override the shared connection
// for the chat role only, with the same empty-inherits-shared semantics.
ChatBaseURL string
ChatAPIKey string
ChatAuth string
ChatTimeout time.Duration
// StructuredOutput declares that the provider supports JSON-schema
// (response_format) output. Off by default so lore works against any
// OpenAI-compatible endpoint; enable it for providers that support it.
// A chat-role property.
StructuredOutput bool
// ImageInput / DocumentInput declare that the provider accepts image /
// document attachments. Off by default; `ask --attach`
// errors for an attachment whose capability is off. Chat-role properties.
ImageInput bool
DocumentInput bool
}
Provider configures the OpenAI-compatible backend. The bare connection fields (BaseURL/APIKey/Auth/Timeout) are the shared default for both the embed and chat roles; the Embed*/Chat* fields optionally override them per role so one process can embed against one endpoint and chat against another. Resolve a role's effective connection with EmbedConnection / ChatConnection.
func (Provider) ChatConnection ¶
func (p Provider) ChatConnection() Connection
ChatConnection resolves the chat role's connection: each field is its chat_* override when set, else the shared provider.* value.
func (Provider) EmbedConnection ¶
func (p Provider) EmbedConnection() Connection
EmbedConnection resolves the embedding role's connection: each field is its embed_* override when set, else the shared provider.* value.
type Rerank ¶
type Rerank struct {
BaseURL string
APIKey string
Auth string // "bearer" (default) or "api-key"
Model string
Timeout time.Duration
}
Rerank configures the cross-encoder rerank provider for two-stage retrieval. It is deliberately separate from Provider: rerank APIs are Cohere-style, not OpenAI-compatible, and are commonly a different vendor (embed with OpenAI, rerank with Cohere/Jina). Empty BaseURL/Model means reranking is unconfigured; requesting it then is a usage error.
type Retrieval ¶ added in v1.0.0
type Retrieval struct {
Hybrid bool
}
Retrieval configures default retrieval behavior. Hybrid turns on BM25⊕vector hybrid retrieval by default for query/ask; the per-command --hybrid flag still overrides it (use --hybrid=false to force vector-only when the default is on).