base
base
¶
Base class for GlobalLearningStore with connection and schema management.
This module provides the foundational GlobalLearningStoreBase class that handles:
- SQLite database connection management with WAL mode
- Schema creation and migration
- Static hashing utilities for workspace and job identification
Extracted from global_store.py as part of the modularization effort. Mixins inherit from this base to add domain-specific functionality.
Classes¶
WhereBuilder
¶
Accumulates SQL WHERE clauses and their bound parameters.
Provides a consistent pattern for building dynamic SQL queries across learning store mixins. Clauses are joined with AND.
Usage::
wb = WhereBuilder()
wb.add("status = ?", status)
wb.add("score >= ?", min_score)
where_sql, params = wb.build()
conn.execute(f"SELECT * FROM t WHERE {where_sql}", params)
Source code in src/marianne/learning/store/base.py
GlobalLearningStoreBase
¶
SQLite-based global learning store base class.
Provides persistent storage infrastructure for execution outcomes, detected patterns, and error recovery data across all Marianne workspaces. Uses WAL mode for safe concurrent access.
This base class handles: - Database connection lifecycle - Schema version management - Migration and schema creation - Hashing utilities
Subclasses (via mixins) add domain-specific methods for patterns, executions, rate limits, drift detection, escalation, and budget management.
Attributes:
| Name | Type | Description |
|---|---|---|
db_path |
Path to the SQLite database file. |
|
_logger |
Module logger instance for consistent logging. |
Initialize the global learning store.
Creates the database directory if needed, establishes the connection, and runs any necessary migrations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path | None
|
Path to the SQLite database file. Defaults to ~/.marianne/global-learning.db |
None
|
Source code in src/marianne/learning/store/base.py
Functions¶
batch_connection
¶
Reuse a single connection across multiple operations.
While this context manager is active, all _get_connection() calls
will reuse the same connection, avoiding repeated open/close overhead.
The connection is committed once on successful exit or rolled back on error.
Example::
with store.batch_connection():
patterns = store.get_patterns(min_priority=0.01)
for p in patterns:
store.update_trust_score(p.pattern_id, ...)
Yields:
| Type | Description |
|---|---|
Connection
|
The shared sqlite3.Connection instance. |
Source code in src/marianne/learning/store/base.py
close
¶
Close any persistent resources.
No-op: connections are managed per-operation via _get_connection().
This method exists for API compatibility so callers can unconditionally
call store.close() without checking the backend type.
Source code in src/marianne/learning/store/base.py
hash_workspace
staticmethod
¶
Generate a stable hash for a workspace path.
Creates a reproducible 16-character hex hash from the resolved absolute path. This allows pattern matching across sessions while preserving privacy (paths are not stored directly).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_path
|
Path
|
The absolute path to the workspace. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A hex string hash of the workspace path (16 characters). |
Source code in src/marianne/learning/store/base.py
hash_job
staticmethod
¶
Generate a stable hash for a job.
Creates a reproducible 16-character hex hash from the job name and optional config hash. The config hash enables version-awareness: the same job with different configs will have different hashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_name
|
str
|
The job name. |
required |
config_hash
|
str | None
|
Optional hash of the job config for versioning. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A hex string hash of the job (16 characters). |
Source code in src/marianne/learning/store/base.py
clear_all
¶
Clear all data from the global store.
WARNING: This is destructive and should only be used for testing.