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

# LWAI Batch Vectorize Index Stage

> Lucidworks AI

export const schema = {
  "type": "object",
  "title": "LWAI Batch Vectorize",
  "description": "Invokes a Lucidworks AI model to encode a string field to a vector representation. Will be skipped if the field to encode doesn't exist or is null on the pipeline document.",
  "required": ["accountName", "modelType", "sourceFieldName", "destinationFieldName"],
  "properties": {
    "skip": {
      "type": "boolean",
      "title": "Skip This Stage",
      "description": "Set to true to skip this stage.",
      "default": false,
      "hints": ["advanced"]
    },
    "label": {
      "type": "string",
      "title": "Label",
      "description": "A unique label for this stage.",
      "hints": ["advanced"],
      "maxLength": 255
    },
    "condition": {
      "type": "string",
      "title": "Condition",
      "description": "Define a conditional script that must result in true or false. This can be used to determine if the stage should process or not.",
      "hints": ["code", "code/javascript", "advanced"]
    },
    "accountName": {
      "type": "string",
      "title": "Account Name",
      "description": "Lucidworks AI API Account Name as defined in Lucidworks AI Gateway Service.  This entry should match the account name set in the LWAI Gateway.",
      "hints": ["enumUrl:/api/query-stages/lwai-accounts"]
    },
    "modelType": {
      "type": "string",
      "title": "Model",
      "description": "Lucidworks AI API model to use for encoding.",
      "hints": ["enumUrl:/api/query-stages/lwai-model?account=${accountName}&useCase=embedding"]
    },
    "sourceFieldName": {
      "type": "string",
      "title": "Source Field",
      "description": "Name of the string field whose value should be submitted to the model for encoding. If the field doesn't exist or is null in the pipeline document, this stage will be skipped.  Supports Template Expressions, e.g. <doc.title_t> and <ctx.myVar>."
    },
    "destinationFieldName": {
      "type": "string",
      "title": "Destination Field",
      "description": "Name of the field into which the dense vector value from the model response will be saved."
    },
    "useCaseConfig": {
      "type": "array",
      "title": "Use Case Configuration",
      "default": [{
        "key": "dataType",
        "value": "passage"
      }],
      "items": {
        "type": "object",
        "required": ["key"],
        "properties": {
          "key": {
            "type": "string",
            "title": "Parameter Name"
          },
          "value": {
            "type": "string",
            "title": "Parameter Value"
          }
        }
      }
    },
    "modelConfig": {
      "type": "array",
      "title": "Model Configuration",
      "items": {
        "type": "object",
        "required": ["key"],
        "properties": {
          "key": {
            "type": "string",
            "title": "Parameter Name"
          },
          "value": {
            "type": "string",
            "title": "Parameter Value"
          }
        }
      }
    },
    "maxBatchSize": {
      "type": "integer",
      "title": "Maximum Batch Size",
      "description": "The maximum number of documents to include in each batch when batch mode is enabled. This value should not exceed the maximum batch size supported by the selected model in the Lucidworks AI Platform. If unsure, refer to the model documentation or set to a conservative value like 16 or 32.  LWAI maximum is 32.",
      "default": 16,
      "maximum": 32,
      "exclusiveMaximum": false,
      "minimum": 1,
      "exclusiveMinimum": false
    },
    "maxBatchDelay": {
      "type": "integer",
      "title": "Maximum Batch Delay (ms)",
      "description": "The maximum time in milliseconds to wait before sending a batch of documents for vectorization. If the batch is not full within this time, the current batch will be sent regardless of size. This setting helps to balance latency and throughput when batch mode is enabled.",
      "default": 1000,
      "minimum": 0,
      "exclusiveMinimum": false
    },
    "failOnError": {
      "type": "boolean",
      "title": "Fail on Error",
      "description": "Flag to indicate if this stage should throw an exception if an error occurs while generating a prediction for a document.",
      "default": false
    }
  },
  "category": "AI",
  "categoryPriority": 10,
  "unsafe": false
};

