Skip to content

orcalib.curate.memories_handle#

MemoriesHandle #

1
2
3
4
5
6
7
MemoriesHandle(
    database_name,
    index_name=None,
    table_name=None,
    model_id=None,
    model_version=None,
)

A handle to query memories associated with an index used in a model.

Parameters:

  • index_name (str | None, default: None ) –

    The index that the memories are associated with.

  • table_name (str | None, default: None ) –

    The table that the memories are stored in.

  • database_name (str) –

    The name of the database the index is defined on.

  • model_id (str | None, default: None ) –

    The model id to filter the model run memory lookups by.

  • model_version (str | None, default: None ) –

    The model version to filter the model run memory lookups by.

select #

select(*args)

Thin peewee wrapper method for selecting the columns to return.

Parameters:

  • args (str | Column | Alias, default: () ) –

    The columns to select

Returns:

Examples:

>>> my_memories.select("label", "text")

MemoriesSelectQuery #

MemoriesSelectQuery(memories_table, *args)

Bases: BaseSelectQuery

having #

having(*args)

Thin peewee wrapper method for having filters on aggregate function results.

Parameters:

  • args (Any, default: () ) –

    The conditions to filter by

Returns:

  • BaseSelectQuery

    The query object for chaining

Examples:

>>> my_query.having(sql("avg_model_feedback") == 1.0)

limit #

limit(limit)

Thin peewee wrapper method to limit the number of rows returned.

Parameters:

  • limit (int) –

    The maximum number of rows to return

Returns:

  • BaseSelectQuery

    The query object for chaining

Examples:

>>> my_query.limit(5)

offset #

offset(offset)

Thin peewee wrapper method for applying an offset to the query.

Parameters:

  • offset (int) –

    The number of rows to skip

Returns:

  • BaseSelectQuery

    The query object for chaining

Examples:

>>> my_query.offset(5)

order_by #

order_by(*args)

Thin peewee wrapper method for ordering the results.

Parameters:

  • args (Any, default: () ) –

    The columns to order by

Returns:

  • BaseSelectQuery

    The query object for chaining

Examples:

>>> my_query.order_by(runs_handle.id.desc())

where #

where(*args)

Thin peewee wrapper method for filtering the results.

Parameters:

  • args (Any, default: () ) –

    The conditions to filter by

Returns:

  • BaseSelectQuery

    The query object for chaining

Examples:

>>> my_query.where(runs_handle.id == 42)

df #

df(limit=None, offset=None)

Fetch rows from the table and return as a DataFrame

Parameters:

  • limit (int | None, default: None ) –

    The maximum number of rows to return, if None returns all rows

  • offset (int | None, default: None ) –

    The number of rows to skip, if None starts from the beginning

Returns:

  • DataFrame

    A pandas data frame containing the rows

sql #

sql()

Debugging method to get the SQL query and parameters.

Returns:

  • query ( str ) –

    The SQL query

  • params ( tuple[Any, ...] ) –

    The parameters for the query

aggregate_runs #

aggregate_runs(*args)

Thin peewee wrapper method for aggregating the results by runs.

Parameters:

  • args (str | Column | Alias, default: () ) –

    The columns to aggregate by

Returns:

Examples:

>>> my_query.aggregate_runs(
...     fn.count(runs_handle.id).alias("num_runs")
... )

aggregate_feedback #

aggregate_feedback()

Method for aggregating the feedback table values onto a memory.

Returns:

Examples:

>>> my_query.aggregate_feedback()

select_all_feedback #

select_all_feedback()

Method for returning all feedback with the memories. This sets a flag to fetch all feedback.

Returns:

fetch #

fetch(limit=None, offset=None)

Extract the SQL query from peewee and run it through Orca Client to get results.

Parameters:

  • limit (int | None, default: None ) –

    The maximum number of rows to return, if None returns all rows

  • offset (int | None, default: None ) –

    The number of rows to skip, if None starts from the beginning

Returns:

  • list[dict[str, Any]]

    A list of dictionaries mapping column names to values.

Examples:

>>> my_query.fetch(1)
[{'label': 'my_label', 'text': 'my_text', 'avg_feedback': 0.5, 'num_runs': 1}]