config

package
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerLLMDefaultMaxConcurrent        = 4
	ServerLLMDefaultMaxRedirects         = 3
	ServerLLMDefaultMaxResponseBodyBytes = int64(4 << 20)
	ServerLLMDefaultMaxErrorBodyBytes    = int64(4 << 10)
	ServerLLMDefaultTimeout              = 45 * time.Second
	ServerLLMMaxTimeout                  = 5 * time.Minute
	ServerLLMMaxAllowedHosts             = 64
	ServerLLMMaxAllowedPorts             = 16
)

Defaults applied by ValidateServerLLM for unset bounds.

View Source
const MinimalDefaultJSON = `` /* 184-byte string literal not displayed */
View Source
const MinimalDefaultTOML = `` /* 186-byte string literal not displayed */
View Source
const MinimalDefaultYAML = `` /* 244-byte string literal not displayed */

Minimal templates for initial setup

Variables

This section is empty.

Functions

func ClearEnvVar

func ClearEnvVar(key string) error

ClearEnvVar clears an environment variable Useful for testing

func CortexDir

func CortexDir() string

CortexDir returns the centralized data directory (~/.cortex/). It uses $HOME, $USERPROFILE, or os.UserHomeDir() to resolve the home directory.

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns the default database path (~/.cortex/cortex.db).

func GetEnvVarName

func GetEnvVarName(key string) string

GetEnvVarName returns the environment variable name for a given config key e.g., "database.path" -> "CORTEX_DATABASE_PATH"

func InitConfig

func InitConfig(targetPath string, format string, force bool) (string, error)

InitConfig creates a clean minimal config file of the requested format.

func Save

func Save(cfg *Config, path string) error

Save writes the configuration to the specified path. If path is empty, writes to the loaded path or default ~/.cortex/cortex.yaml. The write is atomic: data goes to a .tmp file first, then renamed.

func SetEnvVar

func SetEnvVar(key, value string) error

SetEnvVar sets an environment variable for configuration override Useful for testing

func Validate

func Validate(cfg *Config) error

Validate checks a configuration without reading or writing a file.

func ValidateServerLLM

func ValidateServerLLM(cfg *ServerLLMConfig) error

ValidateServerLLM validates and normalizes the outbound LLM configuration. Error messages never include the API key or the raw base URL: they name the offending field and the constraint only.

Types

type AIConfig

type AIConfig struct {
	Provider string `yaml:"provider,omitempty" json:"provider,omitempty" toml:"provider,omitempty" mapstructure:"provider"`
	Model    string `yaml:"model,omitempty" json:"model,omitempty" toml:"model,omitempty" mapstructure:"model"`
	BaseURL  string `yaml:"base_url,omitempty" json:"base_url,omitempty" toml:"base_url,omitempty" mapstructure:"base_url"`
}

AIConfig holds unified AI and embedding model settings

type Config

type Config struct {
	AI        AIConfig        `yaml:"ai,omitempty" json:"ai,omitempty" toml:"ai,omitempty" mapstructure:"ai"`
	Database  DatabaseConfig  `yaml:"database,omitempty" json:"database,omitempty" toml:"database,omitempty" mapstructure:"database"`
	HTTP      HTTPConfig      `yaml:"http,omitempty" json:"http,omitempty" toml:"http,omitempty" mapstructure:"http"`
	Server    ServerConfig    `yaml:"server,omitempty" json:"server,omitempty" toml:"server,omitempty" mapstructure:"server"`
	MCP       MCPConfig       `yaml:"mcp,omitempty" json:"mcp,omitempty" toml:"mcp,omitempty" mapstructure:"mcp"`
	Logging   LoggingConfig   `yaml:"logging,omitempty" json:"logging,omitempty" toml:"logging,omitempty" mapstructure:"logging"`
	Search    SearchConfig    `yaml:"search,omitempty" json:"search,omitempty" toml:"search,omitempty" mapstructure:"search"`
	Memory    MemoryConfig    `yaml:"memory,omitempty" json:"memory,omitempty" toml:"memory,omitempty" mapstructure:"memory"`
	Lifecycle LifecycleConfig `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty" toml:"lifecycle,omitempty" mapstructure:"lifecycle"`
	Vector    VectorConfig    `yaml:"vector,omitempty" json:"vector,omitempty" toml:"vector,omitempty" mapstructure:"vector"`
	Sync      SyncConfig      `yaml:"sync,omitempty" json:"sync,omitempty" toml:"sync,omitempty" mapstructure:"sync"`

	// LoadedFrom is the path of the config file that was loaded.
	// Used by Save() and ReloadConfig() to always use the same file.
	// Not serialized to YAML, JSON, or TOML.
	LoadedFrom string `yaml:"-" json:"-" toml:"-" mapstructure:"-"`
}

