Context

class sycamore.context.Context(exec_mode: ~sycamore.context.ExecMode = ExecMode.RAY, ray_args: dict[str, ~typing.Any] | None = None, rewrite_rules: list[~typing.Callable[[~sycamore.plan_nodes.Node], ~sycamore.plan_nodes.Node] | ~sycamore.plan_nodes.NodeTraverse] = <factory>, params: dict[str, ~typing.Any] = <factory>)[source]

A class to implement a Sycamore Context, which initializes a Ray Worker and provides the ability to read data into a DocSet

ray_args = None

Type:    Optional[dict[str, Any]]

Allows for the registration of Rules in the Sycamore Context that allow for transforming the nodes before execution. These rules can optimize ray execution or perform other manipulations.

rewrite_rules

Type:    list[Union[Callable[[Node], Node], NodeTraverse]]

Define parameters for global usage

enum sycamore.context.ExecMode(value)[source]

Valid values are as follows:

UNKNOWN = <ExecMode.UNKNOWN: 0>
RAY = <ExecMode.RAY: 1>
LOCAL = <ExecMode.LOCAL: 2>
enum sycamore.context.OperationTypes(value)[source]

Valid values are as follows:

DEFAULT = <OperationTypes.DEFAULT: 'default'>
BINARY_CLASSIFIER = <OperationTypes.BINARY_CLASSIFIER: 'binary_classifier'>
INFORMATION_EXTRACTOR = <OperationTypes.INFORMATION_EXTRACTOR: 'information_extractor'>
TEXT_SIMILARITY = <OperationTypes.TEXT_SIMILARITY: 'text_similarity'>
sycamore.context.context_params(*names)[source]

Applies kwargs from the context to a function call. Requires 'context': Context, to be an argument to the method.

There is a fair bit of complexity regarding arg management but the comments should be clear.

sycamore.context.get_val_from_context(context: Context, val_key: str, param_names: List[str] | None = None, ignore_default: bool = False) Any | None[source]

Helper function: Given a Context object, return the possible value for a given val. This assumes context.params is not a nested dict. @param context: Context to use @param val_key: Key for the value to be returned @param param_names: List of parameter namespaces to look for.

Always uses OperationTypes.DEFAULT unless configured otherwise.

@param ignore_default: disable usage for OperationTypes.DEFAULT parameter namespace @return: Optional value given configs.

sycamore.context.init(exec_mode=ExecMode.RAY, ray_args: dict[str, Any] | None = None, **kwargs) Context[source]

Initialize a new Context.

sycamore.context.modified_context(context: Context, param_name: str, **overrides) Context[source]

Returns a Context just like the one passed in, but with individual values within params[param_name] changed to values from the overrides kwargs. Use param_name 'default' if unsure. Avoids deep-copying anything.