TsgcAIDocumentExtractor › Properties › OCRMode
When the local OCR is used instead of sending the attachments to the model.
property OCRMode: TsgcAIDocumentOCRMode read FOCRMode write FOCRMode default domNone;
// TsgcAIDocumentOCRMode = (domNone, domFallback, domAlways)
domNone
| Value | Behaviour |
|---|---|
domNone | The attachments are sent to the model, which reads them with its vision support. The OCR is never used. |
domFallback | The vision request is sent first. When it fails with a transport or provider error (for example a model without vision support), OnOCRFallback is raised and the data is extracted from the text recognised by the OCR. A validation failure is an answer of the model, not a failed request, so it does not trigger the fallback, and neither does a document the OCR can not read (a PDF): the original error is raised. |
domAlways | The attachments are never sent. The OCR text is always used, so a text only model can extract the data. |
The local OCR, TsgcAIOCRTesseract or TsgcAIOCRWindows, accepts images only. With domAlways a PDF raises EsgcAIDocumentExtractor; convert the pages to images first. The recognised text is sent with one "Page N" block per attachment and is available in LastResult.OCRText, and LastResult.UsedOCR tells which path produced the data.
oExtractor.OCR := oOCR;
oExtractor.OCRMode := domAlways;
vJSON := oExtractor.ExtractFile('receipt.jpg');