Why environment variables?
Environment variables provide several benefits:- Security: Keep credentials out of version control
- Flexibility: Change settings per environment without code changes
- Portability: Deploy the same config across dev, staging, and production
- CI/CD integration: Inject secrets from vault systems
Variable syntax in configurations
VectorDB supports two environment variable patterns in YAML:Vector database credentials
Pinecone
Weaviate
Weaviate cluster URL including protocol and port.Example:Usage in config:
API key for Weaviate authentication.Example:Usage in config:
Milvus
Milvus connection URI including protocol, host, and port.Example:Usage in config:
Authentication token for Milvus (required for managed instances).Example:Usage in config:
Qdrant
Qdrant server URL including protocol, host, and port.Example:Usage in config:
API key for Qdrant authentication (required for cloud deployments).Example:Usage in config:
Alternative: Qdrant host (used with QDRANT_PORT).Example:
Qdrant port number (used with QDRANT_HOST).Default:
6333Chroma
Chroma server host for client/server mode.Example:Usage in config:
Chroma server port.Example:Default:
8000Directory for Chroma local persistence.Example:Usage in config:
LLM API keys
Groq
OpenAI
API key for OpenAI services.Example:Usage in config:
Cohere
API key for Cohere reranking services.Example:Usage in config:
Application settings
Logging level for the application.Values: Default:
DEBUG, INFO, WARNING, ERROR, CRITICALExample:INFOUsage in config:Deployment environment identifier.Values: Usage in code:
development, staging, productionExample:Enable telemetry and metrics collection.Example:Default:
falseMaximum retry attempts for failed operations.Example:Default:
3Default timeout for API requests in seconds.Example:Default:
30Setting environment variables
Local development (.env file)
Create a.env file in your project root:
.env
Shell export
Docker
Docker Compose
docker-compose.yml
Kubernetes secrets
secrets.yaml
deployment.yaml
GitHub Actions
.github/workflows/test.yml
Environment-specific configuration pattern
Organize variables by environment:Security best practices
Never commit secrets
Never commit secrets
Add environment files to Provide an example file with placeholders:
.gitignore:.gitignore
.env.example
Use secret management systems
Use secret management systems
For production, use dedicated secret management:
- AWS Secrets Manager or Parameter Store
- Google Cloud Secret Manager
- Azure Key Vault
- HashiCorp Vault
- Kubernetes Secrets
Rotate credentials regularly
Rotate credentials regularly
- Set up automatic key rotation (monthly or quarterly)
- Monitor for leaked credentials using tools like GitGuardian
- Revoke old keys after rotation
- Test new credentials before revoking old ones
Validate required variables
Validate required variables
Check that required variables are set at startup:
Troubleshooting
Variable not substituted
Variable not substituted
Symptom: Configuration shows
${VAR_NAME} literal instead of value.Solutions:- Ensure variable is exported:
export VAR_NAME=value - Check variable name spelling matches exactly
- Verify
.envfile is loaded if using python-dotenv - Use default syntax:
${VAR_NAME:-default}to see if default appears
Empty string instead of value
Empty string instead of value
Symptom: Variable resolves to empty string.Solutions:
- Variable is set but empty:
export VAR_NAME= - Use
echo $VAR_NAMEto verify shell environment - Check for typos in variable name
- Ensure export happens before running Python
Wrong environment loaded
Wrong environment loaded
Symptom: Production uses development credentials.Solutions:
- Set
ENVIRONMENTvariable before loading config - Use explicit env file path:
load_dotenv('.env.production') - Check which env file was loaded in logs
- Verify Kubernetes/Docker env injection
Next steps
Configuration reference
See how to use these variables in YAML configs
Production deployment
Learn production secrets management patterns
Building RAG pipelines
Use environment variables in your first pipeline
Benchmarking
Set up evaluation environments