במאמר הזה מוסבר איך לנהל את המסמכים במאגר Document AI, כולל פעולות של יצירה, אחזור, עדכון ומחיקה.
מהם מסמכים
מסמך הוא מודל הנתונים שמשמש ב-Document AI Warehouse לארגון מסמך מהעולם האמיתי (לדוגמה, PDF או TXT) והמאפיינים שמשויכים אליו. האינטראקציה עם Document AI Warehouse מתבצעת באמצעות פעולות על המסמכים.
סוגי קבצים נתמכים
הכלי Document AI Warehouse מתמקד במסמכים, אבל הוא משמש גם לניהול תמונות משויכות (למשל, בתחומים כמו ביטוח, הנדסה, בנייה ומחקר).
- Ingest API תומך בקובצי PDF ובתמונות בפורמטים TIFF, JPEG ו-PNG, וגם בכל המאפיינים או הטקסטים שחולצו מראש.
- ממשק המשתמש להעלאה תומך בחילוץ קובצי PDF באמצעות OCR של Document AI ומעבדים מותאמים אישית.
- ממשק המשתמש של הכלי לצפייה תומך בעיבוד של קובצי PDF, קובצי טקסט וקובצי Microsoft Office.
לפני שמתחילים
לפני שמתחילים, חשוב לוודא שסיימתם את השלבים במדריך למתחילים.
כדי ליצור מסמכים, אם הנתונים שלכם נמצאים בקטגוריה של Cloud Storage משלכם, אתם צריכים לתת לחשבון השירות של Document AI Warehouse הרשאת צפייה באובייקט אחסון כדי לקרוא את הנתונים.
כל מסמך מוגדר על ידי סכימה ושייך לסוג מסמך. סכימת מסמך מגדירה את מבנה המסמך ב-Document AI Warehouse. כדי ליצור מסמכים, צריך קודם ליצור סכימת מסמכים.
יצירת מסמך
כדי ליצור מסמך, צריך לספק ל-Document AI Warehouse תוכן גולמי של מסמך. יש שתי דרכים לספק תוכן גולמי של בייטים של מסמך: על ידי הגדרה של Document.inline_raw_document או של Document.raw_document_path.
אלה ההבדלים:
-
Document.raw_document_path: זו הגישה המועדפת. הוא משתמש בנתיב Cloud Storage (gs://bucket/object) של הקובץ שצריך להטמיע. הערה: כדי שהקריאה תצליח, למתקשר צריכה להיות הרשאת קריאה באובייקט הזה.
Document.inline_raw_document: ייצוג של הקובץ בבייט או בטקסט, שמועבר ישירות לנקודת הקצה.
כדי ליצור מסמך:
העלאת מסמך מ-Cloud Storage
צריך לתת לחשבון השירות של Document AI Warehouse גישה לקטגוריה של Cloud Storage, כמו שמתואר בקטע 'דרישות מוקדמות'.
צריך להעלות את הקובץ לקטגוריה של Cloud Storage, בהתאם להוראות.
REST
בקשה:
curl --location --request POST --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=utf-8" \
--data '{
"document": {
"display_name": "TestDoc3",
"document_schema_name": "projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/DOCUMENT_SCHEMA_ID",
"raw_document_path": "gs://BUCKET_URI/FILE_URI",
"properties": [
{
"name": "supplier_name",
"text_values": {
"values": "Stanford Plumbing & Heating"
}
},
{
"name": "total_amount",
"float_values": {
"values": "1091.81"
}
},
]
},
"requestMetadata":{
"userInfo":{
"id": "user:USER_EMAIL_ID"
}
}
}'העלאה ממכונה מקומית
REST
בקשה:
curl --location --request POST --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/ \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=utf-8" \
--data '{
"document": {
"display_name": "TestDoc3",
"document_schema_name": "projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/DOCUMENT_SCHEMA_ID",
"inline_raw_document": "<bytes>",
"properties": [
{
"name": "supplier_name",
"text_values": {
"values": "Stanford Plumbing & Heating"
}
},
{
"name": "total_amount",
"float_values": {
"values": "1091.81"
}
},
]
},
"requestMetadata": {
"userInfo": {
"id": "user:USER_EMAIL_ID"
}
}
}'קבלת מסמך
מאת document_id:
REST
curl --request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=UTF-8" -d '{
"requestMetadata":{
"userInfo":{
"id": "user:USER_EMAIL"
}
}
}' \
"https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/DOCUMENT_ID:get"Python
מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Python API.
כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Java
מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Java API.
כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Node.js
מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Node.js API.
כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
מאת reference_id:
curl --request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=UTF-8" -d '{
"requestMetadata":{
"userInfo":{
"id": "user:USER_EMAIL"
}
}
}' \
"https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/referenceId/REFERENCE_ID:get"עדכון מסמך
מאת document_id:
REST
posix-terminal
curl --location --request POST --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=utf-8" \
--data '{
"document": {
"display_name": "TestDoc3",
"document_schema_name": "projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/DOCUMENT_SCHEMA_ID",
"raw_document_path": "gs://BUCKET_URI/FILE_URI",
"properties": [
{
"name": "supplier_name",
"text_values": {
"values": "Stanford Plumbing & Heating"
}
},
{
"name": "total_amount",
"float_values": {
"values": "1091.81"
}
},
{
"name": "invoice_id",
"text_values": {
"values": "invoiceid"
}
},
]
},
"requestMetadata": {
"userInfo": {
"id": "user:USER_EMAIL"
}
}
}'
Python
מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Python API.
כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Java
מידע נוסף מופיע במאמרי העזרה של Document AI Warehouse Java API.
כדי לבצע אימות ב-Document AI Warehouse, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
מאת reference_id:
curl --location --request POST --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=utf-8" \
--data '{
"document": {
"display_name": "TestDoc3",
"document_schema_name": "projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/referenceId/REFERENCE_ID",
"raw_document_path": "gs://BUCKET_URI/FILE_URI",
"properties": [
{
"name": "supplier_name",
"text_values": {
"values": "Stanford Plumbing & Heating"
}
},
{
"name": "total_amount",
"float_values": {
"values": "1091.81"
}
},
{
"name": "invoice_id",
"text_values": {
"values": "invoiceid"
}
},
]
},
"requestMetadata": {
"userInfo": {
"id": "user:USER_EMAIL"
}
}
}'מחיקת מסמך
REST
מאת document_id:
curl --request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=UTF-8" -d '{
"requestMetadata":{
"userInfo":{
"id": "user:USER_EMAIL"
}
}
}' \
"https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/DOCUMENT_ID:delete"מאת reference_id:
curl --request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json; charset=UTF-8" -d '{
"requestMetadata":{
"userInfo":{
"id": "user:USER_EMAIL"
}
}
}' \
"https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/referenceId/REFERENCE_ID":delete"השלבים הבאים
- כדי ללמוד איך לארגן מסמכים בתיקיות, אפשר לעבור אל ארגון מסמכים בתיקיות.