config

package
v0.20.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config — embedding_check.go

The embedding dimension is wired into migration 011 via store.RunMigrations:

pg.RunMigrations(ctx, migrationsDir, cfg.EmbeddingDim)

RunMigrations detects "011_configurable_embedding_dim.sql" by filename and executes it inside a transaction on a dedicated connection with

SET LOCAL app.embedding_dim = <cfg.EmbeddingDim>

immediately before the DO block. SET LOCAL is transaction-scoped, so the GUC is guaranteed to be visible to current_setting('app.embedding_dim') within that same transaction regardless of pool connection reuse.

This file is intentionally kept as documentation. No code is required here because the wiring lives in store.(*Postgres).RunMigrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port        string
	DatabaseURL string

	// Embedding (optional — vector search disabled when EMBEDDING_API_KEY and
	// CLIPROXY_AUTH_FILE are both empty; FTS remains the graceful fallback).
	//
	// Routing decision (issue #34): embeddings use OpenAI directly via a
	// dedicated sk- key (EMBEDDING_API_KEY).  cliproxy is chat-only — it
	// returns 404 on /v1/embeddings and is therefore NOT suitable for this
	// path.  Setting EMBEDDING_API_KEY disables CLIPROXY_AUTH_FILE for the
	// embedding path (apiKey takes priority).
	//
	// Token resolution order:
	//   1. EMBEDDING_API_KEY non-empty → static Bearer token (OpenAI direct)
	//   2. CLIPROXY_AUTH_FILE non-empty → CliProxyAPI OAuth token (legacy; chat proxies only)
	//   3. Both empty → disabled (FTS-only mode, no embeddings generated)
	//
	// Default EMBEDDING_API_URL: https://api.openai.com/v1
	// Default EMBEDDING_MODEL:   text-embedding-3-small
	// Default EMBEDDING_DIM:     1536 (matches text-embedding-3-small output)
	EmbeddingAPIURL string
	// EmbeddingAPIKey is a dedicated OpenAI API key (EMBEDDING_API_KEY env var).
	// Use a separate key from any chat/LLM key so embedding costs are tracked
	// independently and the key can be rotated without affecting chat traffic.
	EmbeddingAPIKey  string
	EmbeddingModel   string
	EmbeddingDim     int    // EMBEDDING_DIM — vector dimension; must match the model output. Default 1536.
	CliProxyAuthFile string // CLIPROXY_AUTH_FILE — CliProxyAPI OAuth JSON path (chat proxies only; NOT used for embeddings when EMBEDDING_API_KEY is set)

	// EmbeddingProvider selects the embedding backend (EMBEDDING_PROVIDER env var).
	// Valid values: "openai" (default), "local" (Ollama-compatible).
	EmbeddingProvider string

	// Local embedding (Ollama-compatible) — used when EMBEDDING_PROVIDER=local.
	//
	// LOCAL_EMBEDDING_MODEL:    Ollama model name (default "bge-m3").
	// LOCAL_EMBEDDING_ENDPOINT: Ollama base URL (no default).
	//                           When empty the local embedder is disabled even if
	//                           EMBEDDING_PROVIDER=local (a warning is logged).
	LocalEmbeddingModel    string
	LocalEmbeddingEndpoint string

	// LLM (optional — Discord RAG answer generation; falls back to EmbeddingAPIURL when unset)
	// LLMAPIURL: LLM_API_URL env var; defaults to EmbeddingAPIURL with /embeddings → /chat/completions suffix fix.
	// LLMAPIKey: LLM_API_KEY env var; defaults to EmbeddingAPIKey.
	// LLMAuthFile: LLM_CLIPROXY_AUTH_FILE env var; defaults to CLIPROXY_AUTH_FILE when unset.
	// LLMTimeoutSeconds: LLM_TIMEOUT_SECONDS env var; per-request HTTP timeout for LLM calls.
	//   Default 120 s (generous for local CPU inference). Set higher for slow models
	//   (e.g. gemma3:4b on Mac mini CPU). Setting 0 falls back to the default.
	LLMAPIURL         string
	LLMAPIKey         string
	LLMAuthFile       string // path to CliProxyAPI OAuth JSON for LLM requests
	LLMModel          string
	LLMMaxTokens      int
	LLMTemperature    float64
	LLMTimeoutSeconds int // LLM_TIMEOUT_SECONDS — HTTP client timeout; default 120

	// Slack (optional)
	SlackBotToken string
	SlackTeamID   string

	// Discord (optional)
	DiscordBotToken               string
	DiscordApplicationID          string
	DiscordGuildIDs               []string
	DiscordCollectInterval        time.Duration
	DiscordMentionResponseEnabled bool

	// GitHub (optional)
	GitHubToken string
	GitHubOrg   string

	// Google Drive (optional)
	GDriveCredentialsJSON string

	// Notion (optional)
	NotionToken string

	// Telegram (optional)
	TelegramBotToken string
	TelegramChatIDs  []int64

	// Reranker (optional — cross-encoder post-retrieval reranking disabled when empty)
	RerankURL    string // RERANKER_URL — Jina-compatible /rerank endpoint base URL
	RerankAPIKey string // RERANKER_API_KEY — Bearer token for the reranker API
	RerankModel  string // RERANKER_MODEL — model identifier sent in the request body

	// Alerting (optional — Slack/Discord webhook for eval regression alerts)
	AlertWebhookURL string // ALERT_WEBHOOK_URL — Slack-compatible incoming webhook URL

	// API authentication (optional — disabled when empty, for dev backward compat)
	APIKey string // API_KEY — Bearer token required for /api/v1/* routes

	// Filesystem (optional)
	FilesystemPath        string   // FILESYSTEM_PATH — directory to scan
	FilesystemEnabled     bool     // FILESYSTEM_ENABLED — default false
	FilesystemExcludeDirs []string // FILESYSTEM_EXCLUDE_DIRS — comma-separated dir names to skip (merged with built-in defaults)
	FilesystemExcludeExts []string // FILESYSTEM_EXCLUDE_EXTS — comma-separated file extensions to skip (merged with built-in defaults)

	// Secretary SQLite (optional — disabled when empty)
	SecretaryDBPath string // SECRETARY_DB_PATH — path to secretary.db (e.g. /data/secretary.db)

	// LLM Memory SQLite (optional — disabled when empty)
	LLMMemoryDBPath string // LLM_MEMORY_DB_PATH — path to llm-memory.sqlite (e.g. /data/llm-memory.sqlite)

	// Gmail (optional — disabled when both credential fields are empty)
	// GMAIL_CREDENTIALS_JSON: OAuth2 client credentials JSON string (from Google Cloud Console)
	// GMAIL_TOKEN_JSON: OAuth2 access/refresh token JSON string
	// GMAIL_QUERY: Gmail search query (default: "-in:spam -in:trash")
	// GMAIL_MAX_MESSAGES: per-Collect cap on total message IDs fetched (default: 50000).
	// Set 0 to disable the cap entirely (no limit). Invalid values use the default.
	GmailCredentialsJSON string
	GmailTokenJSON       string
	GmailQuery           string
	GmailMaxMessages     int

	// Calendar (optional — disabled when both credential fields are empty)
	// CALENDAR_CREDENTIALS_JSON: OAuth2 client credentials JSON string
	// CALENDAR_TOKEN_JSON: OAuth2 access/refresh token JSON string
	// CALENDAR_ID: calendar identifier (default: "primary")
	// CALENDAR_LOOKAHEAD_DAYS: days into the future to collect (default: 90)
	// CALENDAR_LOOKBEHIND_DAYS: days into the past to collect (default: 365)
	CalendarCredentialsJSON string
	CalendarTokenJSON       string
	CalendarID              string
	CalendarLookaheadDays   int
	CalendarLookbehindDays  int

	// SMS + Call Log (optional — disabled when SMSSourceDir is empty)
	// SMS_SOURCE_DIR: directory containing SMS Backup & Restore XML exports
	// (sms-*.xml and calls-*.xml; latest mtime per prefix is used)
	// SMS_MAX_FILE_BYTES: per-file size cap for OOM guard (bytes, int64).
	// Default 1 GiB. Set 0 to disable the cap entirely (no limit).
	SMSSourceDir    string
	SMSMaxFileBytes int64

	// Whisper transcription (optional — disabled when WhisperAPIKey is empty)
	// WHISPER_API_KEY: OpenAI (or compatible) API key
	// WHISPER_API_URL: base URL (default: "https://api.openai.com/v1")
	// WHISPER_AUDIO_DIR: directory containing audio files to transcribe
	// WHISPER_MODEL: model identifier (default: "whisper-1")
	// WHISPER_LANGUAGE: BCP-47 language hint (default: "ko")
	// WHISPER_MAX_FILE_BYTES: per-file size cap (bytes, int64, default: 100 MiB).
	// Set 0 to disable the cap entirely (no limit). Invalid values use the default.
	// WHISPER_HTTP_TIMEOUT: per-request HTTP timeout for transcription calls
	// (Go duration string, default: "2h"). Raise for long audio files that exceed
	// the previous hardcoded 10-minute limit. Invalid values use the 2h default.
	// A zero duration (e.g. "0") falls back to the 2h default so a misconfigured
	// value never produces an infinite (zero) timeout.
	WhisperAPIKey       string
	WhisperAPIURL       string
	WhisperAudioDir     string
	WhisperModel        string
	WhisperLanguage     string
	WhisperMaxFileBytes int64
	WhisperHTTPTimeout  time.Duration

	// Speaker diarization (optional — feature-flagged OFF by default).
	//
	// DIARIZATION_ENABLED: set "true" to enable speaker diarization post-processing
	// after each successful Whisper transcription. Default false (no behaviour change).
	//
	// DIARIZATION_API_URL: base URL of the local diarization microservice
	// (e.g. "http://localhost:8765"). Required when DIARIZATION_ENABLED=true.
	// The collector POSTs audio bytes to {DIARIZATION_API_URL}/diarize and
	// receives speaker-segment JSON. When empty, diarization is disabled even
	// if DIARIZATION_ENABLED=true.
	DiarizationEnabled bool   // DIARIZATION_ENABLED — default false
	DiarizationAPIURL  string // DIARIZATION_API_URL — default ""

	// IngestMaxFileBytes is the per-upload file size cap for POST /api/v1/ingest/file
	// and POST /api/v1/ingest/recording.
	// Default 100 MiB. Set INGEST_MAX_FILE_BYTES=0 to disable the cap entirely.
	// Invalid values use the default.
	IngestMaxFileBytes int64

	// IngestRecordingDir is the directory where POST /api/v1/ingest/recording
	// saves uploaded audio files for later transcription by WhisperCollector.
	//
	// Resolution order:
	//   1. INGEST_RECORDING_DIR non-empty → use directly.
	//   2. WHISPER_AUDIO_DIR non-empty    → use WHISPER_AUDIO_DIR/ingest.
	//   3. Both empty                     → recording ingest is disabled.
	//
	// WhisperCollector picks up the saved files on its next scheduled run.
	IngestRecordingDir string

	// IngestMaxBatchMessages is the maximum number of combined SMS + call records
	// accepted in a single POST /api/v1/ingest/messages request.
	// Default 5000. Set INGEST_MAX_BATCH_MESSAGES=0 to use the default.
	// Invalid values use the default.
	IngestMaxBatchMessages int

	// Summarizer
	// SummarizerBackfillEnabled controls whether the SummarizerWorker scans for
	// pre-existing unsummarized documents (WHERE title_summary IS NULL).
	// Default true. Set SUMMARIZER_BACKFILL_ENABLED=false when running a slow
	// local LLM to avoid a flood of LLM calls for the pre-existing backlog.
	SummarizerBackfillEnabled bool // SUMMARIZER_BACKFILL_ENABLED

	// Scheduler
	CollectInterval time.Duration
	// CollectIntervalPerSource holds per-source overrides for the global
	// CollectInterval. Keys are the collector Name() strings; values are the
	// desired intervals. Populated from COLLECT_INTERVAL_<NAME> env vars where
	// <NAME> is the upper-cased, underscore-normalised collector name
	// (e.g. COLLECT_INTERVAL_WHISPER, COLLECT_INTERVAL_FILESYSTEM).
	// Only positive durations are stored; invalid or zero values are ignored.
	CollectIntervalPerSource map[string]time.Duration

	// DeletionRatioOverride bypasses the 50% deletion-ratio guard when true.
	// Controlled by DELETION_RATIO_OVERRIDE=true. Use only for legitimate large
	// one-off deletions (see scheduler.WithDeletionRatioOverride for trade-offs).
	DeletionRatioOverride bool

	// CollectorInstance is the per-host identifier used to key the
	// collector_state watermark table. Defaults to os.Hostname() (or
	// "default" when that fails) when COLLECTOR_INSTANCE is unset.
	CollectorInstance string

	// CollectorCutover is an optional floor time for IndexAware collectors
	// (SMS, Whisper). When non-zero, the collector will not emit any record
	// whose event time (OccurredAt for SMS/call-log, mtime for Whisper) is
	// before this value — even if the record was never indexed.
	//
	// This prevents re-collecting pre-cutover history that is already covered
	// by the legacy secretary source, while still allowing post-cutover
	// late-arrival recovery via the IndexAware path.
	//
	// Source: COLLECTOR_CUTOVER env var (RFC3339 format).
	// Default: zero time.Time{} = floor DISABLED (no behaviour change).
	CollectorCutover time.Time
}

Config holds all application configuration loaded from environment variables.

func Load

func Load() (*Config, error)

Load reads configuration from environment variables and returns a Config. Required variables (PORT, DATABASE_URL) fall back to safe defaults for development.

func LoadCollector

func LoadCollector() (*Config, error)

LoadCollector reads configuration for the collector daemon. It excludes server-only fields (PORT, API_KEY).

Jump to

Keyboard shortcuts

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