Skip to content

Commit 294e528

Browse files
committed
QVAC-23971 feat[api]: describe OCR modelConfig fields
- Add .describe() to every ocrConfigSchema field (langList, pipelineType, magRatio, canvasSize, defaultRotationAngles, contrastRetry, lowConfidenceThreshold, recognizerBatchSize, nThreads, backendDevice, gpuDevice, detectorModelSrc) - Sourced from @qvac/ocr-ggml index.d.ts (OcrGgmlParams); detectorModelSrc noted as derived from the recognizer source when omitted - Regenerate contract/schema.json and the Python generated models
1 parent 714d52b commit 294e528

3 files changed

Lines changed: 138 additions & 22 deletions

File tree

packages/inference/src/schemas/ocr.ts

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,69 @@ import { modelSrcInputSchema } from '@/schemas/model-src-utils'
66
// (useGPU, timeout, pipelineMode, decodingMethod, straightenPages) are dropped;
77
// zod's default (non-strict) object strips them silently if still passed.
88
export const ocrConfigSchema = z.object({
9-
langList: z.array(z.string()).optional(),
10-
pipelineType: z.enum(['easyocr', 'doctr']).optional(),
11-
magRatio: z.number().optional(),
12-
canvasSize: z.number().optional(),
13-
defaultRotationAngles: z.array(z.number()).optional(),
14-
contrastRetry: z.boolean().optional(),
15-
lowConfidenceThreshold: z.number().optional(),
16-
recognizerBatchSize: z.number().optional(),
17-
nThreads: z.number().optional(),
18-
backendDevice: z.enum(['cpu', 'vulkan', 'metal', 'opencl']).optional(),
19-
gpuDevice: z.number().optional(),
20-
detectorModelSrc: modelSrcInputSchema.optional()
9+
langList: z
10+
.array(z.string())
11+
.optional()
12+
.describe(
13+
"Languages handled by the recognizer, e.g. `['en']` or `['en', 'fr']`. Required for `easyocr`; ignored by the language-agnostic `doctr` pipeline."
14+
),
15+
pipelineType: z
16+
.enum(['easyocr', 'doctr'])
17+
.optional()
18+
.describe(
19+
"OCR pipeline: `'easyocr'` (CRAFT detector + CRNN recognizer, default) or `'doctr'` (DBNet detector + doctr recognizer, language-agnostic)."
20+
),
21+
magRatio: z
22+
.number()
23+
.optional()
24+
.describe('Detection magnification ratio (easyocr only). Default 1.5.'),
25+
canvasSize: z
26+
.number()
27+
.optional()
28+
.describe(
29+
'Detection canvas cap (long side, px) applied after `magRatio` scaling; lower it on memory-constrained targets. Default 2560. easyocr only.'
30+
),
31+
defaultRotationAngles: z
32+
.array(z.number())
33+
.optional()
34+
.describe(
35+
'Rotation angles tried when the primary pass is low-confidence (easyocr only). Default [90, 270].'
36+
),
37+
contrastRetry: z
38+
.boolean()
39+
.optional()
40+
.describe('Retry low-confidence boxes with contrast adjustment (easyocr only). Default false.'),
41+
lowConfidenceThreshold: z
42+
.number()
43+
.optional()
44+
.describe('Confidence threshold below which contrast-retry kicks in (easyocr only). Default 0.4.'),
45+
recognizerBatchSize: z
46+
.number()
47+
.optional()
48+
.describe('Recognizer batch size (easyocr only). Default 32.'),
49+
nThreads: z
50+
.number()
51+
.optional()
52+
.describe(
53+
"GGML CPU thread count: `0` (default) auto-detects physical cores, `> 0` sets an explicit count, `< 0` leaves the backend's default unchanged."
54+
),
55+
backendDevice: z
56+
.enum(['cpu', 'vulkan', 'metal', 'opencl'])
57+
.optional()
58+
.describe(
59+
"ggml backend device: `'cpu'` (default), `'vulkan'`, `'metal'`, or `'opencl'`. Falls back to CPU when the requested GPU device is unavailable."
60+
),
61+
gpuDevice: z
62+
.number()
63+
.optional()
64+
.describe(
65+
"0-based GPU device index for `'vulkan'`/`'metal'`/`'opencl'`; when omitted, prefers a discrete GPU. Ignored for `'cpu'`."
66+
),
67+
detectorModelSrc: modelSrcInputSchema
68+
.optional()
69+
.describe(
70+
'Text-detector model source (easyocr: CRAFT; doctr: DBNet). Derived from the recognizer model source when omitted.'
71+
)
2172
})
2273

