

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 문서를 지식 기반에 직접 수집
<a name="kb-direct-ingestion-add"></a>

이 주제에서는 문서를 지식 기반에 직접 수집하는 방법을 설명합니다. 데이터 소스에 따라 직접 수집할 수 있는 문서 유형에는 제한이 적용됩니다. 수집할 문서를 지정하는 데 사용할 수 있는 방법에 대한 제한 사항은 다음 표를 참조하세요.


****  

| 데이터 소스 유형 | 인라인으로 정의된 문서 | Amazon S3 위치의 문서 | 
| --- | --- | --- | 
| Amazon S3 | ![\[Red circular icon with an X symbol, indicating cancellation or denial.\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/images/icons/icon-no.png)아니요 | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/images/icons/icon-yes.png)예 | 
| 사용자 지정 | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/images/icons/icon-yes.png)예 | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/images/icons/icon-yes.png)예 | 

해당하는 사용 사례의 섹션을 확장해 내용을 살펴보세요.

**참고**  
콘솔을 사용할 때 지식 기반에 최대 10개의 문서를 직접 수집할 수 있습니다. 대신 `IngestKnowledgeBaseDocuments` API를 사용하는 경우 지식 기반에 최대 25개의 문서를 수집할 수 있습니다. 이 할당량에 대한 자세한 내용은 *AWS 일반 참조 안내서*의 [Amazon Bedrock Service Quotas](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#limits_bedrock)를 참조하세요.

## 콘솔을 사용합니다.
<a name="kb-direct-ingestion-add-console"></a>

에서 직접 문서를 추가하거나 수정하려면 다음을 AWS Management Console수행합니다.

1. Amazon Bedrock 콘솔을 사용할 권한이 있는 IAM 자격 증명 AWS Management Console 으로에 로그인합니다. 그 다음 [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock)에서 Amazon Bedrock 콘솔을 엽니다.

1. 왼쪽 탐색 창에서 **지식 기반**을 선택합니다.

1. **지식 기반** 섹션에서 문서를 수집할 지식 기반을 선택합니다.

1. **데이터 소스** 섹션에서 문서를 추가, 수정 또는 삭제하려는 데이터 소스를 선택합니다.

1. **문서** 섹션에서 **문서 추가**를 선택합니다. 그런 다음, 다음 중 하나를 수행합니다.
   + 문서를 직접 추가하거나 수정하려면 **문서 직접 추가**를 선택합니다. 뒤이어 다음과 같이 하세요.

     1. **문서 식별자** 필드에서 문서의 고유한 이름을 지정합니다. 데이터 소스에 이미 있는 이름을 지정하면 문서가 대체됩니다.

     1. 문서를 업로드하려면 **업로드**를 선택합니다. 문서 인라인을 정의하려면 **문서 인라인 추가**를 선택하고 형식을 선택한 다음 상자에 문서 텍스트를 입력합니다.

     1. (선택 사항) 메타데이터를 문서와 연결하려면 **메타데이터 추가**를 선택하고 키, 유형 및 값을 입력합니다.
   + S3 위치를 지정하여 문서를 추가하거나 수정하려면 **S3 문서 추가**를 선택합니다. 뒤이어 다음과 같이 하세요.

     1. **문서 식별자** 필드에서 문서의 고유한 이름을 지정합니다. 데이터 소스에 이미 있는 이름을 지정하면 문서가 대체됩니다.

     1. 문서의 **S3 위치가** 현재 AWS 계정에 있는지 아니면 다른 계정에 있는지 지정합니다. 그런 다음 문서의 S3 URI를 지정합니다.

     1. (선택 사항) 메타데이터를 문서와 연결하려면 **메타데이터 소스**를 선택합니다. 메타데이터의 S3 URI를 지정하거나 **메타데이터 추가**를 선택하고 키, 유형 및 값을 입력합니다.

1. 문서 및 관련 메타데이터를 수집하려면 **추가**를 선택합니다.

## API 사용
<a name="kb-direct-ingestion-add-api"></a>

Amazon Bedrock API를 사용하여 문서를 지식 기반에 직접 수집하려면 [Amazon Bedrock Agents 빌드 타임 엔드포인트](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt)를 사용하여 [IngestKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_IngestKnowledgeBaseDocuments.html) 요청을 보내고 지식 기반 및 연결된 데이터 소스의 ID를 지정합니다.

**참고**  
지식 기반에 이미 있는 문서 식별자 또는 S3 위치를 지정하면 문서가 새 콘텐츠로 덮어씁니다.

요청 본문에는 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 객체 배열에 매핑되는 `documents` 필드 1개가 포함되며, 각 필드는 데이터 소스에 추가하고 지식 기반에 수집할 문서의 콘텐츠 및 선택적 메타데이터를 나타냅니다. [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 객체에는 다음 필드가 포함됩니다.
+ 콘텐츠 - 추가할 문서의 콘텐츠에 대한 정보가 포함된 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 객체에 매핑됩니다.
+ 메타데이터 - (선택 사항) 추가할 문서의 메타데이터에 대한 정보가 포함된 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 객체에 매핑됩니다. 검색 중에 메타데이터를 사용하는 방법에 대한 자세한 내용은 [쿼리와 응답 생성 구성 및 사용자 지정](kb-test-config.md)의 **메타데이터 및 필터링** 섹션을 참조하세요.

주제를 선택하여 다양한 데이터 소스 유형에 대한 문서를 수집하는 방법을 알아보거나 예제를 확인합니다.

**Topics**
+ [사용자 지정 데이터 소스에 연결된 지식 기반에 문서 수집](#kb-direct-ingestion-add-custom)
+ [Amazon S3 데이터 소스에 연결된 지식 기반에 문서 수집](#kb-direct-ingestion-add-s3)
+ [요청 본문의 예](#w2aac28c10c23c19c17c11b3c19)

### 사용자 지정 데이터 소스에 연결된 지식 기반에 문서 수집
<a name="kb-direct-ingestion-add-custom"></a>

지정한 `dataSourceId`가 사용자 지정 데이터 소스에 속하는 경우 `documents` 배열의 각 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 객체에 대한 콘텐츠와 메타데이터를 추가할 수 있습니다.

사용자 지정 데이터 소스에 추가된 문서의 내용은 다음과 같은 방법으로 정의할 수 있습니다.

#### 문서를 인라인으로 정의
<a name="kb-direct-ingestion-add-custom-inline"></a>

다음과 같은 유형의 문서를 인라인으로 정의할 수 있습니다.

------
#### [ Text ]

문서가 텍스트인 경우 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 객체는 다음 형식이어야 합니다.

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "inlineContent": { 
            "textContent": { 
                "data": "string"
            },
            "type": "TEXT"
        },
        "sourceType": "IN_LINE"
    },
    "dataSourceType": "CUSTOM"
}
```

`id` 필드에 문서의 ID를 포함하고 `data` 필드에 문서의 텍스트를 포함합니다.

------
#### [ Bytes ]

문서에 텍스트 이외의 요소가 포함되어 있다면, 이를 Base64 문자열로 변환합니다. 그러면 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 객체는 다음 형식이어야 합니다.

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "inlineContent": { 
            "byteContent": { 
                "data": blob,
                "mimeType": "string"
            },
            "type": "BYTE"
        },
        "sourceType": "IN_LINE"
    },
    "dataSourceType": "CUSTOM"
}
```

`id` 필드에 문서의 ID, `data` 필드에 Base64로 인코딩된 문서, `mimeType` 필드에 MIME 유형을 포함합니다.

------

#### S3에서 문서 수집
<a name="w2aac28c10c23c19c17c11b3c15b7b3"></a>

S3 위치에서 문서를 수집하는 경우 `content` 필드의 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 객체는 다음 형식이어야 합니다.

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "s3Location": { 
            "bucketOwnerAccountId": "string",
            "uri": "string"
        },
        "sourceType": "S3"
    },
    "dataSourceType": "CUSTOM"
}
```

`id` 필드에 문서의 ID, `bucketOwnerAccountId` 필드에 문서가 포함된 S3 버킷의 소유자, `uri` 필드에 문서의 S3 URI를 포함합니다.

문서의 메타데이터는 다음과 같은 방법으로 정의할 수 있습니다.

#### 메타데이터를 인라인으로 정의
<a name="w2aac28c10c23c19c17c11b3c15c11b1"></a>

메타데이터를 인라인으로 정의하는 경우 `metadata` 필드의 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 객체는 다음 형식이어야 합니다.

```
{ 
    "inlineAttributes": [ 
        { 
            "key": "string",
            "value": { 
                "stringValue": "string",
                "booleanValue": boolean,
                "numberValue": number,
                "stringListValue": [ "string" ],
                "type": "STRING" | "BOOLEAN" | "NUMBER" | "STRING_LIST"
            }
        }
    ],
    "type": "IN_LINE_ATTRIBUTE"
}
```

추가하는 각 속성에 대해 `key` 필드에 키를 정의합니다. `type` 필드에 값의 데이터 형식을 지정하고 데이터 유형에 해당하는 필드를 포함합니다. 예를 들어 문자열을 포함하는 경우 속성은 다음 형식입니다.

```
{ 
    "key": "string",
    "value": { 
        "stringValue": "string",
        "type": "STRING"
    }
}
```

#### S3에서 메타데이터 수집
<a name="w2aac28c10c23c19c17c11b3c15c11b3"></a>

S3 위치에 `.metadata.json` 확장명이 있는 파일에서 메타데이터를 수집할 수도 있습니다. 메타데이터 파일의 형식에 대한 자세한 내용은 [지식 기반을 위해 Amazon S3에 연결](s3-data-source-connector.md)의 **문서 메타데이터 필드** 섹션을 참조하세요.

메타데이터가 S3 파일에서 가져온 경우 `metadata` 필드의 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 객체는 다음 형식이어야 합니다.

```
{
    "s3Location": { 
        "bucketOwnerAccountId": "string",
        "uri": "string"
    },
        "type": "S3_LOCATION"
    }
 }
