Skip to main content
This guide covers all configuration options available in the SKU Semantic Search application. Configuration is managed through environment variables using Pydantic Settings.

Configuration file

All configuration is defined in app/core/config.py using Pydantic’s BaseSettings class, which automatically loads values from environment variables and .env files.

Environment variables

Application settings

PROJECT_NAME
string
default:"SKU Semantic Search"
The name of the application. This value is used in the FastAPI documentation and API metadata.Status: Optional (has default value)
VERSION
string
default:"1.0.0"
The version of the application. Displayed in API documentation.Status: Optional (has default value)

Database configuration

DATABASE_URL
string
required
PostgreSQL connection string with pgvector extension support.Status: Required
Format: postgresql://username:password@host:port/database
Example: postgresql://user:pass@localhost:5435/skudb
The database must have the pgvector extension installed for vector similarity search to work.

AI provider configuration

GEMINI_API_KEY
string
required
Google Gemini API key for embeddings and text generation.Status: Required
Used for:
  • Generating embeddings via gemini-embedding-001
  • Primary LLM for answer generation (Gemini 2.5 Flash, Gemini Flash Latest, Gemini 2.5 Pro)
Get your key: Google AI Studio
This is the primary API key. If not provided or invalid, the system will fall back to Anthropic, but embeddings will fail.
ANTHROPIC_API_KEY
string
required
Anthropic API key for fallback LLM generation.Status: Required
Used for:
  • Fallback LLM when Gemini fails (Claude 3 Haiku, Claude 3.5 Sonnet)
Get your key: Anthropic Console
The system implements intelligent failover. If Gemini models fail due to rate limits or network issues, Claude models are automatically used.

Security configuration

JWT_SECRET
string
required
Secret key for signing JWT tokens used in authentication.Status: Required
Security: Must be a strong, random string. Never commit this value to version control.
Generate a secure secret:
openssl rand -hex 32
Use a cryptographically secure random string. Weak secrets compromise your entire authentication system.
ALGORITHM
string
default:"HS256"
Algorithm used for JWT token encoding and decoding.Status: Optional (has default value)
Default: HS256
Supported values: HS256, HS384, HS512
ACCESS_TOKEN_EXPIRE_MINUTES
integer
default:"30"
Expiration time for JWT access tokens in minutes.Status: Optional (has default value)
Default: 30 minutes
Shorter expiration times are more secure but require users to log in more frequently. Adjust based on your security requirements.

Setting up your environment

Create a .env file

Create a .env file in the root directory of your project:
# Application
PROJECT_NAME="SKU Semantic Search"
VERSION="1.0.0"

# Database
DATABASE_URL="postgresql://user:password@localhost:5435/skudb"

# AI Providers
GEMINI_API_KEY="your_google_gemini_api_key_here"
ANTHROPIC_API_KEY="your_anthropic_api_key_here"

# Security
JWT_SECRET="your_secure_random_secret_here"
ALGORITHM="HS256"
ACCESS_TOKEN_EXPIRE_MINUTES=30
Never commit your .env file to version control. Add it to .gitignore.

Configuration loading order

Pydantic Settings loads configuration in the following order (later sources override earlier ones):
  1. Default values defined in Settings class
  2. Values from .env file
  3. Environment variables from the system
This allows you to:
  • Use .env for local development
  • Override with system environment variables in production
  • Keep sensible defaults for optional settings

Accessing configuration

Configuration is available throughout the application via the settings singleton:
from app.core.config import settings

# Access any setting
print(settings.PROJECT_NAME)
print(settings.DATABASE_URL)

Production considerations

In production environments (Docker, Kubernetes, cloud platforms), set environment variables directly rather than using .env files. This is more secure and follows twelve-factor app principles.Docker example:
environment:
  - DATABASE_URL=postgresql://user:pass@db:5432/skudb
  - GEMINI_API_KEY=${GEMINI_API_KEY}
  - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
  - JWT_SECRET=${JWT_SECRET}
Regularly rotate your JWT_SECRET and API keys. When rotating JWT secrets:
  1. Generate a new secret
  2. Update the configuration
  3. Restart the application
  4. Users will need to log in again (existing tokens become invalid)
For production deployments, consider using dedicated secret management:
  • AWS Secrets Manager
  • Google Cloud Secret Manager
  • Azure Key Vault
  • HashiCorp Vault
These services provide encryption, access control, and audit logging for sensitive configuration.

Validation

Pydantic automatically validates configuration on startup. If required variables are missing or invalid, the application will fail to start with clear error messages. Example error:
ValidationError: 1 validation error for Settings
DATABASE_URL
  field required (type=value_error.missing)
This fail-fast behavior prevents running the application with incomplete configuration.

Build docs developers (and LLMs) love