Builder
Memory client builder module.
This module provides factory functions for creating memory clients.
build_from_env(api_key=None, instruction=None, host=None)
Create a memory client from environment variables or provided parameters.
Reads configuration from environment variables to create a memory client. Supports MEM0_API_KEY for authentication. If api_key is provided, it takes precedence over the environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str | None
|
API key for authentication. If None, will be read from MEM0_API_KEY environment variable. Defaults to None. |
None
|
instruction |
str | None
|
Custom instructions for memory handling. Defaults to None. |
None
|
host |
str | None
|
Host for the memory client. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseMemoryClient |
BaseMemoryClient
|
The created memory client instance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If API key is not provided and MEM0_API_KEY environment variable is missing. |
ValueError
|
If the provider specified in environment is not supported. |
Modules
build_memory_client
Memory client factory for creating memory providers.
This module implements the Factory pattern to create memory providers, making it easy to switch between different implementations without users needing to know which platform is being used.
References
[1] https://docs.mem0.ai/introduction
build_from_env(api_key=None, instruction=None, host=None)
Create a memory client from environment variables or provided parameters.
Reads configuration from environment variables to create a memory client. Supports MEM0_API_KEY for authentication. If api_key is provided, it takes precedence over the environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str | None
|
API key for authentication. If None, will be read from MEM0_API_KEY environment variable. Defaults to None. |
None
|
instruction |
str | None
|
Custom instructions for memory handling. Defaults to None. |
None
|
host |
str | None
|
Host for the memory client. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseMemoryClient |
BaseMemoryClient
|
The created memory client instance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If API key is not provided and MEM0_API_KEY environment variable is missing. |
ValueError
|
If the provider specified in environment is not supported. |
build_memory_client(provider, **kwargs)
Create a memory client for the specified provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider |
str
|
The name of the memory provider. |
required |
**kwargs |
Additional keyword arguments passed to the client constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseMemoryClient |
BaseMemoryClient
|
The created memory client instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provider is not supported. |