options.base_options

source

This module contains the BaseOptions class that defines configuration settings for all experiments in lettuce. It handles initialization, validation, and management of various configuration options, particularly focusing on database connections, LLM model settings, embedding configurations, and inference parameters.

The class uses Pydantic BaseSettings to automatically load configuration from environment variables and .env files, providing a robust and type-safe configuration management system.

Classes

BaseOptions

class BaseOptions(BaseSettings)

A configuration settings class for the lettuce pipeline that manages all configuration options including database connections, LLM model settings, embedding configurations, and inference parameters. It uses Pydantic BaseSettings to handle environment variable loading and configuration validation with sensible defaults for all configuration options.

Configuration Fields

Database Configuration
FieldEnvironment VariableTypeDefaultDescription
db_hostDB_HOSTstr"localhost"Database host address
db_userDB_USERstr"postgres"Database username
db_passwordDB_PASSWORDstr"password"Database password
db_nameDB_NAMEstr"omop"Database name
db_portDB_PORTint5432Database port
db_schemaDB_SCHEMAstr"cdm"Database schema name
db_vectableDB_VECTABLEstr"embeddings"Name of the vector embeddings table
db_vecsizeDB_VECSIZEint384Dimension size of embedding vectors
Inference Configuration
FieldEnvironment VariableTypeDefaultDescription
inference_typeINFERENCE_TYPEInferenceTypeInferenceType.OLLAMAType of inference backend to use
ollama_urlOLLAMA_URLstr"http://localhost:11434"URL for Ollama server
LLM Model Configuration
FieldEnvironment VariableTypeDefaultDescription
llm_modelLLM_MODELLLMModelLLMModel.LLAMA_3_1_8BLLM model to use for inference
temperatureTEMPERATUREfloat0.0Sampling temperature for LLM generation
local_llmLOCAL_LLMstr | NoneNonePath to local LLM weights file
debug_promptDEBUG_PROMPTboolFalseEnable prompt debugging output
Embedding Configuration
FieldEnvironment VariableTypeDefaultDescription
embedding_modelEMBEDDING_MODELEmbeddingModelNameEmbeddingModelName.BGESMALLEmbedding model to use
embedding_top_kEMBEDDING_TOP_Kint5Number of top embeddings to retrieve
Authentication
FieldEnvironment VariableTypeDefaultDescription
auth_api_keyAUTH_API_KEYstr | NoneNoneAPI key for authentication

Methods

connection_url
def connection_url() -> str:

Generate a PostgreSQL connection URL from the database configuration. Constructs a connection string in the format required by SQLAlchemy and other database libraries using the configured database parameters.

Returns

str

PostgreSQL connection URL in the format: “postgresql://user:password@host:port/database”

Examples
settings = BaseOptions()
settings.connection_url()
'postgresql://postgres:password@localhost:5432/omop'
print
def print() -> None:

Print all configuration settings in a formatted display. Outputs all current configuration values in a readable format, useful for debugging and verification of loaded settings.

Examples
settings = BaseOptions()
settings.print()
------------ Options -------------
db_host: localhost
db_user: postgres
db_password: password
...
-------------- End ---------------

Environment Variables

The BaseOptions class automatically loads configuration from environment variables and .env files. Environment variables should be prefixed with the field name in uppercase:

Using .env Files

If you have configuration different from the defaults, create a .env file in your project root:

DB_HOST=my-database-server
DB_USER=myuser
DB_PASSWORD=mypassword
LLM_MODEL=LLAMA_3_1_8B
TEMPERATURE=0.7

The configuration will be automatically loaded:

settings = BaseOptions()