> ## Documentation Index
> Fetch the complete documentation index at: https://api.aodocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Train Extraction

> Train the metadata extraction rules<br>



## OpenAPI

````yaml https://document-assistant.us.aodocs.app/openapi.json post /assistant/api/v1/tenants/{tenant}/metadata:train
openapi: 3.1.0
info:
  title: Document Assistant API
  description: |
    <p>
      The Document Assistant API enables developers to integrate document-based assistant
      functionalities into their applications using AODocs.
    </p>
    <p>
      The first step is to enable AIDA (AODocs Intelligent Document Assistant) in your tenant.
      The support team will provide you with the necessary information on how to get started.
    </p>
    <p>
      The second step is to enable AIDA on libraries. You need to be an administrator of the
      library to do this.<br />
      AIDA can answer questions only from those documents that are in an AIDA enabled
      library.<br />
      We create a vector store index for these documents. This can take some time. The get
      library API provides the status of the indexation and an estimate of the time
      remaining.<br />
      The content of the index is automatically kept up-to-date near real time with the
      content changes.
    </p>
    <p>
      The third step is to ask questions based on the AODocs documents.<br />
      AIDA automatically filters the results based on the user's permissions.
    </p>
    <p>
      <strong>Authentication:</strong> All API endpoints require a valid OAuth2 token in the
      Authorization header. Ensure the client ID of the OAuth2 token is whitelisted in AODocs.
    </p>
  version: 1.1.0
servers:
  - url: https://document-assistant.us.aodocs.app
    description: Production US
  - url: https://document-assistant.eu.aodocs.app
    description: Production EU