Config represents the main configuration structure

func Load

func Load(configPath string) (*Config, error)

Load reads configuration from file, environment variables, and applies defaults The configPath parameter is optional - if empty, it searches for cortex.yaml, cortex.yml, cortex.json, cortex.toml

func LoadFromEnv

func LoadFromEnv() (*Config, error)

LoadFromEnv loads configuration exclusively from environment variables and defaults Useful for containerized deployments where config files are not used

func (*Config) GetProperty

func (cfg *Config) GetProperty(key string) (string, error)

GetProperty retrieves a configuration value by dot-separated path.

func (*Config) SetProperty

func (cfg *Config) SetProperty(key, value string) error

SetProperty updates a configuration value by dot-separated path.

func (*Config) String

func (c *Config) String() string

String returns a string representation of the configuration (for debugging). The Vector.Qdrant.APIKey is NEVER included: secrets must not surface in logs or debug output (REQ-CP-002). Vector is rendered with the key blanked so the representation stays useful without leaking credentials.

type DatabaseConfig

type DatabaseConfig struct {
	Path     string       `yaml:"path,omitempty" json:"path,omitempty" toml:"path,omitempty" mapstructure:"path"`
	InMemory bool         `yaml:"in_memory,omitempty" json:"in_memory,omitempty" toml:"in_memory,omitempty" mapstructure:"in_memory"`
	Pragma   PragmaConfig `yaml:"pragma,omitempty" json:"pragma,omitempty" toml:"pragma,omitempty" mapstructure:"pragma"`
}

DatabaseConfig holds database configuration

type HTTPConfig

type HTTPConfig struct {
	Enabled        bool     `yaml:"enabled,omitempty" json:"enabled,omitempty" toml:"enabled,omitempty" mapstructure:"enabled"`
	Port           int      `yaml:"port,omitempty" json:"port,omitempty" toml:"port,omitempty" mapstructure:"port"`
	Host           string   `yaml:"host,omitempty" json:"host,omitempty" toml:"host,omitempty" mapstructure:"host"`
	Token          string   `yaml:"token,omitempty" json:"token,omitempty" toml:"token,omitempty" mapstructure:"token"`
	AllowedOrigins []string `` /* 129-byte string literal not displayed */
}

HTTPConfig holds HTTP server configuration

type LifecycleConfig

type LifecycleConfig struct {
	EnableAutoArchive    bool   `` /* 145-byte string literal not displayed */
	ArchiveCheckInterval string `` /* 157-byte string literal not displayed */
}

LifecycleConfig holds lifecycle management configuration

type LoggingConfig

type LoggingConfig struct {
	Level  string `yaml:"level,omitempty" json:"level,omitempty" toml:"level,omitempty" mapstructure:"level"`
	Format string `yaml:"format,omitempty" json:"format,omitempty" toml:"format,omitempty" mapstructure:"format"`
}

LoggingConfig holds logging configuration

type MCPConfig

type MCPConfig struct {
	Enabled bool            `yaml:"enabled,omitempty" json:"enabled,omitempty" toml:"enabled,omitempty" mapstructure:"enabled"`
	Remote  MCPRemoteConfig `yaml:"remote,omitempty" json:"remote,omitempty" toml:"remote,omitempty" mapstructure:"remote"`
}

MCPConfig holds MCP (Model Context Protocol) configuration

type MCPRemoteConfig

