Skip to main content

Base Workflow

Index your data and provide your app with a default knowledge base


The base workflow acts as the default knowledge base for your app and provides the basic structure for indexing your data. It gives you a "head start" when working with your data — by pre-indexing your inputs for search and by providing a default embedding for your custom models.

Click here to learn more about the base workflow functionality.

Let's demonstrate how you can update the default workflow for your app.

Create a Workflow

You may need to start by creating a workflow for your app.

Below is an example of how to create a workflow with a custom model. Note that you can also create a workflow using the models available publicly on the Clarifai Community platform.

###################################################################################
# In this section, we set the user authentication, app ID, and the details we want
# to use to create a workflow. Change these strings to run your own example.
###################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to create your own workflow
WORKFLOW_ID = 'my-new-workflow-id'
EMBED_MODEL_ID = 'YOUR_EMBED_MODEL_ID'
EMBED_MODEL_VERSION_ID = 'YOUR_EMBED_MODEL_VERSION_ID'
WORKFLOWNODE_ID = 'my-custom-model'
CUSTOM_MODEL_ID = 'YOUR_CUSTOM_MODEL_ID'
CUSTOM_MODEL_VERSION_ID = 'YOUR_CUSTOM_MODEL_VERSION_ID'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_workflows_response = stub.PostWorkflows(
service_pb2.PostWorkflowsRequest(
user_app_id=userDataObject,
workflows=[
resources_pb2.Workflow(
id=WORKFLOW_ID,
nodes=[
resources_pb2.WorkflowNode(
id="embed",
model=resources_pb2.Model(
id=EMBED_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=EMBED_MODEL_VERSION_ID
)
)
),
resources_pb2.WorkflowNode(
id=WORKFLOWNODE_ID,
model=resources_pb2.Model(
id=CUSTOM_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=CUSTOM_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id="embed")
]
),
]
)
]
),
metadata=metadata
)

if post_workflows_response.status.code != status_code_pb2.SUCCESS:
print(post_workflows_response.status)
raise Exception("Post workflows failed, status: " + post_workflows_response.status.description)

Update Your Base Workflow

After creating a workflow, you can then use it to update the default workflow for your app. You can also use a publicly available workflow to update your default workflow.

Below is an example of how to update your base workflow.

note

Updating the base workflow will re-index your app, processing all inputs through the new base workflow. This may take some time, and could incur costs. You could avoid the costs by deleting all your inputs before updating the base workflow.

########################################################################
# In this section, we set the user authentication, app ID, and default
# workflow ID. Change these strings to run your own example.
########################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to update your default workflow
DEFAULT_WORKFlOW_ID = 'auto-annotation-workflow-id'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_apps_response = stub.PatchApps(
service_pb2.PatchAppsRequest(
user_app_id=userDataObject,
action="overwrite",
apps=[
resources_pb2.App(
id=APP_ID,
default_workflow_id=DEFAULT_WORKFlOW_ID
)
]
),
metadata=metadata
)

if patch_apps_response.status.code != status_code_pb2.SUCCESS:
print(patch_apps_response.status)
raise Exception("Patch apps failed, status: " + patch_apps_response.status.description)