export const SchemaParamFields = ({schema}) => {
  const sanitize = str => {
    if (typeof str !== "string") return str;
    return str.replace(/^"(.*)"$/s, "$1").replace(/\\/g, "").replace(/"/g, "'");
  };
  const formatDescription = str => {
    const s = sanitize(str);
    return (/[.!?]\)*$/).test(s) ? s : `${s}.`;
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  return <div>
      {description && <p>{formatDescription(description)}</p>}

      {visibleProps.map(([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...prop.title && ({
        post: [<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>]
      }),
      ...isRequired && ({
        required: true
      }),
      ...!isComplexDefault && hasDefault ? {
        default: sanitize(String(rawDefault))
      } : {}
    };
    const isObject = prop.type === "object" && prop.properties;
    const isArrayOfObjects = prop.type === "array" && prop.items?.type === "object" && prop.items.properties;
    return <ParamField {...fieldProps}>
            {prop.description && <p>{formatDescription(prop.description)}</p>}

            {isComplexDefault && <div className="flex">
                <p>
                  <strong>Default:</strong>
                </p>
                <pre className="!my-0">
                  <code>
                    {JSON.stringify(rawDefault, null, 2)}
                  </code>
                </pre>
              </div>}

            {isArrayOfObjects && <div className="flex">
              <p>
                <strong>Object attributes:</strong>
              </p>
              <pre className="!my-0">
                <code>
                  {'{\n'}
                  {Object.entries(prop.items.properties).map(([iname, iprop]) => <>
                      {`  ${iname}`}
                      {prop.items?.required?.includes(iname) && <span style={{
      color: 'red'
    }}> required</span>}
                      {`: {\n    display name: ${sanitize(iprop.title || '')}\n    type: ${iprop.type}\n  }\n`}
                    </>)}
                  {'}'}
                </code>
              </pre>
              </div>}

            {isObject && <Expandable title="properties">
                <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
              </Expandable>}
          </ParamField>;
  })}
    </div>;
};

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/lw-platform/lw-ai/lw-ai-stages/batch-vectorize-field-via-lucidworks-ai-index-stage

[mintlify link]: https://doc.lucidworks.com/docs/lw-platform/lw-ai/lw-ai-stages/batch-vectorize-field-via-lucidworks-ai-index-stage

<Note>
  This feature is only available in Fusion 5.9.x for versions 5.9.15 and later.
</Note>

The LWAI Batch Vectorize Index Stage is an integration between Fusion and Lucidworks AI to enrich your index with [Generative AI](/docs/lw-platform/lw-ai/lw-ai-generative-ai) predictions. This stage processes your documents in batches before sending them to the next stage in your index pipeline. Use this stage instead of the LWAI Vectorize Field index stage if you have many documents to process.

All the field names and values for the LWAI Vectorize Field index stage are maintained in the LWAI Batch Vectorize index stage, so you can switch from the LWAI Vectorize Field stage while maintaining your existing index pipeline.

To use this stage, non-admin Fusion users must be granted the `PUT,POST,GET:/LWAI-ACCOUNT-NAME/**` permission in Fusion, which is the Lucidworks AI API Account Name defined in [Lucidworks AI Gateway](/docs/lw-platform/lw-ai/lw-ai-gateway) when this stage is configured.

<LwTemplate />

## Configurable batch length and waiting time

In order to use the LWAI Batch Vectorize index stage, you must configure two fields in addition to the fields that are also included in the LWAI Vectorize Field stage.

The **Maximum Batch Size** field allows you to configure how many documents to include in each batch when batch processing documents. The value should not exceed the maximum value supported by your model. The Lucidworks AI maximum value is 32.

The **Maximum Batch Delay** field allows you to configure the maximum time to wait before sending a batch of documents to be vectorized. If the batch is not full within this time, the current batch will be sent regardless of size. This setting helps to balance latency and throughput while batch processing documents. The default value is 1000 milliseconds, or 1 second.

## Configuration

<Tip>
  When entering configuration values in the UI, use *unescaped* characters, such as `\t` for the tab character. When entering configuration values in the API, use *escaped* characters, such as `\\t` for the tab character.
</Tip>

<SchemaParamFields schema={schema} />