security: []
paths:
  /assistant/api/v1/tenants/{tenant}/metadata:train:
    post:
      tags:
        - metadata
      summary: Train Extraction
      description: Train the metadata extraction rules<br>
      operationId: train_extraction_assistant_api_v1_tenants__tenant__metadata_train_post
      parameters:
        - name: tenant
          in: path
          required: true
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: The domain of the customer
            examples:
              - example.com
            title: Tenant
          description: The domain of the customer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MetadataExtractRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractionSuggestion'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    MetadataExtractRequest:
      properties:
        llm_provider:
          anyOf:
            - $ref: '#/components/schemas/LlmProvider'
            - type: 'null'
          description: >-
            The LLM provider to use. If not provided, the default provider will
            be used.
        llm_model_prefix:
          anyOf:
            - type: string
            - type: 'null'
          title: Llm Model Prefix
          description: >-
            The prefix of the LLM model name to use. If not provided, the
            default model will be used.
          examples:
            - gemini-2.5-pro
            - gemini-2.5-pro-preview-05-06
            - gpt-4.1
        document_id:
          type: string
          title: Document Id
          description: The document ID of the files
        attachment_filters:
          anyOf:
            - items:
                $ref: '#/components/schemas/AttachmentFilter'
              type: array
            - type: 'null'
          title: Attachment Filters
          description: |-
            The attachments to extract metadata from.
                        If provided then only the attachments matching one of the rules are used.
                        If not provided then all attachments will be extracted.
                        Deprecated: use sources with an attachments entry instead. 
          deprecated: true
        sources:
          anyOf:
            - items:
                oneOf:
                  - $ref: '#/components/schemas/DescriptionExtractionSource'
                  - $ref: '#/components/schemas/AttachmentsExtractionSource'
                discriminator:
                  propertyName: type
                  mapping:
                    attachments:
                      $ref: '#/components/schemas/AttachmentsExtractionSource'
                    description:
                      $ref: '#/components/schemas/DescriptionExtractionSource'
              type: array
              minItems: 1
            - type: 'null'
          title: Sources
          description: |-
            The ordered document content sources to extract metadata from.
                        If omitted, attachment-only extraction is used for backward compatibility.
                        Description sources are opt-in. 
        instruction:
          anyOf:
            - type: string
            - type: 'null'
          title: Instruction
          description: The prompt extension for the metadata extraction
        provide_location:
          type: boolean
          title: Provide Location
          description: >-
            Whether to calculate and return page locations (bounding boxes) for
            the quote supporting each extracted field. Quotes are matched
            against textual and scanned PDF attachments plus PNG, JPEG, and WebP
            images without changing extracted values. Unsupported attachment
            types and quotes that do not occur verbatim after normalization do
            not produce boxes.
          default: false
        fields:
          anyOf:
            - items:
                $ref: '#/components/schemas/FieldSpec'
              type: array
            - items:
                type: string
              type: array
            - type: 'null'
          title: Fields
          description: >-
            Specification which metadata to extract and how. If not provided,
            all fields will be extracted.
        example_documents:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Example Documents
          description: >-
            A list of example documents to use for metadata extraction. If
            provided, the LLM will use these documents to better understand the
            context and provide more accurate extractions.
        registries:
          anyOf:
            - items:
                $ref: '#/components/schemas/Registry'
              type: array
            - type: 'null'
          title: Registries
          description: >-
            A list of metadata registries to use for metadata extraction. If
            provided, the LLM will use these registries to better understand the
            context and provide more accurate extractions.
      type: object
      required:
        - document_id
      title: MetadataExtractRequest
    ExtractionSuggestion:
      properties:
        fields:
          items:
            $ref: '#/components/schemas/FieldSuggestion'
          type: array
          title: Fields
          description: The suggested instructions for extracting the fields
        extraction_instruction:
          type: string
          title: Extraction Instruction
          description: The suggested instruction for the whole document
        comment:
          anyOf:
            - type: string
            - type: 'null'
          title: Comment
          description: Reason for the instruction change
      type: object
      required:
        - fields
        - extraction_instruction
        - comment
      title: ExtractionSuggestion
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    LlmProvider:
      type: string
      enum:
        - OpenAI
        - Google
        - Altirnao
        - MistralAI
        - Anthropic
      title: LlmProvider
    AttachmentFilter:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: The name of the attachment to match (it can be a regular expression)
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
          description: The id of the matched attachment
        mime_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Mime Type
          description: The mimetype of the matched attachment
      type: object
      title: AttachmentFilter
      description: Match an attachment by identifier, MIME type, or name expression.
    DescriptionExtractionSource:
      properties:
        type:
          type: string
          const: description
          title: Type
          default: description
      type: object
      title: DescriptionExtractionSource
    AttachmentsExtractionSource:
      properties:
        type:
          type: string
          const: attachments
          title: Type
          default: attachments
        include:
          anyOf:
            - items:
                $ref: '#/components/schemas/AttachmentFilter'
              type: array
            - type: 'null'
          title: Include
          description: >-
            Attachment filters to include. If omitted, all attachments are
            included. If empty, no attachments are included.
        exclude:
          anyOf:
            - items:
                $ref: '#/components/schemas/AttachmentFilter'
              type: array
            - type: 'null'
          title: Exclude
          description: >-
            Attachment filters to exclude after applying include filters.
            Exclusion takes precedence over inclusion.
      type: object
      title: AttachmentsExtractionSource
    FieldSpec:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: The name of the metadata field. Either the name or id is mandatory
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
          description: The id of the metadata field. Either the name or id is mandatory
        instruction:
          anyOf:
            - type: string
              maxLength: 1024
            - type: 'null'
          title: Instruction
          description: Custom instruction for extracting this field
        barcode:
          type: boolean
          title: Barcode
          description: >-
            Extract decoded barcode content and locations without using the LLM.
            Supported only for STRING and TEXT fields.
          default: false
        integer_decimal_handling:
          $ref: '#/components/schemas/IntegerDecimalHandling'
          description: >-
            How to coerce a decimal value the LLM returns for this integer-typed
            field: `truncate` drops the fractional part (3.7 → 3), `round`
            rounds to the nearest integer (3.5 → 4, 3.4 → 3), `roundup` always
            rounds up toward positive infinity (3.2 → 4), `error` raises an
            extraction error (default — current behavior). Applies only to
            integer fields; ignored otherwise.
          default: error
        table_search:
          anyOf:
            - $ref: '#/components/schemas/TableSearchConfig'
            - type: 'null'
          description: >-
            Optional request-scoped table-search configuration used to validate
            and canonicalize STRING, CATEGORY, REFERENCE_CATALOG, or TABLE
            values. Complete low-cardinality enum values remain available to the
            extraction model; incomplete or high-cardinality enums are extracted
            as plain text.
      type: object
      title: FieldSpec
    Registry:
      properties:
        name:
          type: string
          title: Name
          description: >-
            The name of the metadata registry. This is used to identify the
            registry in the request.
        library_id:
          type: string
          title: Library Id
          description: >-
            The library ID that contains the metadata registry that should be
            used for metadata extraction.
        document_class_id:
          type: string
          title: Document Class Id
          description: >-
            The document class ID that contains the metadata registry that
            should be used for metadata extraction.
        match_mode:
          $ref: '#/components/schemas/MatchMode'
          description: >-
            Specifies whether all key fields must match (ALL) or if any single
            key field match is sufficient (ANY) to consider a registry entry as
            a potential match.
          default: ALL
        field_mappings:
          items:
            $ref: '#/components/schemas/FieldMapping'
          type: array
          title: Field Mappings
          description: |-
            Mapping between the extracted fields and the registry 
            There should be at least one key field in this mapping.
      type: object
      required:
        - name
        - library_id
        - document_class_id
        - field_mappings
      title: Registry
    FieldSuggestion:
      properties:
        name:
          type: string
          title: Name
          description: The name of the field
        extraction_instruction:
          type: string
          title: Extraction Instruction
          description: The suggested instruction for extracting this field
        comment:
          anyOf:
            - type: string
            - type: 'null'
          title: Comment
          description: >-
            Reason for the instruction change. You can argue here if the
            expected value is wrong and no reasonable instruction can be
            provided.
      type: object
      required:
        - name
        - extraction_instruction
        - comment
      title: FieldSuggestion
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    IntegerDecimalHandling:
      type: string
      enum:
        - truncate
        - round
        - roundup
        - error
      title: IntegerDecimalHandling
    TableSearchConfig:
      properties:
        dataset_id:
          type: string
          minLength: 1
          title: Dataset Id
          description: Tenant-scoped table-search dataset ID.
        input_columns:
          anyOf:
            - items:
                type: string
              type: array
              minItems: 1
            - type: 'null'
          title: Input Columns
          description: >-
            Dataset filter columns. Wrap a single STRING filter in a one-item
            list.
        output_columns:
          anyOf:
            - items:
                $ref: '#/components/schemas/TableSearchOutputColumn'
              type: array
              minItems: 1
            - type: 'null'
          title: Output Columns
          description: >-
            Dataset output columns. Wrap a single STRING output in a one-item
            list.
      type: object
      required:
        - dataset_id
      title: TableSearchConfig
    MatchMode:
      type: string
      enum:
        - ALL
        - ANY
      title: MatchMode
    FieldMapping:
      properties:
        extracted_field:
          type: string
          title: Extracted Field
          description: The id of the field in the extracted metadata
        registry_field:
          type: string
          title: Registry Field
          description: The id of the field in the metadata registry
        key_field:
          type: boolean
          title: Key Field
          description: >-
            If true, the field is used to match the document to the metadata
            registry. 

            We need at least one key field to match the document to the metadata
            registry.
          default: false
        optional_key:
          type: boolean
          title: Optional Key
          description: >-
            If True, this key field is optional—if it's missing in the extracted
            data, the match can still succeed as long as other key fields are
            present and match.
          default: false
        similarity_threshold:
          type: number
          maximum: 1
          minimum: 0
          title: Similarity Threshold
          description: >-
            For key fields only: how closely the extracted and registry values
            need to match (0.0 = no similarity, 1.0 = perfect match). If more
            than one record matches, the one with the highest total similarity
            across all key fields will be chosen.
          default: 1
      type: object
      required:
        - extracted_field
        - registry_field
      title: FieldMapping
    TableSearchOutputColumn:
      properties:
        name:
          type: string
          minLength: 1
          title: Name
          description: >-
            Dataset output column. For TABLE fields this must exactly match the
            metadata table-column name.
        id_column:
          anyOf:
            - type: string
              minLength: 1
            - type: 'null'
          title: Id Column
          description: >-
            Companion dataset output column containing the category or reference
            catalog value ID. It is not exposed as a separate extracted column.
      type: object
      required:
        - name
      title: TableSearchOutputColumn
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````