```

`bucketOwnerAccountId` 필드에 메타데이터 파일이 포함된 S3 버킷의 소유자와 `uri` 필드에 메타데이터 파일의 S3 URI를 포함합니다.

**주의**  
콘텐츠를 인라인으로 정의한 경우 메타데이터를 인라인으로 정의해야 합니다.

### Amazon S3 데이터 소스에 연결된 지식 기반에 문서 수집
<a name="kb-direct-ingestion-add-s3"></a>

지정한 `dataSourceId`가 S3 데이터 소스에 속하는 경우 `documents` 배열의 각 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 객체에 대한 콘텐츠와 메타데이터를 추가할 수 있습니다.

**참고**  
S3 데이터 소스의 경우 S3 위치에서만 콘텐츠 및 메타데이터를 추가할 수 있습니다.

S3에 추가할 S3 문서의 콘텐츠를 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 객체에 다음 형식으로 추가해야 합니다.

```
{ 
    "dataSourceType": "string",
    "s3": { 
        "s3Location": { 
            "uri": "string"
        }
    }
}
```

`bucketOwnerAccountId` 필드에 문서가 포함된 S3 버킷의 소유자와 `uri` 필드에 문서의 S3 URI를 포함합니다.

사용자 지정 데이터 소스에 추가된 문서의 메타데이터는 다음 형식으로 정의할 수 있습니다.

```
{
    "s3Location": { 
        "bucketOwnerAccountId": "string",
        "uri": "string"
    },
        "type": "S3_LOCATION"
    }
 }
