# ============================================================================= # Memory Engine Server — Environment Variables # ============================================================================= # Copy to .env and fill in the required values. # ----------------------------------------------------------------------------- # Required # ----------------------------------------------------------------------------- # PostgreSQL connection string for the application database. One database holds # the auth + core control plane and every per-space me_ schema. DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres # Public base URL for OAuth callbacks API_BASE_URL=http://localhost:3000 # OpenAI API key (or compatible provider) for generating embeddings EMBEDDING_API_KEY= # better-auth signing secret: signs session cookies and encrypts the JWKS keys. # Required — the server refuses to boot without it. Use a long random value, # e.g. `openssl rand -base64 32`. BETTER_AUTH_SECRET= # ----------------------------------------------------------------------------- # Optional — Docker Compose (self-host) # ----------------------------------------------------------------------------- # Password for the bundled Postgres container in compose.yaml. Required by # `docker compose up` (the server's DATABASE_URL is built from it); ignored by # host-run dev (`./bun run server`), which uses DATABASE_URL above. Use a # URL-safe value (letters/digits) so it needs no encoding in the connection # string. See SELF_HOST.md. # POSTGRES_PASSWORD= # ----------------------------------------------------------------------------- # OAuth Providers # ----------------------------------------------------------------------------- # At least one provider is required for user authentication. # GitHub OAuth app credentials # Create at: https://github.com/settings/developers GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= # Google OAuth app credentials # Create at: https://console.cloud.google.com/apis/credentials GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= # ----------------------------------------------------------------------------- # Optional — Server # ----------------------------------------------------------------------------- # HTTP server port # PORT=3000 # Optional signup restriction: new users need a provider-verified email at this # exact domain (case-insensitive). Existing users and credentials are unaffected. # Leave unset for unrestricted signup. Empty/malformed values fail startup. # SIGNUP_EMAIL_DOMAIN=example.com # Maximum request body size in bytes (default: 1048576 = 1 MiB). # Raise for memory.batchCreate-heavy workloads (e.g. transcript imports). # MAX_REQUEST_BODY_BYTES= # Schema names # AUTH_SCHEMA=auth # CORE_SCHEMA=core # Cron schedule for the auth cleanup job, e.g. expired device authorizations # (UTC). The legacy name DEVICE_FLOW_CLEANUP_CRON is still honored. # AUTH_CLEANUP_CRON=*/15 * * * * # Directory of the built web UI to serve at root `/` (the Docker image bakes # this in; override only for host runs with a non-default build location). # WEB_DIST=packages/web/dist # Extra origins allowed to make cookie-authenticated requests (CSRF gate), # comma-separated. The API_BASE_URL origin is always allowed; add others here # (e.g. to permit both api.* and app.* during a cutover). # WEB_ALLOWED_ORIGINS= # ----------------------------------------------------------------------------- # Optional — Telemetry # ----------------------------------------------------------------------------- # Logfire token for OpenTelemetry export. Default: unset (no export). The token # is project-scoped, so data only appears in that token's own Logfire project. # LOGFIRE_TOKEN= # Deployment environment label for telemetry. Default: unset. # Example: LOGFIRE_ENVIRONMENT=prod # LOGFIRE_ENVIRONMENT= # Print spans to the console. Default: off — set to true to enable # (useful for local development). # LOGFIRE_CONSOLE=true # Scrubbing of sensitive fields (content, embeddings, tokens) is ON by default. # Set to false to disable. # LOGFIRE_SCRUBBING=false # API + worker telemetry profile: lean (default) disables SDK metrics and emits # one numeric Runtime memory sample log at startup and every 60s. diagnostic # enables application HTTP + 9 snapshot gauges (SDK-native 60s export) and 10s # sample logs. Unknown values fall back to lean. Both profiles disable automatic # runtime-node/V8 instrumentation, cgroup sampling, and periodic forceFlush. # LOGFIRE_TELEMETRY_PROFILE=lean # Optional sample-log interval override in ms; minimum 10000. Invalid/nonpositive, # unsafe integers or values above 2147483647 fall back to the profile default # (lean: 60000, diagnostic: 10000). Does not change SDK metric export cadence. # LOGFIRE_RUNTIME_SAMPLE_INTERVAL_MS=60000 # OTEL_METRIC_EXPORT_INTERVAL no longer controls this app. For a production # profile change, restart/redeploy API + worker processes (no new image release # needed once profile support is deployed). Explicitly restore lean after an # incident. See DEVELOPMENT.md and design/runtime-observability.md. # Optional explicit OTel resource attributes. Missing service.instance.id and # Bun runtime attributes are generated automatically per server process start. # OTEL_RESOURCE_ATTRIBUTES=custom.key=value # Kubernetes Downward API identity (optional; POD_NAME falls back to HOSTNAME # inside Kubernetes). See design/runtime-observability.md for deployment wiring. # POD_NAME= # POD_UID= # NAMESPACE= # ----------------------------------------------------------------------------- # Optional — Database Connection Pool # ----------------------------------------------------------------------------- # Maximum connections in pool # DB_POOL_MAX=20 # Close idle pooled connections after N seconds # DB_POOL_IDLE_REAP_SECONDS=300 # Max connection lifetime in seconds (0 = forever) # DB_POOL_MAX_LIFETIME=0 # Timeout for establishing new connections (seconds) # DB_POOL_CONNECTION_TIMEOUT=30 # ----------------------------------------------------------------------------- # Optional — Runtime RPC Database Timeouts # ----------------------------------------------------------------------------- # Session-level PostgreSQL timeouts for request-path database work (ms). # Cancel statements that run longer than this # RPC_DB_STATEMENT_TIMEOUT_MS=30000 # Cancel statements that wait too long for locks # RPC_DB_LOCK_TIMEOUT_MS=5000 # Cancel transactions that run longer than this # RPC_DB_TRANSACTION_TIMEOUT_MS=35000 # End sessions idle in a transaction for longer than this # RPC_DB_IDLE_IN_TRANSACTION_SESSION_TIMEOUT_MS=35000 # ----------------------------------------------------------------------------- # Optional — Embedding # ----------------------------------------------------------------------------- # Base URL for the embedding API (omit for OpenAI default). Any # OpenAI-compatible /embeddings gateway works, e.g. to route through OpenRouter: # EMBEDDING_BASE_URL=https://openrouter.ai/api/v1 # EMBEDDING_MODEL=openai/text-embedding-3-small # EMBEDDING_API_KEY= # EMBEDDING_BASE_URL= # Embedding model name (default: text-embedding-3-small). Override when a # gateway namespaces the model differently (OpenRouter needs the "openai/" # prefix). The replacement MUST emit 1536-dim vectors (the stored column is # halfvec(1536)) and be the same underlying model as whatever produced your # existing vectors — otherwise semantic search silently degrades. # EMBEDDING_MODEL= # Timeout per embedding API call (ms) # EMBEDDING_TIMEOUT_MS= # Vercel AI SDK internal retries per embedding call. Defaults to 0 (disabled): # the embedding worker's own requeue + pool-wide rate-limit backoff are the # single retry authority, so the SDK ladder just multiplies calls during a # provider 429. Set >0 to re-enable (the SDK's own default is 2). # EMBEDDING_MAX_RETRIES= # Max concurrent chunk requests for batch embedding (default: Infinity) # EMBEDDING_MAX_PARALLEL_CALLS= # Worker threads used for OpenAI tokenization/truncation before embedding. # Defaults to auto-size: max(1, min(available CPU cores - 1, 4)). Set 0 to run # tokenization inline (useful for tests or very small self-host environments). # EMBEDDING_TOKENIZE_THREADS= # ----------------------------------------------------------------------------- # Optional — Embedding Worker # ----------------------------------------------------------------------------- # Number of concurrent embedding workers # WORKER_COUNT=2 # Queue entries to claim per batch # WORKER_BATCH_SIZE=10 # PostgreSQL interval for claim lock duration # WORKER_LOCK_DURATION=5 minutes # Poll interval when idle (ms) # WORKER_IDLE_DELAY_MS=10000 # Max error backoff (ms) # WORKER_MAX_BACKOFF_MS=60000 # Space re-discovery interval (ms) # WORKER_REFRESH_INTERVAL_MS=60000 # ----------------------------------------------------------------------------- # Optional — Embedding Worker Database Pool # ----------------------------------------------------------------------------- # The embedding worker uses a dedicated pool. Each setting defaults to the # corresponding application-pool value (or DATABASE_URL) when unset. # WORKER_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres # Defaults to max(WORKER_COUNT, 1), not a fixed 2. # WORKER_DB_POOL_MAX=2 # WORKER_DB_POOL_IDLE_REAP_SECONDS=300 # WORKER_DB_POOL_MAX_LIFETIME=0 # WORKER_DB_POOL_CONNECTION_TIMEOUT=30 # Per-transaction timeouts for the worker pool (default to built-in values). # WORKER_DB_STATEMENT_TIMEOUT=25s # WORKER_DB_LOCK_TIMEOUT=5s # WORKER_DB_TRANSACTION_TIMEOUT=30s # WORKER_DB_IDLE_IN_TRANSACTION_SESSION_TIMEOUT=30s