document_understanding.proto 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.documentai.v1beta2;
  16. import "google/api/annotations.proto";
  17. import "google/api/client.proto";
  18. import "google/api/field_behavior.proto";
  19. import "google/cloud/documentai/v1beta2/document.proto";
  20. import "google/cloud/documentai/v1beta2/geometry.proto";
  21. import "google/longrunning/operations.proto";
  22. import "google/protobuf/timestamp.proto";
  23. option csharp_namespace = "Google.Cloud.DocumentAI.V1Beta2";
  24. option go_package = "google.golang.org/genproto/googleapis/cloud/documentai/v1beta2;documentai";
  25. option java_multiple_files = true;
  26. option java_outer_classname = "DocumentAiProto";
  27. option java_package = "com.google.cloud.documentai.v1beta2";
  28. option php_namespace = "Google\\Cloud\\DocumentAI\\V1beta2";
  29. option ruby_package = "Google::Cloud::DocumentAI::V1beta2";
  30. // Service to parse structured information from unstructured or semi-structured
  31. // documents using state-of-the-art Google AI such as natural language,
  32. // computer vision, and translation.
  33. service DocumentUnderstandingService {
  34. option (google.api.default_host) = "documentai.googleapis.com";
  35. option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";
  36. // LRO endpoint to batch process many documents. The output is written
  37. // to Cloud Storage as JSON in the [Document] format.
  38. rpc BatchProcessDocuments(BatchProcessDocumentsRequest) returns (google.longrunning.Operation) {
  39. option (google.api.http) = {
  40. post: "/v1beta2/{parent=projects/*/locations/*}/documents:batchProcess"
  41. body: "*"
  42. additional_bindings {
  43. post: "/v1beta2/{parent=projects/*}/documents:batchProcess"
  44. body: "*"
  45. }
  46. };
  47. option (google.api.method_signature) = "requests";
  48. option (google.longrunning.operation_info) = {
  49. response_type: "BatchProcessDocumentsResponse"
  50. metadata_type: "OperationMetadata"
  51. };
  52. }
  53. // Processes a single document.
  54. rpc ProcessDocument(ProcessDocumentRequest) returns (Document) {
  55. option (google.api.http) = {
  56. post: "/v1beta2/{parent=projects/*/locations/*}/documents:process"
  57. body: "*"
  58. additional_bindings {
  59. post: "/v1beta2/{parent=projects/*}/documents:process"
  60. body: "*"
  61. }
  62. };
  63. }
  64. }
  65. // Request to batch process documents as an asynchronous operation. The output
  66. // is written to Cloud Storage as JSON in the [Document] format.
  67. message BatchProcessDocumentsRequest {
  68. // Required. Individual requests for each document.
  69. repeated ProcessDocumentRequest requests = 1 [(google.api.field_behavior) = REQUIRED];
  70. // Target project and location to make a call.
  71. //
  72. // Format: `projects/{project-id}/locations/{location-id}`.
  73. //
  74. // If no location is specified, a region will be chosen automatically.
  75. string parent = 2;
  76. }
  77. // Request to process one document.
  78. message ProcessDocumentRequest {
  79. // Target project and location to make a call.
  80. //
  81. // Format: `projects/{project-id}/locations/{location-id}`.
  82. //
  83. // If no location is specified, a region will be chosen automatically.
  84. // This field is only populated when used in ProcessDocument method.
  85. string parent = 9;
  86. // Required. Information about the input file.
  87. InputConfig input_config = 1 [(google.api.field_behavior) = REQUIRED];
  88. // Optional. The desired output location. This field is only needed in
  89. // BatchProcessDocumentsRequest.
  90. OutputConfig output_config = 2 [(google.api.field_behavior) = OPTIONAL];
  91. // Specifies a known document type for deeper structure detection. Valid
  92. // values are currently "general" and "invoice". If not provided, "general"\
  93. // is used as default. If any other value is given, the request is rejected.
  94. string document_type = 3;
  95. // Controls table extraction behavior. If not specified, the system will
  96. // decide reasonable defaults.
  97. TableExtractionParams table_extraction_params = 4;
  98. // Controls form extraction behavior. If not specified, the system will
  99. // decide reasonable defaults.
  100. FormExtractionParams form_extraction_params = 5;
  101. // Controls entity extraction behavior. If not specified, the system will
  102. // decide reasonable defaults.
  103. EntityExtractionParams entity_extraction_params = 6;
  104. // Controls OCR behavior. If not specified, the system will decide reasonable
  105. // defaults.
  106. OcrParams ocr_params = 7;
  107. // Controls AutoML model prediction behavior. AutoMlParams cannot be used
  108. // together with other Params.
  109. AutoMlParams automl_params = 8;
  110. }
  111. // Response to an batch document processing request. This is returned in
  112. // the LRO Operation after the operation is complete.
  113. message BatchProcessDocumentsResponse {
  114. // Responses for each individual document.
  115. repeated ProcessDocumentResponse responses = 1;
  116. }
  117. // Response to a single document processing request.
  118. message ProcessDocumentResponse {
  119. // Information about the input file. This is the same as the corresponding
  120. // input config in the request.
  121. InputConfig input_config = 1;
  122. // The output location of the parsed responses. The responses are written to
  123. // this location as JSON-serialized `Document` objects.
  124. OutputConfig output_config = 2;
  125. }
  126. // Parameters to control Optical Character Recognition (OCR) behavior.
  127. message OcrParams {
  128. // List of languages to use for OCR. In most cases, an empty value
  129. // yields the best results since it enables automatic language detection. For
  130. // languages based on the Latin alphabet, setting `language_hints` is not
  131. // needed. In rare cases, when the language of the text in the image is known,
  132. // setting a hint will help get better results (although it will be a
  133. // significant hindrance if the hint is wrong). Document processing returns an
  134. // error if one or more of the specified languages is not one of the
  135. // supported languages.
  136. repeated string language_hints = 1;
  137. }
  138. // Parameters to control table extraction behavior.
  139. message TableExtractionParams {
  140. // Whether to enable table extraction.
  141. bool enabled = 1;
  142. // Optional. Table bounding box hints that can be provided to complex cases
  143. // which our algorithm cannot locate the table(s) in.
  144. repeated TableBoundHint table_bound_hints = 2 [(google.api.field_behavior) = OPTIONAL];
  145. // Optional. Table header hints. The extraction will bias towards producing
  146. // these terms as table headers, which may improve accuracy.
  147. repeated string header_hints = 3 [(google.api.field_behavior) = OPTIONAL];
  148. // Model version of the table extraction system. Default is "builtin/stable".
  149. // Specify "builtin/latest" for the latest model.
  150. string model_version = 4;
  151. }
  152. // A hint for a table bounding box on the page for table parsing.
  153. message TableBoundHint {
  154. // Optional. Page number for multi-paged inputs this hint applies to. If not
  155. // provided, this hint will apply to all pages by default. This value is
  156. // 1-based.
  157. int32 page_number = 1 [(google.api.field_behavior) = OPTIONAL];
  158. // Bounding box hint for a table on this page. The coordinates must be
  159. // normalized to [0,1] and the bounding box must be an axis-aligned rectangle.
  160. BoundingPoly bounding_box = 2;
  161. }
  162. // Parameters to control form extraction behavior.
  163. message FormExtractionParams {
  164. // Whether to enable form extraction.
  165. bool enabled = 1;
  166. // User can provide pairs of (key text, value type) to improve the parsing
  167. // result.
  168. //
  169. // For example, if a document has a field called "Date" that holds a date
  170. // value and a field called "Amount" that may hold either a currency value
  171. // (e.g., "$500.00") or a simple number value (e.g., "20"), you could use the
  172. // following hints: [ {"key": "Date", value_types: [ "DATE"]}, {"key":
  173. // "Amount", "value_types": [ "PRICE", "NUMBER" ]} ]
  174. //
  175. // If the value type is unknown, but you want to provide hints for the keys,
  176. // you can leave the value_types field blank. e.g. {"key": "Date",
  177. // "value_types": []}
  178. repeated KeyValuePairHint key_value_pair_hints = 2;
  179. // Model version of the form extraction system. Default is
  180. // "builtin/stable". Specify "builtin/latest" for the latest model.
  181. // For custom form models, specify: “custom/{model_name}". Model name
  182. // format is "bucket_name/path/to/modeldir" corresponding to
  183. // "gs://bucket_name/path/to/modeldir" where annotated examples are stored.
  184. string model_version = 3;
  185. }
  186. // User-provided hint for key value pair.
  187. message KeyValuePairHint {
  188. // The key text for the hint.
  189. string key = 1;
  190. // Type of the value. This is case-insensitive, and could be one of:
  191. // ADDRESS, LOCATION, ORGANIZATION, PERSON, PHONE_NUMBER,
  192. // ID, NUMBER, EMAIL, PRICE, TERMS, DATE, NAME. Types not in this list will
  193. // be ignored.
  194. repeated string value_types = 2;
  195. }
  196. // Parameters to control entity extraction behavior.
  197. message EntityExtractionParams {
  198. // Whether to enable entity extraction.
  199. bool enabled = 1;
  200. // Model version of the entity extraction. Default is
  201. // "builtin/stable". Specify "builtin/latest" for the latest model.
  202. string model_version = 2;
  203. }
  204. // Parameters to control AutoML model prediction behavior.
  205. message AutoMlParams {
  206. // Resource name of the AutoML model.
  207. //
  208. // Format: `projects/{project-id}/locations/{location-id}/models/{model-id}`.
  209. string model = 1;
  210. }
  211. // The desired input location and metadata.
  212. message InputConfig {
  213. // Required.
  214. oneof source {
  215. // The Google Cloud Storage location to read the input from. This must be a
  216. // single file.
  217. GcsSource gcs_source = 1;
  218. // Content in bytes, represented as a stream of bytes.
  219. // Note: As with all `bytes` fields, proto buffer messages use a pure binary
  220. // representation, whereas JSON representations use base64.
  221. //
  222. // This field only works for synchronous ProcessDocument method.
  223. bytes contents = 3;
  224. }
  225. // Required. Mimetype of the input. Current supported mimetypes are application/pdf,
  226. // image/tiff, and image/gif.
  227. // In addition, application/json type is supported for requests with
  228. // [ProcessDocumentRequest.automl_params][google.cloud.documentai.v1beta2.ProcessDocumentRequest.automl_params] field set. The JSON file needs to
  229. // be in [Document][google.cloud.documentai.v1beta2.Document] format.
  230. string mime_type = 2 [(google.api.field_behavior) = REQUIRED];
  231. }
  232. // The desired output location and metadata.
  233. message OutputConfig {
  234. // Required.
  235. oneof destination {
  236. // The Google Cloud Storage location to write the output to.
  237. GcsDestination gcs_destination = 1;
  238. }
  239. // The max number of pages to include into each output Document shard JSON on
  240. // Google Cloud Storage.
  241. //
  242. // The valid range is [1, 100]. If not specified, the default value is 20.
  243. //
  244. // For example, for one pdf file with 100 pages, 100 parsed pages will be
  245. // produced. If `pages_per_shard` = 20, then 5 Document shard JSON files each
  246. // containing 20 parsed pages will be written under the prefix
  247. // [OutputConfig.gcs_destination.uri][] and suffix pages-x-to-y.json where
  248. // x and y are 1-indexed page numbers.
  249. //
  250. // Example GCS outputs with 157 pages and pages_per_shard = 50:
  251. //
  252. // <prefix>pages-001-to-050.json
  253. // <prefix>pages-051-to-100.json
  254. // <prefix>pages-101-to-150.json
  255. // <prefix>pages-151-to-157.json
  256. int32 pages_per_shard = 2;
  257. }
  258. // The Google Cloud Storage location where the input file will be read from.
  259. message GcsSource {
  260. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  261. }
  262. // The Google Cloud Storage location where the output file will be written to.
  263. message GcsDestination {
  264. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  265. }
  266. // Contains metadata for the BatchProcessDocuments operation.
  267. message OperationMetadata {
  268. enum State {
  269. // The default value. This value is used if the state is omitted.
  270. STATE_UNSPECIFIED = 0;
  271. // Request is received.
  272. ACCEPTED = 1;
  273. // Request operation is waiting for scheduling.
  274. WAITING = 2;
  275. // Request is being processed.
  276. RUNNING = 3;
  277. // The batch processing completed successfully.
  278. SUCCEEDED = 4;
  279. // The batch processing was cancelled.
  280. CANCELLED = 5;
  281. // The batch processing has failed.
  282. FAILED = 6;
  283. }
  284. // The state of the current batch processing.
  285. State state = 1;
  286. // A message providing more details about the current state of processing.
  287. string state_message = 2;
  288. // The creation time of the operation.
  289. google.protobuf.Timestamp create_time = 3;
  290. // The last update time of the operation.
  291. google.protobuf.Timestamp update_time = 4;
  292. }