type MCPRemoteConfig struct {
	Enabled  bool          `yaml:"enabled,omitempty" json:"enabled,omitempty" toml:"enabled,omitempty" mapstructure:"enabled"`
	URL      string        `yaml:"url,omitempty" json:"url,omitempty" toml:"url,omitempty" mapstructure:"url"`
	TokenEnv string        `yaml:"token_env,omitempty" json:"token_env,omitempty" toml:"token_env,omitempty" mapstructure:"token_env"`
	Timeout  time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" toml:"timeout,omitempty" mapstructure:"timeout"`
}

MCPRemoteConfig makes the local stdio MCP process proxy an authenticated Streamable HTTP MCP server instead of opening the local SQLite composition.

type MemoryConfig

type MemoryConfig struct {
	MaxObservationLength int     `` /* 157-byte string literal not displayed */
	DedupeWindow         string  `yaml:"dedupe_window,omitempty" json:"dedupe_window,omitempty" toml:"dedupe_window,omitempty" mapstructure:"dedupe_window"`
	AutoArchiveDays      int     `` /* 137-byte string literal not displayed */
	DecayHalfLifeDays    float64 `` /* 173-byte string literal not displayed */
	MinArchiveScore      float64 `` /* 137-byte string literal not displayed */
}

MemoryConfig holds memory management configuration

type PGVectorConfig

type PGVectorConfig struct {
	DSN                string        `yaml:"dsn,omitempty" json:"dsn,omitempty" toml:"dsn,omitempty" mapstructure:"dsn"`
	MigrationDSN       string        `yaml:"migration_dsn,omitempty" json:"migration_dsn,omitempty" toml:"migration_dsn,omitempty" mapstructure:"migration_dsn"`
	Schema             string        `yaml:"schema,omitempty" json:"schema,omitempty" toml:"schema,omitempty" mapstructure:"schema"`
	Table              string        `yaml:"table,omitempty" json:"table,omitempty" toml:"table,omitempty" mapstructure:"table"`
	Dimension          int           `yaml:"dimension,omitempty" json:"dimension,omitempty" toml:"dimension,omitempty" mapstructure:"dimension"`
	IndexType          string        `yaml:"index_type,omitempty" json:"index_type,omitempty" toml:"index_type,omitempty" mapstructure:"index_type"`
	HNSWM              int           `yaml:"hnsw_m,omitempty" json:"hnsw_m,omitempty" toml:"hnsw_m,omitempty" mapstructure:"hnsw_m"`
	HNSWEfConstruction int           `` /* 149-byte string literal not displayed */
	IVFFlatLists       int           `yaml:"ivfflat_lists,omitempty" json:"ivfflat_lists,omitempty" toml:"ivfflat_lists,omitempty" mapstructure:"ivfflat_lists"`
	MaxBatchSize       int           `yaml:"max_batch_size,omitempty" json:"max_batch_size,omitempty" toml:"max_batch_size,omitempty" mapstructure:"max_batch_size"`
	Timeout            time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" toml:"timeout,omitempty" mapstructure:"timeout"`
	MaxConns           int32         `yaml:"max_conns,omitempty" json:"max_conns,omitempty" toml:"max_conns,omitempty" mapstructure:"max_conns"`
	StatementTimeoutMs int           `` /* 149-byte string literal not displayed */
}

PGVectorConfig holds connection parameters for the pgvector external vector adapter.

type PragmaConfig

type PragmaConfig struct {
	JournalMode string `yaml:"journal_mode,omitempty" json:"journal_mode,omitempty" toml:"journal_mode,omitempty" mapstructure:"journal_mode"`
	Synchronous string `yaml:"synchronous,omitempty" json:"synchronous,omitempty" toml:"synchronous,omitempty" mapstructure:"synchronous"`
	CacheSize   int    `yaml:"cache_size,omitempty" json:"cache_size,omitempty" toml:"cache_size,omitempty" mapstructure:"cache_size"`
	ForeignKeys bool   `yaml:"foreign_keys,omitempty" json:"foreign_keys,omitempty" toml:"foreign_keys,omitempty" mapstructure:"foreign_keys"`
	TempStore   string `yaml:"temp_store,omitempty" json:"temp_store,omitempty" toml:"temp_store,omitempty" mapstructure:"temp_store"`
	MmapSize    int    `yaml:"mmap_size,omitempty" json:"mmap_size,omitempty" toml:"mmap_size,omitempty" mapstructure:"mmap_size"`
}

