다음을 통해 공유


AI_GENERATE_CHUNKS(Transact-SQL) (미리 보기)

적용 대상: SQL Server 2025(17.x) 미리 보기

비고

AI_GENERATE_CHUNKS SQL Server 2025의 현재 미리 보기 상태입니다.

AI_GENERATE_CHUNKS 는 형식, 크기 및 소스 식을 기반으로 "청크" 또는 텍스트 조각을 만드는 테이블 반환 함수입니다.

호환성 수준 170

AI_GENERATE_CHUNKS 에서는 호환성 수준이 170 이상이어야 합니다. 수준이 170보다 작으면 데이터베이스 엔진에서 함수를 AI_GENERATE_CHUNKS 찾을 수 없습니다.

데이터베이스의 호환성 수준을 변경하려면 데이터베이스의 호환성 수준 보기를 참조하거나 변경합니다.

문법

Transact-SQL 구문 표기 규칙

AI_GENERATE_CHUNKS (source = text_expression
                    , chunk_type = FIXED
                   [ [ , ] chunk_size = numeric_expression ]
                   [ [ , ] overlap = numeric_expression ]
                   [ [ , ] enable_chunk_set_id = numeric_expression]
)

주장들

원본

모든 문자 형식의 입니다(예: nvarchar, varchar, nchar 또는 char).

chunk_type

텍스트/문서를 청크할 형식 또는 메서드의 이름을 지정하는 문자열 리터럴로, 열의 값이나 텍스트가 될 NULL 수 없습니다.

이 릴리스에 허용되는 값:

  • FIXED

chunk_size

chunk_type 매개 변수는 FIXEDtinyint, smallint, int 또는 bigint 형식의 변수, 리터럴 또는 스칼라 식으로 지정된 각 청크의 문자/단어 개수 크기를 설정합니다. chunk_size 음수 또는 0(NULL)일 0수 없습니다.

겹침

겹침 매개 변수는 현재 청크에 포함해야 하는 이전 텍스트의 백분율을 결정합니다. 이 백분율은 문자의 크기를 계산하기 위해 매개 변수에 적용 chunk_size 됩니다. 겹침 값은 tinyint, smallint, int 또는 bigint 형식의 변수, 리터럴 또는 스칼라 식으로 지정할 수 있습니다. 0과0 50 사이의 정수여야 하며 NULL 또는 음수일 수 없습니다. 기본값은 0(0)입니다.

enable_chunk_set_id

출력 열을 사용하거나 사용하지 않도록 설정하는 플래그 역할을 하는 int 또는 chunk_set_id 식입니다. 동일한 원본에 속한 반환된 청크를 그룹화할 수 있도록 숫자를 반환하는 열입니다. 값이 1이면 열을 사용할 수 있습니다. enable_chunk_set_id 생략되거나 NULL이거나 값이 0 chunk_set_id 이면 열이 비활성화되고 반환되지 않습니다.

반환 형식

AI_GENERATE_CHUNKS 는 다음 열이 있는 테이블을 반환합니다.

열 이름 데이터 형식 설명
chunk 원본 식 데이터 형식과 동일 원본 식에서 청크된 텍스트가 반환되었습니다.
chunk_order int 각 청크가 처리된 순서와 관련된 순서가 지정된 숫자의 시퀀스입니다 11.
chunk_offset int 청크 처리 시작과 관련하여 원본 데이터/문서의 청크 위치입니다.
chunk_length int 반환된 텍스트 청크의 문자 길이입니다.
chunk_set_id int 원본 식, 문서 또는 행의 모든 청크를 그룹화할 ID를 포함하는 선택적 열 입니다. 여러 문서 또는 행이 단일 트랜잭션에서 청크로 분할되는 경우 각각 다른 chunk_set_id항목이 제공됩니다. 표시 유형은 매개 변수에 의해 제어됩니다 enable_chunk_set_id .

예제 반환

다음은 다음 매개 변수를 사용하는 반환 결과의 AI_GENERATE_CHUNKS 예입니다.

  • 의 청크 유형입니다 FIXED.

  • 청크 크기는 50자입니다.

  • 'chunk_set_id'을 사용할 수 있습니다.

  • 청크 텍스트: All day long we seemed to dawdle through a country which was full of beauty of every kind. Sometimes we saw little towns or castles on the top of steep hills such as we see in old missals; sometimes we ran by rivers and streams which seemed from the wide stony margin on each side of them to be subject to great floods.

