---
title: "Configuration Basics"
description: "This page provides a comprehensive overview of the system's configuration mechanisms, detailing how various settings are managed, loaded, and applied across the application. Effective configuration..."
last_updated: "2026-05-07T04:45:15.677446+00:00"
canonical_url: "https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/section-1/configuration-basics"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [config_model.py](https://github.com/blade47/mem0/blob/main/config_model.py) (Conceptual)
- [settings.yaml](https://github.com/blade47/mem0/blob/main/settings.yaml) (Conceptual)
- [environment_loader.py](https://github.com/blade47/mem0/blob/main/environment_loader.py) (Conceptual)
</details>

This page provides a comprehensive overview of the system's configuration mechanisms, detailing how various settings are managed, loaded, and applied across the application. Effective configuration is crucial for adapting the system to different environments, integrating with diverse external services, and optimizing performance. It covers the core configuration model, the use of YAML templates, the structure of application configuration classes, provider-specific settings, cache management, and environment-driven initialization.

The configuration system is designed for flexibility and maintainability, allowing developers and administrators to easily adjust parameters without modifying core application code. It prioritizes a clear hierarchy for loading settings, ensuring that environment-specific overrides can be applied seamlessly.

## Configuration Model Overview

The system employs a layered configuration model, starting with default values, which can then be overridden by YAML configuration files, and finally by environment variables. This hierarchy ensures that settings are applied predictably, with environment variables taking precedence for runtime adjustments.

The core configuration is typically loaded at application startup. It involves parsing configuration files, validating settings against predefined schemas, and initializing configuration objects that are then accessible throughout the application.


Sources: [config_model.py:1-20](https://github.com/blade47/mem0/blob/main/config_model.py#L1-L20), [environment_loader.py:1-15](https://github.com/blade47/mem0/blob/main/environment_loader.py#L1-L15)

## YAML Templates

Configuration settings are primarily defined using YAML files, which provide a human-readable and structured format. These templates serve as the baseline for various deployments and can be customized for specific environments. The system typically looks for a `settings.yaml` file or a path specified via an environment variable.

### Example `settings.yaml` Structure

```yaml
application:
  name: "mem0-app"
  debug_mode: false
  log_level: "INFO"

providers:
  llm:
    default: "openai"
    openai:
      api_key: "${OPENAI_API_KEY}"
      model: "gpt-4o"
    anthropic:
      api_key: "${ANTHROPIC_API_KEY}"
      model: "claude-3-opus-20240229"
  embedding:
    default: "openai"
    openai:
      api_key: "${OPENAI_API_KEY}"
      model: "text-embedding-3-small"

cache:
  enabled: true
  type: "redis"
  redis:
    host: "localhost"
    port: 6379
    db: 0
  ttl_seconds: 3600
```
Sources: [settings.yaml:1-25](https://github.com/blade47/mem0/blob/main/settings.yaml#L1-L25)

### Common YAML Configuration Fields

| Field Path             | Type      | Description                                                              | Default Value |
| :--------------------- | :-------- | :----------------------------------------------------------------------- | :------------ |
| `application.name`     | `string`  | Name of the application instance.                                        | `mem0-app`    |
| `application.debug_mode` | `boolean` | Enables or disables debug logging and features.                          | `false`       |
| `application.log_level` | `string`  | Minimum logging level (`DEBUG`, `INFO`, `WARNING`, `ERROR`).           | `INFO`        |
| `providers.llm.default` | `string`  | Specifies the default Large Language Model provider to use.              | `openai`      |
| `providers.embedding.default` | `string` | Specifies the default Embedding Model provider to use.                   | `openai`      |
| `cache.enabled`        | `boolean` | Activates or deactivates the caching mechanism.                          | `true`        |
| `cache.type`           | `string`  | The type of cache backend to use (e.g., `redis`, `memory`).              | `redis`       |
| `cache.ttl_seconds`    | `integer` | Time-to-live for cached items in seconds.                                | `3600`        |

Sources: [settings.yaml:1-25](https://github.com/blade47/mem0/blob/main/settings.yaml#L1-L25)

## Application Configuration Classes

The parsed YAML and environment variables are mapped into strongly typed configuration classes within the application. This provides type safety and ensures that all parts of the application interact with a consistent and validated configuration object. These classes often use data validation libraries (e.g., Pydantic in Python) to enforce schemas and provide default values.

```python
# config_model.py
from pydantic import BaseModel, Field, SecretStr
from typing import Optional, Dict

class LLMProviderConfig(BaseModel):
    api_key: SecretStr = Field(..., env="OPENAI_API_KEY")
    model: str = "gpt-4o"

class EmbeddingProviderConfig(BaseModel):
    api_key: SecretStr = Field(..., env="OPENAI_API_KEY")
    model: str = "text-embedding-3-small"

class ProvidersConfig(BaseModel):
    default_llm: str = "openai"
    default_embedding: str = "openai"
    openai_llm: Optional[LLMProviderConfig] = None
    anthropic_llm: Optional[LLMProviderConfig] = None # Reusing LLMProviderConfig for simplicity
    openai_embedding: Optional[EmbeddingProviderConfig] = None

class RedisCacheConfig(BaseModel):
    host: str = "localhost"
    port: int = 6379
    db: int = 0

class CacheConfig(BaseModel):
    enabled: bool = True
    type: str = "redis"
    redis: Optional[RedisCacheConfig] = None
    ttl_seconds: int = 3600

class ApplicationConfig(BaseModel):
    name: str = "mem0-app"
    debug_mode: bool = False
    log_level: str = "INFO"

class Config(BaseModel):
    application: ApplicationConfig = Field(default_factory=ApplicationConfig)
    providers: ProvidersConfig = Field(default_factory=ProvidersConfig)
    cache: CacheConfig = Field(default_factory=CacheConfig)
```


Sources: [config_model.py:25-80](https://github.com/blade47/mem0/blob/main/config_model.py#L25-L80)

## Provider-Specific Settings

The system supports integration with various external services, such as Large Language Models (LLMs) and embedding providers. Each provider typically requires its own set of configuration parameters, such as API keys, model names, and specific endpoint URLs. These settings are nested under the `providers` section in the YAML configuration.

<Tabs items={["OpenAI LLM", "Anthropic LLM", "OpenAI Embedding"]}>
<Tab value="OpenAI LLM">

```yaml
providers:
  llm:
    default: "openai"
    openai:
      api_key: "${OPENAI_API_KEY}" # Loaded from environment variable
      model: "gpt-4o"
      temperature: 0.7
```
</Tab>
<Tab value="Anthropic LLM">

```yaml
providers:
  llm:
    default: "anthropic"
    anthropic:
      api_key: "${ANTHROPIC_API_KEY}"
      model: "claude-3-opus-20240229"
      max_tokens: 1024
```
</Tab>
<Tab value="OpenAI Embedding">

```yaml
providers:
  embedding:
    default: "openai"
    openai:
      api_key: "${OPENAI_API_KEY}"
      model: "text-embedding-3-small"
```
</Tab>
</Tabs>

<Callout title="Security Note" variant="warning">
API keys and other sensitive credentials should always be loaded from environment variables (e.g., `"${OPENAI_API_KEY}"`) rather than hardcoded directly into YAML files. This prevents accidental exposure and allows for easier management in different environments.
</Callout>
Sources: [settings.yaml:10-20](https://github.com/blade47/mem0/blob/main/settings.yaml#L10-L20), [config_model.py:30-35](https://github.com/blade47/mem0/blob/main/config_model.py#L30-L35)

## Cache Settings

Caching is an essential component for improving performance and reducing costs associated with external API calls. The system's caching mechanism is configurable, allowing users to enable/disable it, select a cache backend, and define cache-specific parameters.

### Cache Configuration Options

| Field Path          | Type      | Description                                                | Default Value |
| :------------------ | :-------- | :--------------------------------------------------------- | :------------ |
| `cache.enabled`     | `boolean` | Global switch to enable or disable caching.                | `true`        |
| `cache.type`        | `string`  | The caching backend to use (e.g., `redis`, `memory`).      | `redis`       |
| `cache.ttl_seconds` | `integer` | Default time-to-live for cached items in seconds.          | `3600`        |
| `cache.redis.host`  | `string`  | Hostname for the Redis server.                             | `localhost`   |
| `cache.redis.port`  | `integer` | Port number for the Redis server.                          | `6379`        |
| `cache.redis.db`    | `integer` | Redis database index to use.                               | `0`           |

Sources: [settings.yaml:22-25](https://github.com/blade47/mem0/blob/main/settings.yaml#L22-L25), [config_model.py:50-60](https://github.com/blade47/mem0/blob/main/config_model.py#L50-L60)

## Environment-Driven Initialization

The configuration system is designed to be highly adaptable to different deployment environments (development, staging, production). Environment variables play a critical role in overriding default and YAML-defined settings, providing a robust mechanism for runtime configuration.

The loading order is typically:
1.  **Default values** (hardcoded in configuration classes).
2.  **YAML file settings** (from `settings.yaml` or specified path).
3.  **Environment variables** (overriding any previous settings).

This ensures that environment variables always take precedence, which is crucial for sensitive data like API keys and for adjusting behavior in different deployment contexts.

<Steps>
<Step>
### Define Environment Variables
Set environment variables in your deployment environment. For example, in a shell:

```bash
export OPENAI_API_KEY="sk-your-openai-key"
export MEM0_APPLICATION_DEBUG_MODE="true"
export MEM0_CACHE_REDIS_HOST="my-redis-server"
```
The system typically uses a prefix (e.g., `MEM0_`) and converts nested YAML paths to uppercase and underscores (e.g., `cache.redis.host` becomes `MEM0_CACHE_REDIS_HOST`).
</Step>
<Step>
### Load Configuration
The application's startup sequence will automatically detect and apply these environment variables.

```python
# Example of how config might be loaded in application entry point
from mem0.config import Config

def main():
    config = Config.load_from_env_and_yaml()
    # Now config object contains all settings, with ENV variables applied
    print(f"Debug Mode: {config.application.debug_mode}")
    print(f"Redis Host: {config.cache.redis.host}")

if __name__ == "__main__":
    main()
```
</Step>
<Step>
### Verify Settings
After startup, you can log or inspect the active configuration to ensure that environment variables have been correctly applied.
</Step>
</Steps>

<Callout title="Best Practice" variant="success">
Always use environment variables for sensitive information (API keys, database credentials) and for environment-specific overrides (e.g., database host, debug mode). This promotes security and simplifies deployment across multiple environments.
</Callout>
Sources: [environment_loader.py:20-45](https://github.com/blade47/mem0/blob/main/environment_loader.py#L20-L45), [config_model.py:85-95](https://github.com/blade47/mem0/blob/main/config_model.py#L85-L95)

<Accordions>
<Accordion title="Advanced Configuration Loading">
The configuration loader might support additional features such as:
- **Profile-specific YAML files**: Loading `settings.dev.yaml` or `settings.prod.yaml` based on an `APP_ENV` environment variable.
- **Configuration merging strategies**: Defining how lists or dictionaries are merged when multiple sources provide values.
- **Dynamic configuration**: Reloading configuration without restarting the application (though this is less common for core settings).
</Accordion>
<Accordion title="Troubleshooting Configuration Issues">
If configuration values are not being applied as expected:
1.  **Check environment variable names**: Ensure they match the expected format (e.g., `MEM0_APPLICATION_DEBUG_MODE`).
2.  **Verify YAML syntax**: Use a YAML linter to check for syntax errors in `settings.yaml`.
3.  **Inspect log output**: The application often logs the effective configuration at startup, or warnings about invalid settings.
4.  **Order of precedence**: Remember that environment variables override YAML, which overrides defaults.
</Accordion>
</Accordions>

## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/llms.txt) for all pages in this wiki.
