abacusai.model ============== .. py:module:: abacusai.model Classes ------- .. autoapisummary:: abacusai.model.Model Module Contents --------------- .. py:class:: Model(client, name=None, modelId=None, modelConfigType=None, modelPredictionConfig=None, createdAt=None, projectId=None, trainFunctionName=None, predictFunctionName=None, predictManyFunctionName=None, initializeFunctionName=None, trainingInputTables=None, sourceCode=None, cpuSize=None, memory=None, trainingFeatureGroupIds=None, algorithmModelConfigs=None, trainingVectorStoreVersions=None, documentRetrievers=None, documentRetrieverIds=None, isPythonModel=None, defaultAlgorithm=None, customAlgorithmConfigs=None, restrictedAlgorithms=None, useGpu=None, notebookId=None, trainingRequired=None, refreshSchedules={}, codeSource={}, databaseConnector={}, dataLlmFeatureGroups={}, latestModelVersion={}, modelConfig={}) Bases: :py:obj:`abacusai.return_class.AbstractApiClass` A model :param client: An authenticated API Client instance :type client: ApiClient :param name: The user-friendly name for the model. :type name: str :param modelId: The unique identifier of the model. :type modelId: str :param modelConfigType: Name of the TrainingConfig class of the model_config. :type modelConfigType: str :param modelPredictionConfig: The prediction config options for the model. :type modelPredictionConfig: dict :param createdAt: Date and time at which the model was created. :type createdAt: str :param projectId: The project this model belongs to. :type projectId: str :param trainFunctionName: Name of the function found in the source code that will be executed to train the model. It is not executed when this function is run. :type trainFunctionName: str :param predictFunctionName: Name of the function found in the source code that will be executed run predictions through model. It is not executed when this function is run. :type predictFunctionName: str :param predictManyFunctionName: Name of the function found in the source code that will be executed to run batch predictions trhough the model. :type predictManyFunctionName: str :param initializeFunctionName: Name of the function found in the source code to initialize the trained model before using it to make predictions using the model :type initializeFunctionName: str :param trainingInputTables: List of feature groups that are supplied to the train function as parameters. Each of the parameters are materialized Dataframes (same type as the functions return value). :type trainingInputTables: list :param sourceCode: Python code used to make the model. :type sourceCode: str :param cpuSize: Cpu size specified for the python model training. :type cpuSize: str :param memory: Memory in GB specified for the python model training. :type memory: int :param trainingFeatureGroupIds: The unique identifiers of the feature groups used as the inputs to train this model on. :type trainingFeatureGroupIds: list of unique string identifiers :param algorithmModelConfigs: List of algorithm specific training configs. :type algorithmModelConfigs: list[dict] :param trainingVectorStoreVersions: The vector store version IDs used as inputs during training to create this ModelVersion. :type trainingVectorStoreVersions: list :param documentRetrievers: List of document retrievers use to create this model. :type documentRetrievers: list :param documentRetrieverIds: List of document retriever IDs used to create this model. :type documentRetrieverIds: list :param isPythonModel: If this model is handled as python model :type isPythonModel: bool :param defaultAlgorithm: If set, this algorithm will always be used when deploying the model regardless of the model metrics :type defaultAlgorithm: str :param customAlgorithmConfigs: User-defined configs for each of the user-defined custom algorithm :type customAlgorithmConfigs: dict :param restrictedAlgorithms: User-selected algorithms to train. :type restrictedAlgorithms: dict :param useGpu: If this model uses gpu. :type useGpu: bool :param notebookId: The notebook associated with this model. :type notebookId: str :param trainingRequired: If training is required to keep the model up-to-date. :type trainingRequired: bool :param latestModelVersion: The latest model version. :type latestModelVersion: ModelVersion :param refreshSchedules: List of refresh schedules that indicate when the next model version will be trained :type refreshSchedules: RefreshSchedule :param codeSource: If a python model, information on the source code :type codeSource: CodeSource :param databaseConnector: Database connector used by the model. :type databaseConnector: DatabaseConnector :param dataLlmFeatureGroups: List of feature groups used by the model for queries :type dataLlmFeatureGroups: FeatureGroup :param modelConfig: The training config options used to train this model. :type modelConfig: TrainingConfig .. py:attribute:: name :value: None .. py:attribute:: model_id :value: None .. py:attribute:: model_config_type :value: None .. py:attribute:: model_prediction_config :value: None .. py:attribute:: created_at :value: None .. py:attribute:: project_id :value: None .. py:attribute:: train_function_name :value: None .. py:attribute:: predict_function_name :value: None .. py:attribute:: predict_many_function_name :value: None .. py:attribute:: initialize_function_name :value: None .. py:attribute:: training_input_tables :value: None .. py:attribute:: source_code :value: None .. py:attribute:: cpu_size :value: None .. py:attribute:: memory :value: None .. py:attribute:: training_feature_group_ids :value: None .. py:attribute:: algorithm_model_configs :value: None .. py:attribute:: training_vector_store_versions :value: None .. py:attribute:: document_retrievers :value: None .. py:attribute:: document_retriever_ids :value: None .. py:attribute:: is_python_model :value: None .. py:attribute:: default_algorithm :value: None .. py:attribute:: custom_algorithm_configs :value: None .. py:attribute:: restricted_algorithms :value: None .. py:attribute:: use_gpu :value: None .. py:attribute:: notebook_id :value: None .. py:attribute:: training_required :value: None .. py:attribute:: refresh_schedules .. py:attribute:: code_source .. py:attribute:: database_connector .. py:attribute:: data_llm_feature_groups .. py:attribute:: latest_model_version .. py:attribute:: model_config .. py:attribute:: deprecated_keys .. py:method:: __repr__() .. py:method:: to_dict() Get a dict representation of the parameters in this class :returns: The dict value representation of the class parameters :rtype: dict .. py:method:: describe_train_test_data_split_feature_group() Get the train and test data split for a trained model by its unique identifier. This is only supported for models with custom algorithms. :param model_id: The unique ID of the model. By default, the latest model version will be returned if no version is specified. :type model_id: str :returns: The feature group containing the training data and fold information. :rtype: FeatureGroup .. py:method:: refresh() Calls describe and refreshes the current object's fields :returns: The current object :rtype: Model .. py:method:: describe() Retrieves a full description of the specified model. :param model_id: Unique string identifier associated with the model. :type model_id: str :returns: Description of the model. :rtype: Model .. py:method:: rename(name) Renames a model :param name: The new name to assign to the model. :type name: str .. py:method:: update_python(function_source_code = None, train_function_name = None, predict_function_name = None, predict_many_function_name = None, initialize_function_name = None, training_input_tables = None, cpu_size = None, memory = None, package_requirements = None, use_gpu = None, is_thread_safe = None, training_config = None) Updates an existing Python Model using user-provided Python code. If a list of input feature groups is supplied, they will be provided as arguments to the `train` and `predict` functions with the materialized feature groups for those input feature groups. This method expects `functionSourceCode` to be a valid language source file which contains the functions named `trainFunctionName` and `predictFunctionName`. `trainFunctionName` returns the ModelVersion that is the result of training the model using `trainFunctionName`. `predictFunctionName` has no well-defined return type, as it returns the prediction made by the `predictFunctionName`, which can be anything. :param function_source_code: Contents of a valid Python source code file. The source code should contain the functions named `trainFunctionName` and `predictFunctionName`. A list of allowed import and system libraries for each language is specified in the user functions documentation section. :type function_source_code: str :param train_function_name: Name of the function found in the source code that will be executed to train the model. It is not executed when this function is run. :type train_function_name: str :param predict_function_name: Name of the function found in the source code that will be executed to run predictions through the model. It is not executed when this function is run. :type predict_function_name: str :param predict_many_function_name: Name of the function found in the source code that will be executed to run batch predictions through the model. It is not executed when this function is run. :type predict_many_function_name: str :param initialize_function_name: Name of the function found in the source code to initialize the trained model before using it to make predictions using the model. :type initialize_function_name: str :param training_input_tables: List of feature groups that are supplied to the `train` function as parameters. Each of the parameters are materialized DataFrames (same type as the functions return value). :type training_input_tables: list :param cpu_size: Size of the CPU for the model training function. :type cpu_size: str :param memory: Memory (in GB) for the model training function. :type memory: int :param package_requirements: List of package requirement strings. For example: `['numpy==1.2.3', 'pandas>=1.4.0']`. :type package_requirements: list :param use_gpu: Whether this model needs gpu :type use_gpu: bool :param is_thread_safe: Whether this model is thread safe :type is_thread_safe: bool :param training_config: The training config used to train this model. :type training_config: TrainingConfig :returns: The updated model. :rtype: Model .. py:method:: set_training_config(training_config, feature_group_ids = None) Edits the default model training config :param training_config: The training config used to train this model. :type training_config: TrainingConfig :param feature_group_ids: The list of feature groups used as input to the model. :type feature_group_ids: List :returns: The model object corresponding to the updated training config. :rtype: Model .. py:method:: set_prediction_params(prediction_config) Sets the model prediction config for the model :param prediction_config: Prediction configuration for the model. :type prediction_config: dict :returns: Model object after the prediction configuration is applied. :rtype: Model .. py:method:: get_metrics(model_version = None, return_graphs = False, validation = False) Retrieves metrics for all the algorithms trained in this model version. If only the model's unique identifier (model_id) is specified, the latest trained version of the model (model_version) is used. :param model_version: Version of the model. :type model_version: str :param return_graphs: If true, will return the information used for the graphs on the model metrics page such as PR Curve per label. :type return_graphs: bool :param validation: If true, will return the validation metrics instead of the test metrics. :type validation: bool :returns: An object containing the model metrics and explanations for what each metric means. :rtype: ModelMetrics .. py:method:: list_versions(limit = 100, start_after_version = None) Retrieves a list of versions for a given model. :param limit: Maximum length of the list of all dataset versions. :type limit: int :param start_after_version: Unique string identifier of the version after which the list starts. :type start_after_version: str :returns: An array of model versions. :rtype: list[ModelVersion] .. py:method:: retrain(deployment_ids = None, feature_group_ids = None, custom_algorithms = None, builtin_algorithms = None, custom_algorithm_configs = None, cpu_size = None, memory = None, training_config = None, algorithm_training_configs = None) Retrains the specified model, with an option to choose the deployments to which the retraining will be deployed. :param deployment_ids: List of unique string identifiers of deployments to automatically deploy to. :type deployment_ids: List :param feature_group_ids: List of feature group IDs provided by the user to train the model on. :type feature_group_ids: List :param custom_algorithms: List of user-defined algorithms to train. If not set, will honor the runs from the last time and applicable new custom algorithms. :type custom_algorithms: list :param builtin_algorithms: List of algorithm names or algorithm IDs of Abacus.AI built-in algorithms to train. If not set, will honor the runs from the last time and applicable new built-in algorithms. :type builtin_algorithms: list :param custom_algorithm_configs: User-defined training configs for each custom algorithm. :type custom_algorithm_configs: dict :param cpu_size: Size of the CPU for the user-defined algorithms during training. :type cpu_size: str :param memory: Memory (in GB) for the user-defined algorithms during training. :type memory: int :param training_config: The training config used to train this model. :type training_config: TrainingConfig :param algorithm_training_configs: List of algorithm specifc training configs that will be part of the model training AutoML run. :type algorithm_training_configs: list :returns: The model that is being retrained. :rtype: Model .. py:method:: delete() Deletes the specified model and all its versions. Models which are currently used in deployments cannot be deleted. :param model_id: Unique string identifier of the model to delete. :type model_id: str .. py:method:: set_default_algorithm(algorithm = None, data_cluster_type = None) Sets the model's algorithm to default for all new deployments :param algorithm: Algorithm to pin in the model. :type algorithm: str :param data_cluster_type: Data cluster type to set the lead model for. :type data_cluster_type: str .. py:method:: list_artifacts_exports(limit = 25) List all the model artifacts exports. :param limit: Maximum length of the list of all exports. :type limit: int :returns: List of model artifacts exports. :rtype: list[ModelArtifactsExport] .. py:method:: get_training_types_for_deployment(model_version = None, algorithm = None) Returns types of models that can be deployed for a given model instance ID. :param model_version: The unique ID associated with the model version to deploy. :type model_version: str :param algorithm: The unique ID associated with the algorithm to deploy. :type algorithm: str :returns: Model training types for deployment. :rtype: ModelTrainingTypeForDeployment .. py:method:: update_agent(function_source_code = None, agent_function_name = None, memory = None, package_requirements = None, description = None, enable_binary_input = None, agent_input_schema = None, agent_output_schema = None, workflow_graph = None, agent_interface = None, included_modules = None, org_level_connectors = None, user_level_connectors = None, initialize_function_name = None, initialize_function_code = None, autonomous_trigger_type = None) Updates an existing AI Agent. A new version of the agent will be created and published. :param memory: Memory (in GB) for the agent. :type memory: int :param package_requirements: A list of package requirement strings. For example: ['numpy==1.2.3', 'pandas>=1.4.0']. :type package_requirements: list :param description: A description of the agent, including its purpose and instructions. :type description: str :param workflow_graph: The workflow graph for the agent. :type workflow_graph: WorkflowGraph :param agent_interface: The interface that the agent will be deployed with. :type agent_interface: AgentInterface :param included_modules: A list of user created custom modules to include in the agent's environment. :type included_modules: List :param org_level_connectors: A list of org level connector ids to be used by the agent. :type org_level_connectors: List :param user_level_connectors: A dictionary mapping ApplicationConnectorType keys to lists of OAuth scopes. Each key represents a specific user level application connector, while the value is a list of scopes that define the permissions granted to the application. :type user_level_connectors: Dict :param initialize_function_name: The name of the function to be used for initialization. :type initialize_function_name: str :param initialize_function_code: The function code to be used for initialization. :type initialize_function_code: str :param autonomous_trigger_type: The type of trigger for autonomous agents. 'SCHEDULE' for periodic execution, 'WEBHOOK' for event-driven execution. Only applicable when agent_interface is AUTONOMOUS. :type autonomous_trigger_type: AutonomousTriggerType :returns: The updated agent. :rtype: Agent .. py:method:: wait_for_training(timeout=None) A waiting call until model is trained. :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out. :type timeout: int .. py:method:: wait_for_evaluation(timeout=None) A waiting call until model is evaluated completely. :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out. :type timeout: int .. py:method:: wait_for_publish(timeout=None) A waiting call until agent is published. :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out. :type timeout: int .. py:method:: wait_for_full_automl(timeout=None) A waiting call until full AutoML cycle is completed. :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out. :type timeout: int .. py:method:: get_status(get_automl_status = False) Gets the status of the model training. :returns: A string describing the status of a model training (pending, complete, etc.). :rtype: str .. py:method:: create_refresh_policy(cron) To create a refresh policy for a model. :param cron: A cron style string to set the refresh time. :type cron: str :returns: The refresh policy object. :rtype: RefreshPolicy .. py:method:: list_refresh_policies() Gets the refresh policies in a list. :returns: A list of refresh policy objects. :rtype: List[RefreshPolicy] .. py:method:: get_train_test_feature_group_as_pandas() Get the model train test data split feature group as pandas. :returns: A pandas dataframe for the training data with fold column. :rtype: pandas.Dataframe