Database
SessionManager#
    Manages the database engine and provides session management.
Source code in src/genai_monitor/db/config.py
                    
                  
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
              
    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#
    A database manager class.
Class provides basic operations for saving, updating and searching records in the database using SQLAlchemy ORM models.
class-attribute
      instance-attribute
  
#
session_manager: Optional[SessionManager] = None
    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
              
    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(
    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(
    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#
    
              Bases: BaseModel
Database table representing the value of conditioning.
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
samples: Mapped[List[SampleTable]] = relationship(
    back_populates="conditioning"
)
    
    
              Bases: BaseModel
Database table representing the sample - an atomic unit of data in the system.
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
conditioning: Mapped[ConditioningTable] = relationship(
    back_populates="samples"
)
class-attribute
      instance-attribute
  
#
user: Mapped[UserTable] = relationship(
    back_populates="samples"
)
class-attribute
      instance-attribute
  
#
artifacts: Mapped[List[ArtifactTable]] = relationship(
    back_populates="sample"
)
    
              Bases: BaseModel
Database table representing the generative model.
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
    
              Bases: BaseModel
Database table representing system configuration.
Default values are set at the database level to ensure consistency across all instances.
    
              Bases: BaseModel
Database table representing the users.
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
samples: Mapped[List[SampleTable]] = relationship(
    back_populates="user"
)
    
              Bases: BaseModel
Database table representing the artifact - an atomic unit of data in the system.
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
    
class-attribute
      instance-attribute
  
#
sample: Mapped[SampleTable] = relationship(
    back_populates="artifacts"
)