2374
// Image input types

packages/sdk-python/src/tetherto/qvac_sdk/_generated/models/_internal.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9573,38 +9573,91 @@ class LoadModelSrcRequestGgmlOcrModelConfigDetectorModelSrc(GeneratedBaseModel):
95739573

95749574

95759575
class LoadModelSrcRequestGgmlOcrModelConfig(GeneratedBaseModel):
9576-
lang_list: Annotated[list[str] | None, Field(alias="langList")] = None
9576+
lang_list: Annotated[
9577+
list[str] | None,
9578+
Field(
9579+
alias="langList",
9580+
description="Languages handled by the recognizer, e.g. `['en']` or `['en', 'fr']`. Required for `easyocr`; ignored by the language-agnostic `doctr` pipeline.",
9581+
),
9582+
] = None
95779583
pipeline_type: Annotated[
95789584
LoadModelSrcRequestGgmlOcrModelConfigPipelineType | None,
95799585
Field(
95809586
alias="pipelineType",
9587+
description="OCR pipeline: `'easyocr'` (CRAFT detector + CRNN recognizer, default) or `'doctr'` (DBNet detector + doctr recognizer, language-agnostic).",
95819588
title="LoadModelSrcRequestGgmlOcrModelConfigPipelineType",
95829589
),
95839590
] = None
9584-
mag_ratio: Annotated[float | None, Field(alias="magRatio")] = None
9585-
canvas_size: Annotated[float | None, Field(alias="canvasSize")] = None
9591+
mag_ratio: Annotated[
9592+
float | None,
9593+
Field(
9594+
alias="magRatio",
9595+
description="Detection magnification ratio (easyocr only). Default 1.5.",
9596+
),
9597+
] = None
9598+
canvas_size: Annotated[
9599+
float | None,
9600+
Field(
9601+
alias="canvasSize",
9602+
description="Detection canvas cap (long side, px) applied after `magRatio` scaling; lower it on memory-constrained targets. Default 2560. easyocr only.",
9603+
),
9604+
] = None
95869605
default_rotation_angles: Annotated[
9587-
list[float] | None, Field(alias="defaultRotationAngles")
9606+
list[float] | None,
9607+
Field(
9608+
alias="defaultRotationAngles",
9609+
description="Rotation angles tried when the primary pass is low-confidence (easyocr only). Default [90, 270].",
9610+
),
9611+
] = None
9612+
contrast_retry: Annotated[
9613+
bool | None,
9614+
Field(
9615+
alias="contrastRetry",
9616+
description="Retry low-confidence boxes with contrast adjustment (easyocr only). Default false.",
9617+
),
95889618
] = None
9589-
contrast_retry: Annotated[bool | None, Field(alias="contrastRetry")] = None
95909619
low_confidence_threshold: Annotated[
9591-
float | None, Field(alias="lowConfidenceThreshold")
9620+
float | None,
9621+
Field(
9622+
alias="lowConfidenceThreshold",
9623+
description="Confidence threshold below which contrast-retry kicks in (easyocr only). Default 0.4.",
9624+
),
95929625
] = None
95939626
recognizer_batch_size: Annotated[
9594-
float | None, Field(alias="recognizerBatchSize")
9627+
float | None,
9628+
Field(
9629+
alias="recognizerBatchSize",
9630+
description="Recognizer batch size (easyocr only). Default 32.",
9631+
),
9632+
] = None
9633+
n_threads: Annotated[
9634+
float | None,
9635+
Field(
9636+
alias="nThreads",
9637+
description="GGML CPU thread count: `0` (default) auto-detects physical cores, `> 0` sets an explicit count, `< 0` leaves the backend's default unchanged.",
9638+
),
95959639
] = None
9596-
n_threads: Annotated[float | None, Field(alias="nThreads")] = None
95979640
backend_device: Annotated[
95989641
LoadModelSrcRequestGgmlOcrModelConfigBackendDevice | None,
95999642
Field(
96009643
alias="backendDevice",
9644+
description="ggml backend device: `'cpu'` (default), `'vulkan'`, `'metal'`, or `'opencl'`. Falls back to CPU when the requested GPU device is unavailable.",
96019645
title="LoadModelSrcRequestGgmlOcrModelConfigBackendDevice",
96029646
),
96039647
] = None
9604-
gpu_device: Annotated[float | None, Field(alias="gpuDevice")] = None
9648+
gpu_device: Annotated[
9649+
float | None,
9650+
Field(
9651+
alias="gpuDevice",
9652+
description="0-based GPU device index for `'vulkan'`/`'metal'`/`'opencl'`; when omitted, prefers a discrete GPU. Ignored for `'cpu'`.",
9653+
),
9654+
] = None
96059655
detector_model_src: Annotated[
96069656
str | LoadModelSrcRequestGgmlOcrModelConfigDetectorModelSrc | None,
9607-
Field(alias="detectorModelSrc"),
9657+
Field(
9658+
alias="detectorModelSrc",
9659+
description="Text-detector model source (easyocr: CRAFT; doctr: DBNet). Derived from the recognizer model source when omitted.",
9660+
),
96089661
] = None
96099662