청크(chunk) chunk_order chunk_offset chunk_length chunk_set_id
All day long we seemed to dawdle through a country 1 1 50 1
which was full of beauty of every kind. Sometimes 2 51 50 1
we saw little towns or castles on the top of stee 3 101 50 1
p hills such as we see in old missals; sometimes w 4 151 50 1
e ran by rivers and streams which seemed from the 5 201 50 1
wide stony margin on each side of them to be subje 6 251 50 1
ct to great floods. 7 301 19 1

비고

AI_GENERATE_CHUNKS 는 여러 행이 있는 테이블에서 사용할 수 있습니다. 청크 크기와 청크 분할되는 텍스트 양에 따라 결과 집합은 열이 있는 새 열 또는 문서를 chunk_set_id 시작할 때를 나타냅니다. 다음 예제 chunk_set_id 에서는 첫 번째 행의 텍스트 청크를 완료하고 두 번째 행으로 이동할 때 변경됩니다. 새 시작점을 나타내기 위해 chunk_order 초기화 및 chunk_offset 초기화되는 값입니다.

CREATE TABLE textchunk (text_id INT IDENTITY(1,1) PRIMARY KEY, text_to_chunk nvarchar(max));
GO

INSERT INTO textchunk (text_to_chunk)
VALUES
('All day long we seemed to dawdle through a country which was full of beauty of every kind. Sometimes we saw little towns or castles on the top of steep hills such as we see in old missals; sometimes we ran by rivers and streams which seemed from the wide stony margin on each side of them to be subject to great floods.'),
('My Friend, Welcome to the Carpathians. I am anxiously expecting you. Sleep well to-night. At three to-morrow the diligence will start for Bukovina; a place on it is kept for you. At the Borgo Pass my carriage will await you and will bring you to me. I trust that your journey from London has been a happy one, and that you will enjoy your stay in my beautiful land. Your friend, DRACULA')
GO

SELECT c.*
FROM textchunk t
CROSS APPLY
   AI_GENERATE_CHUNKS(source = text_to_chunk, chunk_type = FIXED, chunk_size = 50, enable_chunk_set_id = 1) c
청크(chunk) chunk_order chunk_offset chunk_length chunk_set_id
All day long we seemed to dawdle through a country 1 1 50 1
which was full of beauty of every kind. Sometimes 2 51 50 1
we saw little towns or castles on the top of stee 3 101 50 1
p hills such as we see in old missals; sometimes w 4 151 50 1
e ran by rivers and streams which seemed from the 5 201 50 1
wide stony margin on each side of them to be subje 6 251 50 1
ct to great floods. 7 301 19 1
My Friend, Welcome to the Carpathians. I am anxi 1 1 50 2
ously expecting you. Sleep well to-night. At three 2 51 50 2
to-morrow the diligence will start for Bukovina; 3 101 50 2
a place on it is kept for you. At the Borgo Pass m 4 151 50 2
y carriage will await you and will bring you to me 5 201 50 2
. I trust that your journey from London has been a 6 251 50 2
happy one, and that you will enjoy your stay in m 7 301 50 2
y beautiful land. Your friend, DRACULA 8 (여덟) 351 38 2

예시

A. FIXED 형식 및 크기가 100자인 텍스트 열 청크

다음 예제에서는 텍스트 열을 청크하는 데 사용합니다 AI_GENERATE_CHUNKS . 100자 중 chunk_typeFIXED 100자를 사용합니다chunk_size.

SELECT
    c.chunk
FROM
   docs_table t
CROSS APPLY
   AI_GENERATE_CHUNKS(source = text_column, chunk_type = FIXED, chunk_size = 100) c

B. 겹치는 텍스트 열 청크

다음 예제에서는 겹침을 사용하여 텍스트 열을 청크하는 데 사용합니다 AI_GENERATE_CHUNKS . FIXED의 chunk_type 100자의 chunk_size 10%의 겹침을 사용합니다.

SELECT
    c.chunk
FROM
   docs_table t
CROSS APPLY
   AI_GENERATE_CHUNKS(source = text_column, chunk_type = FIXED, chunk_size = 100, overlap = 10) c

C. AI_GENERATE_CHUNKS AI_GENERATE_EMBEDDINGS 사용

이 예제에서는 AI_GENERATE_EMBEDDINGSAI_GENERATE_CHUNKS 텍스트 청크에서 포함을 만든 다음 AI 모델 추론 엔드포인트에서 반환된 벡터 배열을 테이블에 삽입합니다.

INSERT INTO
    my_embeddings (chunked_text, vector_embeddings)
SELECT
    c.chunk,
    AI_GENERATE_EMBEDDINGS(c.chunk USE MODEL MyAzureOpenAiModel)
FROM
    table_with_text t
CROSS APPLY
    AI_GENERATE_CHUNKS(source = t.text_to_chunk, chunk_type = FIXED, chunk_size = 100) c