Database
SessionManager#
genai_monitor.db.config.SessionManager
#
Manages the database engine and provides session management.
Source code in src/genai_monitor/db/config.py
initialize
#
initialize(
database_url: str = DEFAULT_DATABASE_URL,
) -> SessionManager
Initializes the database engine and session factory. This should be called once on application start.
PARAMETER | DESCRIPTION |
---|---|
database_url
|
The URL for the database connection. Defaults to sqlite:///genai_eval.db.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SessionManager
|
The |
Source code in src/genai_monitor/db/config.py
session_scope
#
Provide a transactional scope around a series of operations. Commits or rolls back on error.
RAISES | DESCRIPTION |
---|---|
Exception
|
on any error during database transaction |
ConnectionError
|
if the database connection has not been initialized yet |
YIELDS | DESCRIPTION |
---|---|
Session
|
The database connection session |
Source code in src/genai_monitor/db/config.py
Database Manager#
genai_monitor.db.manager.DBManager
#
A database manager class.
Class provides basic operations for saving, updating and searching records in the database using SQLAlchemy ORM models.
session_manager
class-attribute
instance-attribute
#
session_manager: Optional[SessionManager] = None
save
#
Saves an instance of a model to the database.
PARAMETER | DESCRIPTION |
---|---|
instance
|
The ORM model instance to be saved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BaseModel
|
The saved ORM model instance. |
Source code in src/genai_monitor/db/manager.py
search
#
Searches for records in the database that match the given filters.
PARAMETER | DESCRIPTION |
---|---|
model
|
The ORM model class representing the database table to search.
TYPE:
|
filters
|
Dictionary of filter criteria to locate specific records.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sequence[Row]
|
A sequence of rows matching the filter criteria. |
Source code in src/genai_monitor/db/manager.py
update
#
update(
instance: Optional[BaseModel] = None,
model: Optional[Type[BaseModel]] = None,
filters: Optional[Dict[str, Any]] = None,
values: Optional[Dict[str, Any]] = None,
) -> Union[BaseModel, Sequence[Row]]
Updates records in the database.
If an instance is provided, it will be updated directly. Otherwise, model and filter criteria are used to locate records for updating.
PARAMETER | DESCRIPTION |
---|---|
instance
|
An existing ORM model instance to update.
TYPE:
|
model
|
The ORM model class representing the table to update.
TYPE:
|
filters
|
Dictionary of filter criteria to locate records to update.
TYPE:
|
values
|
Dictionary of field names and values to update.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[BaseModel, Sequence[Row]]
|
The updated instance if |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If neither |
Source code in src/genai_monitor/db/manager.py
join_search
#
join_search(
target_model: Type[BaseModel],
join_model: Type[BaseModel],
on_condition: Any,
target_filters: Optional[Dict[str, Any]] = None,
join_filters: Optional[Dict[str, Any]] = None,
) -> Sequence[Row]
Performs a join search between two models based on a join condition and optional filters.
PARAMETER | DESCRIPTION |
---|---|
target_model
|
The ORM model class representing the primary table to search.
TYPE:
|
join_model
|
The ORM model class representing the table to join with.
TYPE:
|
on_condition
|
The join condition specifying how to link the two tables.
TYPE:
|
target_filters
|
Dictionary of filter criteria for the target model.
TYPE:
|
join_filters
|
Dictionary of filter criteria for the join model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sequence[Row]
|
A sequence of rows resulting from the join search, filtered as specified. |
Source code in src/genai_monitor/db/manager.py
Tables#
genai_monitor.db.schemas.tables.ConditioningTable
#
Bases: BaseModel
Database table representing the value of conditioning.
id
class-attribute
instance-attribute
#
type_id
class-attribute
instance-attribute
#
value_metadata
class-attribute
instance-attribute
#
samples
class-attribute
instance-attribute
#
samples: Mapped[List[SampleTable]] = relationship(
back_populates="conditioning"
)
genai_monitor.db.schemas.tables.ConditioningTypeTable
#
genai_monitor.db.schemas.tables.SampleTable
#
Bases: BaseModel
Database table representing the sample - an atomic unit of data in the system.
id
class-attribute
instance-attribute
#
model_id
class-attribute
instance-attribute
#
conditioning_id
class-attribute
instance-attribute
#
user_id
class-attribute
instance-attribute
#
generation_id
class-attribute
instance-attribute
#
conditioning
class-attribute
instance-attribute
#
conditioning: Mapped[ConditioningTable] = relationship(
back_populates="samples"
)
user
class-attribute
instance-attribute
#
user: Mapped[UserTable] = relationship(
back_populates="samples"
)
artifacts
class-attribute
instance-attribute
#
artifacts: Mapped[List[ArtifactTable]] = relationship(
back_populates="sample"
)
genai_monitor.db.schemas.tables.ModelTable
#
Bases: BaseModel
Database table representing the generative model.
id
class-attribute
instance-attribute
#
model_class
class-attribute
instance-attribute
#
checkpoint_location
class-attribute
instance-attribute
#
checkpoint_metadata
class-attribute
instance-attribute
#
training_step
class-attribute
instance-attribute
#
model_metadata
class-attribute
instance-attribute
#
genai_monitor.db.schemas.tables.ConfigurationTable
#
Bases: BaseModel
Database table representing system configuration.
Default values are set at the database level to ensure consistency across all instances.
genai_monitor.db.schemas.tables.UserTable
#
Bases: BaseModel
Database table representing the users.
id
class-attribute
instance-attribute
#
samples
class-attribute
instance-attribute
#
samples: Mapped[List[SampleTable]] = relationship(
back_populates="user"
)
genai_monitor.db.schemas.tables.ArtifactTable
#
Bases: BaseModel
Database table representing the artifact - an atomic unit of data in the system.
id
class-attribute
instance-attribute
#
sample_id
class-attribute
instance-attribute
#
sample
class-attribute
instance-attribute
#
sample: Mapped[SampleTable] = relationship(
back_populates="artifacts"
)