PragmaConfig holds SQLite pragma settings

type QdrantConfig

type QdrantConfig struct {
	Host         string        `yaml:"host,omitempty" json:"host,omitempty" toml:"host,omitempty" mapstructure:"host"`
	Port         int           `yaml:"port,omitempty" json:"port,omitempty" toml:"port,omitempty" mapstructure:"port"`
	Collection   string        `yaml:"collection,omitempty" json:"collection,omitempty" toml:"collection,omitempty" mapstructure:"collection"`
	Dimension    int           `yaml:"dimension,omitempty" json:"dimension,omitempty" toml:"dimension,omitempty" mapstructure:"dimension"`
	APIKey       string        `yaml:"api_key,omitempty" json:"api_key,omitempty" toml:"api_key,omitempty" mapstructure:"api_key"`
	UseTLS       bool          `yaml:"use_tls,omitempty" json:"use_tls,omitempty" toml:"use_tls,omitempty" mapstructure:"use_tls"`
	MaxBatchSize int           `yaml:"max_batch_size,omitempty" json:"max_batch_size,omitempty" toml:"max_batch_size,omitempty" mapstructure:"max_batch_size"`
	MaxRetries   uint          `yaml:"max_retries,omitempty" json:"max_retries,omitempty" toml:"max_retries,omitempty" mapstructure:"max_retries"`
	Timeout      time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" toml:"timeout,omitempty" mapstructure:"timeout"`
}

QdrantConfig holds connection parameters for the Qdrant external vector adapter.

type SearchConfig

type SearchConfig struct {
	DefaultLimit      int     `yaml:"default_limit,omitempty" json:"default_limit,omitempty" toml:"default_limit,omitempty" mapstructure:"default_limit"`
	MaxLimit          int     `yaml:"max_limit,omitempty" json:"max_limit,omitempty" toml:"max_limit,omitempty" mapstructure:"max_limit"`
	FTS5              bool    `yaml:"fts5,omitempty" json:"fts5,omitempty" toml:"fts5,omitempty" mapstructure:"fts5"`
	Vector            bool    `yaml:"vector,omitempty" json:"vector,omitempty" toml:"vector,omitempty" mapstructure:"vector"`
	FusionK           float64 `yaml:"fusion_k,omitempty" json:"fusion_k,omitempty" toml:"fusion_k,omitempty" mapstructure:"fusion_k"`
	EmbeddingProvider string  `` // "ollama", "openai", "none" (default)
	/* 141-byte string literal not displayed */
	EmbeddingModel string `` // Model name override (e.g. "qwen3-embedding:8b")
	/* 129-byte string literal not displayed */
	EmbeddingBaseURL string `` // Ollama base URL override (default: http://localhost:11434)
	/* 141-byte string literal not displayed */
	OllamaAutoStart bool `` // Auto-start Ollama when configured as provider
	/* 137-byte string literal not displayed */
}

SearchConfig holds search-related configuration

type ServerConfig

