

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

# Amazon Bedrock에서 순위 재지정 모델 사용
<a name="rerank-use"></a>

순위 재지정 모델을 직접 사용하거나 지식 기반 쿼리 중에 결과를 검색하는 동안 사용할 수 있습니다. 원하는 방법의 탭을 선택한 후 다음 단계를 따릅니다.

------
#### [ Console ]

에서 직접 리랭커 모델을 사용할 수는 AWS Management Console없지만 다음을 수행하여 지식 기반을 쿼리할 때 리랭커 모델을 사용할 수 있습니다.

1. 지식 기반을 쿼리할 때 ![Icon showing three horizontal sliders at different positions for adjusting settings.](http://docs.aws.amazon.com/ko_kr/bedrock/latest/userguide/images/icons/configurations.png) 아이콘을 선택하여 **구성** 창을 엽니다.

1. **순위 재지정** 섹션을 확장합니다.

1. **모델 선택**을 선택하여 순위 재지정 모델을 선택합니다.

1. Amazon Bedrock 지식 기반 서비스 역할에 [순위 재지정 모델을 사용할 수 있는 권한](rerank-prereq.md)이 없는 경우 **서비스 역할 업데이트**를 선택하여 적절한 권한으로 역할을 수정합니다.

1. (선택 사항) **추가 순위 재지정 옵션** 섹션에서 필요한 옵션을 수정합니다.

1. 새 프롬프트를 입력하고 **실행**을 선택합니다. 응답은 순위 재지정 모델을 적용한 후의 결과입니다.

지식 기반 쿼리 수행에 대한 자세한 지침은 [지식 기반 쿼리 및 데이터 검색](kb-test-retrieve.md) 및 [지식 기반 쿼리 및 검색된 데이터를 기반으로 응답 생성](kb-test-retrieve-generate.md) 섹션을 참조하세요.

------
#### [ API ]

지식 기반 쿼리 중에 순위 재지정 모델을 사용하는 방법에 대한 지침은 [지식 기반 쿼리 및 데이터 검색](kb-test-retrieve.md) 및 [지식 기반 쿼리 및 검색된 데이터를 기반으로 응답 생성](kb-test-retrieve-generate.md) 섹션을 참조하세요.

Amazon Bedrock API에서 직접 순위 재지정 모델을 사용하려면 [Amazon Bedrock Agents 런타임 엔드포인트](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-rt)를 사용하여 [순위 재지정](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_Rerank.html) 요청을 보냅니다.

필수 필드는 다음과 같습니다.


****  

| Field | 기본 설명 | 
| --- | --- | 
| 쿼리 | [RerankQuery](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankQuery.html) 객체 하나의 배열입니다. TEXT를 type으로 지정하고 textQuery 필드에 쿼리를 포함합니다. | 
| 소스 | 순위 재지정 모델에 제출할 [RerankSource](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankSource.html) 객체의 배열입니다. 각 RerankSource에 대해 INLINE를 type으로 지정하고 inlineDocumentSource 필드에 [RerankDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankDocument.html) 객체를 포함합니다. RerankDocument에 대한 자세한 내용은 아래를 참조하세요. | 
| rerankingConfiguration | 사용할 순위 재지정 모델의 Amazon 리소스 이름(ARN)과 순위 재지정 경 후 반환할 결과 수, 선택적으로 모델에 대한 추론 구성을 포함합니다. 추가 모델 구성을 키-값 페어로 지정합니다. 자세한 내용은 Cohere 설명서 웹 사이트에서 [순위 재지정](https://docs.cohere.com/reference/rerank)을 참조하세요. | 

다음 필드는 선택 사항입니다.


****  

| Field | 사용 사례: | 
| --- | --- | 
| nextToken | 다음 결과 배치를 제공하기 위해 포함할 수 있는 이전 응답에서 반환된 토큰입니다. | 

포함하는 `RerankSource` 객체의 형식은 문서의 형식에 따라 다릅니다. 다양한 `RerankSource` 유형의 형식을 보려면 문서 형식에 해당하는 탭을 선택합니다.

------
#### [ String ]

문서가 문자열인 경우 [RerankDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankDocument.html) 객체의 `type` 필드 값을 `TEXT`로 지정하고 `text` 필드에 문서를 포함합니다. 예제:

```
{
    "inlineDocumentSource": {
        "textDocument": {
            "text": "string"
        },
        "type": "TEXT"
    },
    "type": "INLINE"
}
```

------
#### [ JSON object ]

문서가 JSON 객체인 경우 [RerankDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankDocument.html) 객체의 `type` 필드 값을 `JSON`으로 지정하고 `jsonDocument` 필드에 문서를 포함합니다. 예제:

```
{
    "inlineDocumentSource": {
        "jsonDocument": JSON value,
        "type": "JSON"
    },
    "type": "INLINE"
}
```

------

`Rerank` 요청에 대한 응답은 `results` 필드에 [RerankResult](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RerankResult.html) 객체 목록을 반환합니다. 각 객체는 다음 필드를 포함합니다.
+ `document` - 제출한 문서에 대한 정보를 포함합니다.
+ `relevanceScore` - 순위 재지정 모델에서 할당한 문서의 관련성 점수입니다.
+ `index` - 목록의 다른 문서와 비교한 문서의 순위를 나타냅니다. 점수가 낮을수록 순위가 높아집니다.

표시할 결과가 너무 많으면 응답은 `nextToken` 필드에 값을 반환합니다. 이 경우 다음 결과 배치를 보려면 후속 요청에 해당 토큰을 포함합니다.

**코드 예제**

다음 예제에서는 AWS SDKs를 사용하여 Rerank API를 호출하는 방법을 보여줍니다.

------
#### [ Python ]

```
import boto3

client = boto3.client('bedrock-agent-runtime', region_name='us-east-1')
response = client.rerank(
    queries=[{
        'type': 'TEXT',
        'textQuery': {'text': 'What is Amazon Bedrock?'}
    }],
    sources=[
        {
            'type': 'INLINE',
            'inlineDocumentSource': {
                'type': 'TEXT',
                'textDocument': {'text': 'Amazon Bedrock is a fully managed service for foundation models.'}
            }
        },
        {
            'type': 'INLINE',
            'inlineDocumentSource': {
                'type': 'TEXT',
                'textDocument': {'text': 'Amazon S3 is an object storage service.'}
            }
        }
    ],
    rerankingConfiguration={
        'type': 'BEDROCK_RERANKING_MODEL',
        'bedrockRerankingConfiguration': {
            'modelConfiguration': {
                'modelArn': 'arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0'
            },
            'numberOfResults': 2
        }
    }
)
for result in response['results']:
    print(f'Index: {result["index"]}, Score: {result["relevanceScore"]}')
```

------
#### [ Node.js ]

```
import { BedrockAgentRuntimeClient, RerankCommand } from "@aws-sdk/client-bedrock-agent-runtime";

const client = new BedrockAgentRuntimeClient({ region: "us-east-1" });
const response = await client.send(new RerankCommand({
    queries: [{
        type: "TEXT",
        textQuery: { text: "What is Amazon Bedrock?" }
    }],
    sources: [
        {
            type: "INLINE",
            inlineDocumentSource: {
                type: "TEXT",
                textDocument: { text: "Amazon Bedrock is a fully managed service for foundation models." }
            }
        },
        {
            type: "INLINE",
            inlineDocumentSource: {
                type: "TEXT",
                textDocument: { text: "Amazon S3 is an object storage service." }
            }
        }
    ],
    rerankingConfiguration: {
        type: "BEDROCK_RERANKING_MODEL",
        bedrockRerankingConfiguration: {
            modelConfiguration: {
                modelArn: "arn:aws:bedrock:us-east-1::foundation-model/cohere.rerank-v3-5:0"
            },
            numberOfResults: 2
        }
    }
}));
for (const result of response.results) {
    console.log(`Index: ${result.index}, Score: ${result.relevanceScore}`);
}
```

------

------