Use the document classifier node to classify your documents.
This feature is currently in public preview. Functionality and behavior may change in future updates.

Pre-requisites

Run the following command to enable watsonx Orchestrate Developer Edition to process documents:
[BASH]
orchestrate server start -e <.env file path> -d
Note: You need to configure a minimum allocation of 20GB RAM to your Docker engine during installation of watsonx Orchestrate Developer edition to support document processing features.
Note: To run the document classifier, you must define the WO_INSTANCE, WO_API_KEY, and AUTHORIZATION_URL credentials in your .env file. For more information on configuring the .env file, see Installing the watsonx Orchestrate Developer Edition.

Configuring document extractor node in flows

  1. Define document classes Create a class that defines the document classes to classify. Each document class must follow this structure:
    Python
    class CustomClasses(BaseModel):
        invoice: DocClassifierClass = Field(default=DocClassifierClass(class_name="Invoice"))
    
  2. Configure the document extract node
Include a call to the docclassfier() method in your flow to classify the document. This method accepts the following input arguments:
ParameterTypeRequiredDescription
namestringYesUnique identifier for the node.
llmstringYesThe LLM used for document classification.
display_namestringNoDisplay name for the node.
classesobjectYesThe document classification classes.
descriptionstringNoDescription of the node.
min_confidencefloatNoMinimum confidence threshold for classification.
input_mapDataMapNoDefine input mappings using a structured collection of Assignment objects.
Example use of the docext node in a flow:
Python
from pydantic import BaseModel, Field
from ibm_watsonx_orchestrate.flow_builder.flows import (
    Flow, flow, START, END
)
from ibm_watsonx_orchestrate.flow_builder.types import DocClassifierClass, DocumentProcessingCommonInput, DocumentClassificationResponse


class CustomClasses(BaseModel):
    buyer: DocClassifierClass = Field(default=DocClassifierClass(class_name="Buyer"))
    seller: DocClassifierClass = Field(default=DocClassifierClass(class_name="Seller"))
    agreement_date: DocClassifierClass = Field(default=DocClassifierClass(class_name="Agreement_Date"))


@flow(
    name ="custom_flow_docclassifier_example",
    display_name="custom_flow_docclassifier_example",
    description="Extraction of custom classes from a document, specified by the user.",
    input_schema=DocumentProcessingCommonInput
)
def build_docclassifier_flow(aflow: Flow = None) -> Flow:
    # aflow.docclassfier return a DocClassifierNode object
    # DocumentClassificationResponse is the output schema of DocClassifierNode and it can be used as input schema for the next node

    doc_classifier_node = aflow.docclassfier(
        name="document_classifier_node",
        display_name="document_classifier_node",
        description="Classify custom classes from a document",
        llm="watsonx/meta-llama/llama-3-2-90b-vision-instruct",
        classes=CustomClasses(),
    )

    aflow.sequence(START, doc_classifier_node, END)
    return aflow