type ServerConfig struct {
	Name                    string               `yaml:"name,omitempty" json:"name,omitempty" toml:"name,omitempty" mapstructure:"name"`
	Version                 string               `yaml:"version,omitempty" json:"version,omitempty" toml:"version,omitempty" mapstructure:"version"`
	Storage                 ServerStorageConfig  `yaml:"storage,omitempty" json:"storage,omitempty" toml:"storage,omitempty" mapstructure:"storage"`
	Provider                ServerProviderConfig `yaml:"provider,omitempty" json:"provider,omitempty" toml:"provider,omitempty" mapstructure:"provider"`
	Secrets                 ServerSecretsConfig  `yaml:"secrets,omitempty" json:"secrets,omitempty" toml:"secrets,omitempty" mapstructure:"secrets"`
	TenantID                string               `yaml:"tenant_id,omitempty" json:"tenant_id,omitempty" toml:"tenant_id,omitempty" mapstructure:"tenant_id"`
	WorkspaceID             string               `yaml:"workspace_id,omitempty" json:"workspace_id,omitempty" toml:"workspace_id,omitempty" mapstructure:"workspace_id"`
	PrincipalSubject        string               `` /* 137-byte string literal not displayed */
	GrantDigest             string               `yaml:"grant_digest,omitempty" json:"grant_digest,omitempty" toml:"grant_digest,omitempty" mapstructure:"grant_digest"`
	GrantVersion            int64                `yaml:"grant_version,omitempty" json:"grant_version,omitempty" toml:"grant_version,omitempty" mapstructure:"grant_version"`
	Roles                   []string             `yaml:"roles,omitempty" json:"roles,omitempty" toml:"roles,omitempty" mapstructure:"roles"`
	Scopes                  []string             `yaml:"scopes,omitempty" json:"scopes,omitempty" toml:"scopes,omitempty" mapstructure:"scopes"`
	ProjectIDs              []string             `yaml:"project_ids,omitempty" json:"project_ids,omitempty" toml:"project_ids,omitempty" mapstructure:"project_ids"`
	ClassificationClearance []string             `` /* 165-byte string literal not displayed */
	BootstrapDevelopment    bool                 `` /* 153-byte string literal not displayed */
	// RailwayInternalEmbeddingHost is the exact Railway private hostname
	// allowed to serve embeddings over HTTP. An empty value keeps the default
	// policy, which rejects every non-loopback HTTP destination.
	RailwayInternalEmbeddingHost string `` /* 193-byte string literal not displayed */
	// MultiTenant enables SaaS request scoping. Tenant and workspace are derived from a verified bearer and an authorized workspace selection.
	MultiTenant bool `yaml:"multi_tenant,omitempty" json:"multi_tenant,omitempty" toml:"multi_tenant,omitempty" mapstructure:"multi_tenant"`
}

ServerConfig holds server-related configuration

type ServerLLMConfig

type ServerLLMConfig struct {
	// Provider selects the provider preset: "" | "openai" | "anthropic" |
	// "generic". With an empty BaseURL the preset's canonical HTTPS endpoint
	// is used.
	Provider string
	// BaseURL is the admin-approved provider destination. It must be an
	// absolute HTTPS URL without userinfo; plain HTTP is permitted only for a
	// strict loopback host under the explicit AllowLoopbackHTTP development
	// switch.
	BaseURL string
	// Model optionally overrides the provider model.
	Model string
	// APIKey is the provider credential supplied via CORTEX_LLM_API_KEY. It
	// is attached to outbound requests only after the destination passes
	// outbound policy validation.
	APIKey string
	// AllowedHosts is an additional destination host allowlist: plain
	// hostnames (no port, userinfo, slash, or whitespace), case-insensitive.
	AllowedHosts []string
	// AllowedPorts optionally extends approved TCP ports. 443 is always
	// approved for HTTPS destinations.
	AllowedPorts []int
	// AllowLoopback is an explicit local-only development switch permitting
	// HTTPS loopback destinations.
	AllowLoopback bool
	// AllowLoopbackHTTP is an explicit local-only development switch
	// permitting plain HTTP to strict loopback hosts only.
	AllowLoopbackHTTP bool
	// MaxConcurrent bounds concurrent outbound provider requests
	// (default 4, range 1-64).
	MaxConcurrent int
	// MaxRedirects caps redirect chains (default 3, range 1-10).
	MaxRedirects int
	// MaxResponseBodyBytes bounds provider success bodies (default 4 MiB,
	// range 1 B - 64 MiB).
	MaxResponseBodyBytes int64
	// MaxErrorBodyBytes bounds drained provider error bodies (default 4 KiB,
	// range 1 B - 1 MiB).
	MaxErrorBodyBytes int64
	// Timeout bounds one provider round-trip (default 45s, max 5m).
	Timeout time.Duration
	// CACertPool optionally holds private CA roots for the provider TLS
	// handshake (CORTEX_LLM_CA_FILE, PEM-encoded certificates).
	CACertPool *x509.CertPool
}

