Skip to content

model_transfer_tasks

Documentation for CRUDModelTransferTasks

Functionality

CRUDModelTransferTasks manages model transfer tasks in a MongoDB collection. It provides CRUD operations that are specialized for tasks associated with transferring models, using unique model identifiers for both source and destination.

Main Purposes and Motivation

The class is designed to simplify database operations specific to model transfer tasks. It supports retrieving tasks by embedding model IDs through methods like get_by_model_id and get_by_dst_model_id. This specialization ensures that data related to model transfers is handled consistently.

Inheritance

This class inherits from CRUDBase, which provides baseline create, read, update, and delete methods. The inheritance enables us to leverage common operations while customizing behavior for model transfer tasks.

Usage

  • Purpose: Manage and operate on model transfer tasks in a MongoDB collection with built-in data validation.

Methods

CRUDModelTransferTasks.get_by_model_id

Functionality

Retrieves a document from the MongoDB collection using the embedding_model_id field. It searches for the document with the provided ID and validates the result using the model's model_validate method.

Parameters
  • embedding_model_id: A string or ObjectId representing the model's unique identifier. This parameter is used to query the MongoDB collection.
Usage
  • Purpose: Fetch a document using its embedding model ID and ensure it is valid before further processing.
Example
# Example usage
crud_model_transfer_tasks = CRUDModelTransferTasks(
    collection, YourModelClass
)
task = crud_model_transfer_tasks.get_by_model_id("60d5f4839e1d4a3b9c2f9e8a")
if task:
    # Process the retrieved task
    print(task)
else:
    print("Task not found")

CRUDModelTransferTasks.get_by_dst_model_id

Functionality

Retrieves a model transfer task from the database using its destination embedding model ID. It validates the returned object against the model schema and returns it if found; otherwise, it returns None.

Parameters
  • embedding_model_id: A string or ObjectId representing the destination embedding model ID to search for.
Usage
  • Purpose: Retrieve and validate a model transfer task from a MongoDB collection using the destination model ID.
Example
# Example usage
task = crud_model_transfer_tasks.get_by_dst_model_id("your_destination_model_id")
if task:
    print("Transfer task found!")
else:
    print("Task not found.")