```

**주의**  
S3 데이터 소스에 연결된 지식 기반에 직접 수집하는 문서는 S3 버킷 자체에 추가되지 않습니다. 데이터 소스를 동기화할 경우 제거되거나 덮어쓰지 않도록 이러한 문서를 S3 데이터 소스에도 추가하는 것이 좋습니다.

### 요청 본문의 예
<a name="w2aac28c10c23c19c17c11b3c19"></a>

다음 섹션을 지수화하여 `IngestKnowledgeBaseDocuments`의 다양한 사용 사례에 대한 요청 본문을 확인합니다.

#### 사용자 지정 데이터 소스에 사용자 지정 텍스트 문서를 추가하고 수집합니다
<a name="w2aac28c10c23c19c17c11b3c19b5b1"></a>

다음 예제에서는 사용자 지정 데이터 소스에 하나의 텍스트 문서를 추가하는 방법을 보여줍니다.

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "textContent": { 
                     "data": "Hello world!"
                  },
                  "type": "TEXT"
               },
               "sourceType": "IN_LINE"
            }
         }
     }
   ]
}
```

#### 사용자 지정 데이터 소스에 Base64로 인코딩된 문서 추가 및 수집
<a name="w2aac28c10c23c19c17c11b3c19b5b3"></a>

다음 예제에서는 사용자 지정 데이터 소스에 PDF 문서를 추가하는 방법을 보여줍니다.

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "byteContent": { 
                     "data": "<Base64-encoded string>",
                     "mimeType": "application/pdf"
                  },
                  "type": "BYTE"
               },
               "sourceType": "IN_LINE"
            }
         }
     }
   ]
}
```

#### S3 위치의 문서를 사용자 지정 데이터 소스에 연결된 지식 기반에 추가하고 수집합니다
<a name="w2aac28c10c23c19c17c11b3c19b5b5"></a>

다음 예제에서는 S3 위치에서 사용자 지정 데이터 소스에 텍스트 문서 하나를 추가하는 방법을 보여줍니다.

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "s3": {
                "s3Location": {
                    "uri": "amzn-s3-demo-bucket"
                }
               },
               "sourceType": "S3"
            }
         }
     }
   ]
}
```

