Config
clear_session(free_memory=True)
Resets all state generated by synalinks.
synalinks manages a global state, which it uses to implement the Functional model-building API and to uniquify autogenerated modules names.
If you are creating many models in a loop, this global state will consume
an increasing amount of memory over time, and you may want to clear it.
Calling clear_session() releases the global state: this helps avoid
clutter from old programs and modules, especially when memory is limited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
free_memory
|
bool
|
Whether to call Python garbage collection.
It's usually a good practice to call it to make sure
memory used by deleted objects is immediately freed.
However, it may take a few seconds to execute, so
when using |
True
|
Source code in synalinks/src/backend/common/global_state.py
SynalinksFileFormatter
Bases: Formatter
Formatter for file logging that removes ANSI escape codes.
Source code in synalinks/src/backend/config.py
SynalinksLogFormatter
Bases: Formatter
Formatter for console logging with colors and prefix.
Source code in synalinks/src/backend/config.py
api_base()
Returns the Synalinks api base
Returns:
| Type | Description |
|---|---|
str
|
The observability api base |
Source code in synalinks/src/backend/config.py
api_key()
Synalinks API key.
Returns:
| Type | Description |
|---|---|
str
|
Synalinks API key. |
Source code in synalinks/src/backend/config.py
backend()
Publicly accessible method for determining the current backend.
Returns:
| Type | Description |
|---|---|
str
|
The name of the backend synalinks is currently using. like
|
Example:
Source code in synalinks/src/backend/config.py
default_embedding_model()
Return the default EmbeddingModel instance, or None if unset.
Source code in synalinks/src/backend/config.py
default_knowledge_base()
Return the default KnowledgeBase instance, or None if unset.
Source code in synalinks/src/backend/config.py
default_language_model()
Return the default LanguageModel instance, or None if unset.
The instance is constructed lazily on first call when set from a
persisted identifier (e.g. via ~/.synalinks/synalinks.json).
Source code in synalinks/src/backend/config.py
enable_logging(log_level='debug', log_to_file=False)
Configures and enables logging for the application.
This function sets up the logging configuration for the application, allowing logs to be output either to a specified file or to the console. The logging level can be set to DEBUG for more verbose logging or INFO for standard logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level
|
str
|
The logging level. |
'debug'
|
log_to_file
|
bool
|
If True save the logs into |
False
|
The log message format includes the timestamp, log level, and the log message itself.
Source code in synalinks/src/backend/config.py
enable_observability(tracking_uri=None, experiment_name=None)
Configures and enables observability for the application using MLflow.
This function sets up the observability configuration for the application, enabling tracing of module calls via MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracking_uri
|
str
|
Optional. The MLflow tracking server URI. If not provided, MLflow will use the default (local ./mlruns directory or MLFLOW_TRACKING_URI environment variable). |
None
|
experiment_name
|
str
|
Optional. The MLflow experiment name. Defaults to "synalinks_traces". |
None
|
Example:
import synalinks
# Basic usage with defaults
synalinks.enable_observability()
# With custom MLflow tracking server
synalinks.enable_observability(
tracking_uri="http://localhost:5000",
experiment_name="my_experiment"
)
Source code in synalinks/src/backend/config.py
epsilon()
Return the value of the fuzz factor used in numeric expressions.
Returns:
| Type | Description |
|---|---|
float
|
The epsilon value. |
Example:
Source code in synalinks/src/backend/config.py
floatx()
Return the default float type, as a string.
E.g. 'bfloat16', 'float16', 'float32', 'float64'.
Returns:
| Type | Description |
|---|---|
str
|
The current default float type. |
Example:
Source code in synalinks/src/backend/config.py
is_observability_enabled()
Check if the observability is enabled
Returns:
| Type | Description |
|---|---|
bool
|
True if the observability is enabled. |
Source code in synalinks/src/backend/config.py
is_trace_recording_enabled()
Check if the trace recording is enabled
Returns:
| Type | Description |
|---|---|
bool
|
True if the trace recording is enabled. |
Source code in synalinks/src/backend/config.py
mlflow_experiment_name()
Returns the MLflow experiment name for observability.
Returns:
| Type | Description |
|---|---|
str
|
The MLflow experiment name. |
Source code in synalinks/src/backend/config.py
mlflow_tracking_uri()
Returns the MLflow tracking URI for observability.
Returns:
| Type | Description |
|---|---|
str
|
The MLflow tracking URI, or None if not set. |
Source code in synalinks/src/backend/config.py
record_traces(base_dir=None)
Enables trace recording of LanguageModel calls.
This function enables the Recorder hook for every module, recording
each LM call (chat messages, completion, token usage, cost ...) as one
JSON line under base_dir, organized as one folder per program and one
subfolder per originating module. Useful to collect training data.
Call it at the beginning of your scripts, before creating your modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
str
|
Optional. The root folder where the records are
written. If not provided, uses |
None
|
Example:
import synalinks
# Basic usage: records under ~/.synalinks
synalinks.record_traces()
# With a custom folder
synalinks.record_traces(base_dir="./traces")
Source code in synalinks/src/backend/config.py
set_api_base(api_base)
Set the observability api base
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_base
|
str
|
The observability api base |
required |
Source code in synalinks/src/backend/config.py
set_api_key(key)
Set Synalinks API key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The API key value. |
required |
The API key is retrieved from the env variables at start.
Or you can setup it using the config
>>> synalinks.config.set_api_key('my-secret-api-key')
>>> synalinks.config.api_key()
'my-secret-api-key'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Synalinks API key. |
required |
Source code in synalinks/src/backend/config.py
set_default_embedding_model(identifier)
Set the default EmbeddingModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str | dict | EmbeddingModel | None
|
A model string
(e.g. |
required |
Source code in synalinks/src/backend/config.py
set_default_knowledge_base(identifier)
Set the default KnowledgeBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str | dict | KnowledgeBase | None
|
A URI string
(e.g. |
required |
Source code in synalinks/src/backend/config.py
set_default_language_model(identifier)
Set the default LanguageModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str | dict | LanguageModel | None
|
A model string
(e.g. |
required |
Source code in synalinks/src/backend/config.py
set_epsilon(value)
Set the value of the fuzz factor used in numeric expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The new value of epsilon. |
required |
Examples:
Source code in synalinks/src/backend/config.py
set_floatx(value)
Set the default float dtype.
Note: It is not recommended to set this to "float16",
as this will likely cause numeric stability issues.
Instead, use float64 or float32.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The float type between |
required |
Examples:
Raises:
| Type | Description |
|---|---|
ValueError
|
In case of invalid value. |
Source code in synalinks/src/backend/config.py
set_seed(value)
Set the value of the random seed for reproductability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The new value of epsilon. |
required |
Source code in synalinks/src/backend/config.py
trace_recording_dir()
Returns the root folder where the trace records are written.
Returns:
| Type | Description |
|---|---|
str
|
The folder set via |