Cortex PARSE_DOCUMENT¶
PARSE_DOCUMENT 함수는 문서에서 텍스트, 데이터 및 레이아웃 요소를 추출하는 함수를 제공하는 Cortex AI AISQL 함수 입니다. PARSE_DOCUMENT 를 사용하여 다양한 문서와 양식에서 텍스트를 추출하여 다음을 구현할 수 있습니다.
Cortex Search 검색을 지원하는 RAG 파이프라인
Cortex AI 함수를 사용한 문서 요약 또는 변환과 같은 LLM 처리
Cortex AI Structured Outputs를 사용한 제로 샷 엔터티 추출
PARSE_DOCUMENT 작동 방법¶
PARSE_DOCUMENT 함수는 PDF 문서를 처리하기 위한 두 가지 모드를 제공합니다.
OCR 모드는 문서, 계약서, 제품 상세 페이지, 보험 정책 및 청구서, SharePoint 문서 와 같은 문서에서 고품질의 텍스트를 빠르게 추출하는 데 권장되는 옵션입니다.
LAYOUT 모드는 테이블과 같은 텍스트 및 레이아웃 요소를 추출하는 데 최적화되어 있습니다. 이 옵션은 문서 지식웨어하우스의 컨텍스트를 개선하여 검색 정보 시스템을 최적화하고 대규모 언어 모델(LLM) 추론을 위해 권장되는 옵션입니다.
참고
PARSE_DOCUMENT 레이아웃 모드는 현재 미리 보기로 제공됩니다. OCR 모드는 일반적으로 대부분의 리전 에서 사용할 수 있습니다.
PARSE_DOCUMENT 사용하기¶
Cortex PARSE_DOCUMENT 는 SQL 함수입니다. Snowflake에서 전적으로 호스팅 및 관리되므로 사용할 때 별도의 설정이 필요하지 않습니다. PARSE_DOCUMENT 함수를 PDF 문서가 포함된 스테이지로 가리키면 해당 문서에서 데이터를 추출할 수 있습니다. 다음 예제에서는 parse_document
데이터베이스와 demo
스키마의 documents
스테이지에 있는 document_1.pdf
파일에서 텍스트와 레이아웃 정보를 추출합니다.
참고
PARSE_DOCUMENT 는 현재 사용자 지정 네트워크 정책 과 호환되지 않습니다.
SELECT
SNOWFLAKE.CORTEX.PARSE_DOCUMENT(
@parse_document.demo.documents,
'document_1.pdf',
{'mode': 'LAYOUT'}
) AS layout;
문서 처리를 위한 스테이지 생성하기¶
내부 또는 외부 스테이지를 생성해 처리할 문서를 저장하십시오. 스테이지를 생성할 때 서버 측 암호화 를 활성화하십시오. 그렇지 않으면, PARSE_DOCUMENT 는 제공된 파일이 예상 형식이 아니거나 클라이언트 측에서 암호화되었다는 오류를 반환합니다.
아래 SQL 에서 적절한 내부 스테이지를 생성합니다.
CREATE OR REPLACE STAGE input_stage
DIRECTORY = ( ENABLE = true )
ENCRYPTION = ( TYPE = 'SNOWFLAKE_SSE' );
다음 SQL 은 Amazon S3에 외부 스테이지를 생성합니다. Azure 및 GCP 외부 스테이지도 지원됩니다.
CREATE OR REPLACE STAGE input_stage
URL='s3://<s3-path>/'
CREDENTIALS=(AWS_KEY_ID=<aws_key_id>
AWS_SECRET_KEY=<aws_secret_key>)
ENCRYPTION=( TYPE = 'AWS_SSE_S3' );
참고
스테이지에서 파일을 처리하는 것은 현재 사용자 지정 네트워크 정책 과 호환되지 않습니다.
팁
외부 스테이지에서 “Expiry in seconds for AWS role is invalid” 오류 메시지가 표시되는 경우 미리 설정된 URL 만료 시간이 정확하게 설정되어 있는지 확인하십시오. 이 계정 매개 변수의 기본값은 내부 스테이지에 최적화되어 있지만 외부 스테이지에서 작동하도록 조정할 수 있는 옵션이 있습니다. 변경하려면 Snowflake 지원팀에 문의하십시오.
예¶
이 예제에서는 PARSE_DOCUMENT 의 OCR 모드를 사용하여 아래와 같이 날씨 보험 문서의 첫 페이지에서 텍스트를 추출합니다.