#### 사용자 지정 데이터 소스에 연결된 지식 기반에 인라인 문서 추가 및 인라인 메타데이터 포함
<a name="w2aac28c10c23c19c17c11b3c19b5b7"></a>

다음 예제는 두 개의 속성을 포함하는 메타데이터와 함께 문서의 사용자 지정 데이터 소스에 대한 인라인 추가를 보여줍니다.

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "textContent": { 
                     "data": "Hello world!"
                  },
                  "type": "TEXT"
               },
               "sourceType": "IN_LINE"
            }
         },
         "metadata": {
            "inlineAttributes": [ 
               { 
                  "key": "genre",
                  "value": {
                     "stringValue": "pop",
                     "type": "STRING"
                  }
               },
               { 
                  "key": "year",
                  "value": { 
                     "numberValue": 1988,
                     "type": "NUMBER"
                  }
               }
            ],
            "type": "IN_LINE_ATTRIBUTE"
         }
     }
   ]
}
```

#### S3 데이터 소스에 연결된 지식 기반에 문서를 추가하고 이에 대한 메타데이터 포함
<a name="w2aac28c10c23c19c17c11b3c19b5b9"></a>

다음 예제에서는 S3 데이터 소스에 메타데이터와 함께 문서를 추가하는 방법을 보여줍니다. S3를 통해서만 메타데이터를 포함할 수 있습니다.

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
    "documents": [ 
        { 
            "content": { 
                "dataSourceType": "S3",
                "s3": { 
                "s3Location": {
                    "uri": "amzn-s3-demo-bucket"
                }
            }
        },
        "metadata": {
            "s3Location": {
                "bucketOwnerId": "111122223333",
                "uri": "amzn-s3-demo-bucket"
            },
                "type": "S3_LOCATION"
            }
        }
    ]
}
```