trulens.core.database.sqlalchemy¶
trulens.core.database.sqlalchemy
¶
Classes¶
SQLAlchemyDB
¶
Bases: DB
Database implemented using sqlalchemy.
See abstract class DB for method reference.
Attributes¶
redact_keys
class-attribute
instance-attribute
¶
redact_keys: bool = DEFAULT_DATABASE_REDACT_KEYS
Redact secrets before writing out data.
table_prefix
class-attribute
instance-attribute
¶
table_prefix: str = DEFAULT_DATABASE_PREFIX
The prefix to use for all table names.
DB interface requirement.
engine_params
class-attribute
instance-attribute
¶
SQLAlchemy-related engine params.
session_params
class-attribute
instance-attribute
¶
SQLAlchemy-related session.
session
class-attribute
instance-attribute
¶
session: Optional[sessionmaker] = None
SQLAlchemy session(maker).
orm
instance-attribute
¶
Container of all the ORM classes for this database.
This should be set to a subclass of ORM upon initialization.
Functions¶
from_tru_args
classmethod
¶
from_tru_args(
database_url: Optional[str] = None,
database_engine: Optional[Engine] = None,
database_redact_keys: Optional[
bool
] = DEFAULT_DATABASE_REDACT_KEYS,
database_prefix: Optional[
str
] = DEFAULT_DATABASE_PREFIX,
**kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Process database-related configuration provided to the Tru class to create a database.
Emits warnings if appropriate.
from_db_url
classmethod
¶
from_db_url(
url: str, **kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Create a database for the given url.
PARAMETER | DESCRIPTION |
---|---|
url
|
The database url. This includes database type.
TYPE:
|
kwargs
|
Additional arguments to pass to the database constructor. |
RETURNS | DESCRIPTION |
---|---|
SQLAlchemyDB
|
A database instance. |
from_db_engine
classmethod
¶
from_db_engine(
engine: Engine, **kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Create a database for the given engine. Args: engine: The database engine. kwargs: Additional arguments to pass to the database constructor. Returns: A database instance.
batch_insert_record
¶
update_app_metadata
¶
delete_app
¶
delete_app(app_id: AppID) -> None
Deletes an app from the database based on its app_id.
PARAMETER | DESCRIPTION |
---|---|
app_id
|
The unique identifier of the app to be deleted.
TYPE:
|
insert_feedback_definition
¶
insert_feedback_definition(
feedback_definition: FeedbackDefinition,
) -> FeedbackDefinitionID
get_feedback_defs
¶
get_feedback_defs(
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
) -> DataFrame
See DB.get_feedback_defs.
insert_feedback
¶
insert_feedback(
feedback_result: FeedbackResult,
) -> FeedbackResultID
See DB.insert_feedback.
batch_insert_feedback
¶
batch_insert_feedback(
feedback_results: List[FeedbackResult],
) -> List[FeedbackResultID]
get_feedback_count_by_status
¶
get_feedback_count_by_status(
record_id: Optional[RecordID] = None,
feedback_result_id: Optional[FeedbackResultID] = None,
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
status: Optional[
Union[
FeedbackResultStatus,
Sequence[FeedbackResultStatus],
]
] = None,
last_ts_before: Optional[datetime] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
shuffle: bool = False,
run_location: Optional[FeedbackRunLocation] = None,
) -> Dict[FeedbackResultStatus, int]
get_feedback
¶
get_feedback(
record_id: Optional[RecordID] = None,
feedback_result_id: Optional[FeedbackResultID] = None,
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
status: Optional[
Union[
FeedbackResultStatus,
Sequence[FeedbackResultStatus],
]
] = None,
last_ts_before: Optional[datetime] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
shuffle: Optional[bool] = False,
run_location: Optional[FeedbackRunLocation] = None,
) -> DataFrame
See DB.get_feedback.
get_records_and_feedback
¶
insert_ground_truth
¶
insert_ground_truth(
ground_truth: GroundTruth,
) -> GroundTruthID
batch_insert_ground_truth
¶
batch_insert_ground_truth(
ground_truths: List[GroundTruth],
) -> List[GroundTruthID]
get_ground_truth
¶
See DB.get_ground_truth.
get_ground_truths_by_dataset
¶
AppsExtractor
¶
Utilities for creating dataframes from orm instances.
Functions¶
get_df_and_cols
¶
get_df_and_cols(
apps: Optional[List["db_orm.ORM.AppDefinition"]] = None,
records: Optional[List["db_orm.ORM.Record"]] = None,
) -> Tuple[DataFrame, Sequence[str]]
Produces a records dataframe which joins in information from apps and feedback results.
PARAMETER | DESCRIPTION |
---|---|
apps
|
If given, includes all records of all of the apps in this iterable.
TYPE:
|
records
|
If given, includes only these records. Mutually exclusive
with |