이 문서를 구문 분석하려면 document_stage
라는 스테이지에 업로드하고 다음 쿼리를 실행합니다.
SELECT SNOWFLAKE.CORTEX.PARSE_DOCUMENT(
@document_stage,
'weather_policy.pdf'
) AS weather_policy_doc
PARSE_DOCUMENT 의 원시 응답은 다음과 같습니다.
{
"content": "SOME INSURANCE COMPANY\nWEATHER PROTECTION INSURANCE POLICY\nPolicy Number: WP-2025-789456\nEffective Date: April 1, 2025\nExpiration Date: April 1, 2026\nNAMED INSURED AND PROPERTY:\nJohn and Mary Homeowner\n123 Shelter Lane\nWeatherton, ST 12345\n
SECTION I - DEFINITIONS\nThroughout this policy, \"you\" and \"your\" refer to the Named Insured shown in the Declarations and the spouse if a\nresident of the same household. \"We,\" \"us,\" and \"our\" refer to Evergreen Insurance Company providing this\ninsurance. In addition, certain words and phrases are defined as follows:\n1. Weather Event means a natural atmospheric occurrence including but not limited to: a. Wind (including\nhurricanes, tornadoes, and straight-line winds) b. Hail c. Lightning d. Snow, ice, and freezing rain e.\nExcessive rainfall resulting in flooding f. Extreme temperatures causing damage\n2. Named Storm means any storm or weather disturbance that has been declared and named as a tropical\nstorm or hurricane by the National Weather Service or National Hurricane Center.\n3. Actual Cash Value (ACV) means the cost to repair or replace damaged property with new material of like\nkind and quality, less depreciation due to age, wear and condition.\n4. Replacement Cost means the cost to repair or replace damaged property with new material of like kind\nand quality, without deduction for depreciation.\n5. Dwelling means the building structure at the insured location including attached structures and fixtures.\n6. Other Structures means structures on the residence premises separated from the dwelling by clear\nspace or connected only by a fence, utility line, or similar connection.\n7. Personal Property means movable items owned by you and located at the insured property.\n
SECTION II - COVERAGE\nA. PROPERTY COVERAGE\nWe will pay for direct physical loss to property described in the Declarations caused by a Weather Event unless\nthe loss is excluded in Section III - Exclusions.\n1. Dwelling Protection We will cover: a. Your dwelling, including attached structures b. Materials and\nsupplies located on or adjacent to the residence premises for use in construction, alteration, or repair of\nthe dwelling or other structures c. Foundation, floor slab, and footings supporting the dwelling d.\nWall-to-wall carpeting attached to the dwelling\n2. Other Structures Protection We will cover structures on your property separated from your dwelling by\nclear space, including: a. Detached garages b. Storage sheds c. Fences d. Driveways and walkways e.\nPatios and retaining walls\n3. Personal Property Protection We will cover personal property owned or used by you while it is on the\nresidence premises. Coverage includes but is not limited to: a. Furniture b. Clothing c. Electronic\nequipment d. Appliances e. Sporting goods\n4. Loss of Use Protection If a Weather Event makes your residence uninhabitable, we will cover: a.\nAdditional living expenses incurred to maintain your normal standard of living b. Fair rental value if part of\nyour residence is rented to others c. Necessary expenses required to make the residence habitable or\nmove to temporary housing\nB. ADDITIONAL COVERAGES",
"metadata": {
"pageCount": 1
}
}
이 응답을 Cortex AI LLM 함수로 처리하면 비정형 데이터 분석을 쉽게 수행할 수 있습니다. 다음 예제는 간단한 질문과 답변 작업을 보여줍니다.
SELECT SNOWFLAKE.CORTEX.COMPLETE('claude-3-5-sonnet',
CONCAT ('Is clothing covered as part of the weather protection insurance policy?',
TO_VARCHAR(weather_policy_doc))) FROM ocr_example_docs
응답:
Yes, clothing is covered under the insurance policy. According to Section II - Coverage, Part A.3 (Personal Property Protection), clothing is specifically listed as one of the covered personal property items while it is on the residence premises. The policy states: "We will cover personal property owned or used by you while it is on the residence premises. Coverage includes but is not limited to: a. Furniture b. Clothing c. Electronic equipment d. Appliances e. Sporting goods"
입력 요구 사항¶
PARSE_DOCUMENT 는 디지털로 생성된 문서와 스캔한 문서 모두에 최적화되어 있습니다. 다음 테이블에는 입력 문서의 제한 사항과 요구 사항이 나열되어 있습니다.
최대 파일 크기 |
100 MB |
문서당 최대 페이지 수 |
300페이지 |
허용 파일 유형 |
PDF, PPTX, DOCX, JPEG, JPG, PNG, TIFF, TIF |
스테이지 암호화 |
서버 측 암호화: |
글꼴 크기 |
최상의 결과를 위해 8포인트 이상 |
지원되는 문서 기능¶
특징 |
설명 |
---|---|
페이지 방향 |
PARSE_DOCUMENT는 자동으로 페이지 방향을 감지합니다. |
문자 |
PARSE_DOCUMENT 는 다음 문자를 감지합니다.
|
참고
PARSE_DOCUMENT 는 필기 인식에 대해 학습되지 않았습니다.
지원되는 언어¶
PARSE_DOCUMENT 는 다음 언어에 대해 의도적으로 훈련되었습니다.
OCR 모드 |
LAYOUT 모드 |
---|---|
|
|
LAYOUT 모드는 프랑스어, 독일어, 이탈리아어, 노르웨이어, 폴란드어, 포르투갈어, 스페인어 및 스웨덴어도 지원하지만, 최적화되지는 않습니다.
리전 가용성¶
이 기능에 대한 지원은 다음 Snowflake 리전의 계정에서 사용할 수 있습니다.
AWS |
Azure |
Google Cloud Platform |
---|---|---|
US 서부 2(오리건) |
동부 US 2(버지니아) |
US 중부(아이오와) |
US 동부(오하이오) |
서부 US 2(워싱턴) |
|
US 동부 1(북부 버지니아) |
유럽(네덜란드) |
|
유럽(아일랜드) |
||
유럽 중부 1(프랑크푸르트) |
||
아시아 태평양(시드니) |
||
아시아 태평양(도쿄) |
액세스 제어 요구 사항¶
PARSE_DOCUMENT 함수를 사용하려면 ACCOUNTADMIN 역할을 가진 사용자가 함수를 호출할 사용자에게 SNOWFLAKE.CORTEX_USER 데이터베이스 역할을 부여해야 합니다. 자세한 내용은 필수 권한 항목을 참조하십시오.
비용 고려 사항¶
Cortex PARSE_DOCUMENT 함수는 처리되는 문서당 페이지 수에 따라 컴퓨팅 비용이 발생합니다.
문서 파일 형식(PDF, DOCX)의 경우 문서의 각 페이지가 페이지 단위로 청구됩니다.
이미지 파일 형식(JPEG, JPG, TIF, TIFF, PNG)의 경우 각 개별 이미지 파일이 페이지 단위로 청구됩니다.
Snowflake는 더 작은 웨어하우스(MEDIUM보다 크지 않음)에서 Cortex PARSE_DOCUMENT 함수를 호출하는 쿼리를 실행할 것을 권장합니다. 웨어하우스가 크다고 성능이 향상되는 것은 아닙니다.
오류 조건¶
Snowflake Cortex PARSE_DOCUMENT는 다음과 같은 오류 메시지를 표시할 수 있습니다.
메시지 |
설명 |
---|---|
문서에 지원되지 않는 언어가 포함되어 있습니다. |
입력 문서에 지원되지 않는 언어가 포함되어 있습니다 |
제공된 파일 형식 {file_extension} 은 지원되지 않습니다. 지원되는 형식: .[‘.docx’,’.pptx’,’.pdf’]. |
문서가 지원되는 형식이 아닐 때 반환됩니다. |
제공된 파일 형식 .bin은 지원되지 않습니다. 지원되는 형식: [‘.docx’,’.pptx’,’.pdf’]. 파일이 서버 측 암호화로 저장되어 있는지 확인합니다. |
파일 형식이 지원되지 않고 이진 파일로 이해될 때 반환됩니다. 스테이지가 서버 측 암호화를 사용하는지 확인합니다. |
300페이지의 최대 한도를 초과했습니다. |
PDF 가 300페이지를 초과하는 경우 반환됩니다. |
최대 파일 크기인 104857600바이트를 초과했습니다. |
문서가 100MB를 초과하는 경우 반환됩니다. |
제공된 파일을 찾을 수 없습니다. |
파일이 존재하지 않습니다. |
제공된 파일에 액세스할 수 없습니다. |
권한이 부족하여 파일에 액세스할 수 없습니다. |
문서 구문 분석 함수가 허용된 시간 내에 응답하지 않았습니다. |
시간 제한이 발생했습니다. |
내부 오류. |
시스템 오류가 발생했습니다. 잠시 기다린 후 다시 시도해 보십시오. |
법적 고지¶
입력 및 출력의 데이터 분류는 다음 테이블과 같습니다.
입력 데이터 분류 |
출력 데이터 분류 |
지정 |
---|---|---|
Usage Data |
Customer Data |
일반적으로 사용 가능한 함수는 Covered AI 기능입니다. 미리 보기 함수는 Preview AI 기능입니다. [1] |
자세한 내용은 Snowflake AI 및 ML 섹션을 참조하십시오.