ServerLLMConfig holds administrator-owned outbound LLM provider settings for server extract/synthesize (SEC-02). Every field comes exclusively from trusted server configuration (CORTEX_LLM_* environment variables); request data can never influence any field. The API key is read directly from the environment and is never stored in Config, rendered by Config.String, or echoed in validation errors.

An absent configuration (no provider and no base URL) preserves heuristic-only operation with no approved outbound destination.

func ServerLLMFromEnv

func ServerLLMFromEnv() (ServerLLMConfig, error)

ServerLLMFromEnv reads the administrator-owned outbound provider configuration from CORTEX_LLM_* environment variables and validates it. An invalid or inconsistent configuration is an error: callers must fail closed rather than silently fall back to a different destination class.

func (ServerLLMConfig) Configured

func (c ServerLLMConfig) Configured() bool

Configured reports whether an outbound provider is configured. When false, extract/synthesize stay heuristic-only with no approved destination.

type ServerProviderConfig

type ServerProviderConfig struct {
	Embedding string `yaml:"embedding,omitempty" json:"embedding,omitempty" toml:"embedding,omitempty" mapstructure:"embedding"`
	Vector    string `yaml:"vector,omitempty" json:"vector,omitempty" toml:"vector,omitempty" mapstructure:"vector"`
}

ServerProviderConfig selects server-side providers without constructing them.

type ServerSecretsConfig

type ServerSecretsConfig struct {
	SigningKey       string `yaml:"signing_key,omitempty" json:"signing_key,omitempty" toml:"signing_key,omitempty" mapstructure:"signing_key"`
	OIDCClientSecret string `` /* 141-byte string literal not displayed */
}

ServerSecretsConfig contains credentials consumed by later identity waves. Secrets are never rendered by Config.String.

type ServerStorageConfig

type ServerStorageConfig struct {
	Driver       string `yaml:"driver,omitempty" json:"driver,omitempty" toml:"driver,omitempty" mapstructure:"driver"`
	DSN          string `yaml:"dsn,omitempty" json:"dsn,omitempty" toml:"dsn,omitempty" mapstructure:"dsn"`
	MigrationDSN string `yaml:"migration_dsn,omitempty" json:"migration_dsn,omitempty" toml:"migration_dsn,omitempty" mapstructure:"migration_dsn"`
	MaxConns     int32  `yaml:"max_conns,omitempty" json:"max_conns,omitempty" toml:"max_conns,omitempty" mapstructure:"max_conns"`
}

ServerStorageConfig contains server-only PostgreSQL connection settings. It is intentionally separate from the local SQLite database config.

type SyncConfig

type SyncConfig struct {
	Enabled  bool          `yaml:"enabled,omitempty" json:"enabled,omitempty" toml:"enabled,omitempty" mapstructure:"enabled"`
	URL      string        `yaml:"url,omitempty" json:"url,omitempty" toml:"url,omitempty" mapstructure:"url"`
	TokenEnv string        `yaml:"token_env,omitempty" json:"token_env,omitempty" toml:"token_env,omitempty" mapstructure:"token_env"`
	Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty" toml:"interval,omitempty" mapstructure:"interval"`
	Timeout  time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" toml:"timeout,omitempty" mapstructure:"timeout"`
}

SyncConfig controls optional bidirectional SQLite/server replication.

type VectorConfig

type VectorConfig struct {
	Provider string         `yaml:"provider,omitempty" json:"provider,omitempty" toml:"provider,omitempty" mapstructure:"provider"`
	Qdrant   QdrantConfig   `yaml:"qdrant,omitempty" json:"qdrant,omitempty" toml:"qdrant,omitempty" mapstructure:"qdrant"`
	Pgvector PGVectorConfig `yaml:"pgvector,omitempty" json:"pgvector,omitempty" toml:"pgvector,omitempty" mapstructure:"pgvector"`
}

VectorConfig holds external vector index adapter configuration.

Jump to

Keyboard shortcuts

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