96109663

packages/sdk/contract/schema.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11732,49 +11732,61 @@
1173211732
"type": "object",
1173311733
"properties": {
1173411734
"langList": {
11735+
"description": "Languages handled by the recognizer, e.g. `['en']` or `['en', 'fr']`. Required for `easyocr`; ignored by the language-agnostic `doctr` pipeline.",
1173511736
"type": "array",
1173611737
"items": {
1173711738
"type": "string"
1173811739
}
1173911740
},
1174011741
"pipelineType": {
11742+
"description": "OCR pipeline: `'easyocr'` (CRAFT detector + CRNN recognizer, default) or `'doctr'` (DBNet detector + doctr recognizer, language-agnostic).",
1174111743
"type": "string",
1174211744
"enum": ["easyocr", "doctr"],
1174311745
"title": "LoadModelSrcRequestGgmlOcrModelConfigPipelineType"
1174411746
},
1174511747
"magRatio": {
11748+
"description": "Detection magnification ratio (easyocr only). Default 1.5.",
1174611749
"type": "number"
1174711750
},
1174811751
"canvasSize": {
11752+
"description": "Detection canvas cap (long side, px) applied after `magRatio` scaling; lower it on memory-constrained targets. Default 2560. easyocr only.",
1174911753
"type": "number"
1175011754
},
1175111755
"defaultRotationAngles": {
11756+
"description": "Rotation angles tried when the primary pass is low-confidence (easyocr only). Default [90, 270].",
1175211757
"type": "array",
1175311758
"items": {
1175411759
"type": "number"
1175511760
}
1175611761
},
1175711762
"contrastRetry": {
11763+
"description": "Retry low-confidence boxes with contrast adjustment (easyocr only). Default false.",
1175811764
"type": "boolean"
1175911765
},
1176011766
"lowConfidenceThreshold": {
11767+
"description": "Confidence threshold below which contrast-retry kicks in (easyocr only). Default 0.4.",
1176111768
"type": "number"
1176211769
},
1176311770
"recognizerBatchSize": {
11771+
"description": "Recognizer batch size (easyocr only). Default 32.",
1176411772
"type": "number"
1176511773
},
1176611774
"nThreads": {
11775+
"description": "GGML CPU thread count: `0` (default) auto-detects physical cores, `> 0` sets an explicit count, `< 0` leaves the backend's default unchanged.",
1176711776
"type": "number"
1176811777
},
1176911778
"backendDevice": {
11779+
"description": "ggml backend device: `'cpu'` (default), `'vulkan'`, `'metal'`, or `'opencl'`. Falls back to CPU when the requested GPU device is unavailable.",
1177011780
"type": "string",
1177111781
"enum": ["cpu", "vulkan", "metal", "opencl"],
1177211782
"title": "LoadModelSrcRequestGgmlOcrModelConfigBackendDevice"
1177311783
},
1177411784
"gpuDevice": {
11785+
"description": "0-based GPU device index for `'vulkan'`/`'metal'`/`'opencl'`; when omitted, prefers a discrete GPU. Ignored for `'cpu'`.",
1177511786
"type": "number"
1177611787
},
1177711788
"detectorModelSrc": {
11789+
"description": "Text-detector model source (easyocr: CRAFT; doctr: DBNet). Derived from the recognizer model source when omitted.",
1177811790
"anyOf": [
1177911791
{
1178011792
"type": "string"

0 commit comments

Comments
 (0)