Index
trulens_eval.database.base
¶
Attributes¶
DEFAULT_DATABASE_PREFIX
module-attribute
¶
DEFAULT_DATABASE_PREFIX: str = 'trulens_'
Default prefix for table names for trulens_eval to use.
This includes alembic's version table.
DEFAULT_DATABASE_FILE
module-attribute
¶
DEFAULT_DATABASE_FILE: str = 'default.sqlite'
Filename for default sqlite database.
The sqlalchemy url for this default local sqlite database is sqlite:///default.sqlite
.
DEFAULT_DATABASE_REDACT_KEYS
module-attribute
¶
DEFAULT_DATABASE_REDACT_KEYS: bool = False
Default value for option to redact secrets before writing out data to database.
Classes¶
DB
¶
Bases: SerialModel
, ABC
Abstract definition of databases used by trulens_eval.
SQLAlchemyDB is the main and default implementation of this interface.
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
Prefix for table names for trulens_eval to use.
May be useful in some databases where trulens is not the only app.
Functions¶
migrate_database
abstractmethod
¶
Migrade the stored data to the current configuration of the database.
PARAMETER | DESCRIPTION |
---|---|
prior_prefix |
If given, the database is assumed to have been
reconfigured from a database with the given prefix. If not
given, it may be guessed if there is only one table in the
database with the suffix |
check_db_revision
abstractmethod
¶
check_db_revision()
Check that the database is up to date with the current trulens_eval version.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the database is not up to date. |
insert_record
abstractmethod
¶
insert_record(record: Record) -> RecordID
Upsert a record
into the database.
PARAMETER | DESCRIPTION |
---|---|
record |
The record to insert or update.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
RecordID
|
The id of the given record. |
insert_app
abstractmethod
¶
insert_app(app: AppDefinition) -> AppID
Upsert an app
into the database.
PARAMETER | DESCRIPTION |
---|---|
app |
The app to insert or update. Note that only the AppDefinition parts are serialized hence the type hint.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AppID
|
The id of the given app. |
insert_feedback_definition
abstractmethod
¶
insert_feedback_definition(feedback_definition: FeedbackDefinition) -> FeedbackDefinitionID
Upsert a feedback_definition
into the databaase.
PARAMETER | DESCRIPTION |
---|---|
feedback_definition |
The feedback definition to insert or update. Note that only the FeedbackDefinition parts are serialized hence the type hint.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FeedbackDefinitionID
|
The id of the given feedback definition. |
get_feedback_defs
abstractmethod
¶
Retrieve feedback definitions from the database.
PARAMETER | DESCRIPTION |
---|---|
feedback_definition_id |
if provided, only the feedback definition with the given id is returned. Otherwise, all feedback definitions are returned.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
A dataframe with the feedback definitions. |
insert_feedback
abstractmethod
¶
insert_feedback(feedback_result: FeedbackResult) -> FeedbackResultID
Upsert a feedback_result
into the the database.
PARAMETER | DESCRIPTION |
---|---|
feedback_result |
The feedback result to insert or update.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FeedbackResultID
|
The id of the given feedback result. |
get_feedback
abstractmethod
¶
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] = None) -> DataFrame
Get feedback results matching a set of optional criteria:
PARAMETER | DESCRIPTION |
---|---|
record_id |
Get only the feedback for the given record id.
TYPE:
|
feedback_result_id |
Get only the feedback for the given feedback result id.
TYPE:
|
feedback_definition_id |
Get only the feedback for the given feedback definition id.
TYPE:
|
status |
Get only the feedback with the given status. If a sequence of statuses is given, all feedback with any of the given statuses are returned.
TYPE:
|
last_ts_before |
get only results with |
offset |
index of the first row to return. |
limit |
limit the number of rows returned. |
shuffle |
shuffle the rows before returning them. |
get_feedback_count_by_status
abstractmethod
¶
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) -> Dict[FeedbackResultStatus, int]
Get count of feedback results matching a set of optional criteria grouped by their status.
See get_feedback for the meaning of the the arguments.
RETURNS | DESCRIPTION |
---|---|
Dict[FeedbackResultStatus, int]
|
A mapping of status to the count of feedback results of that status that match the given filters. |
get_app
abstractmethod
¶
Get the app with the given id from the database.
RETURNS | DESCRIPTION |
---|---|
Optional[JSONized[App]]
|
The jsonized version of the app with the given id. Deserialization can be done with App.model_validate. |