포함은 기계 학습 모델 및 알고리즘에서 쉽게 활용할 수 있는 특수한 형식의 데이터 표현입니다. 포함은 텍스트 조각의 의미 체계적 의미에 대한 조밀한 정보 표현입니다. 각 포함은 부동 소수점 숫자의 벡터입니다. 따라서 벡터 공간의 두 포함 사이의 거리는 원래 형식의 두 입력 간의 의미 체계 유사성과 상관 관계가 있습니다. 예를 들어 두 텍스트가 비슷한 경우 벡터 표현도 유사해야 합니다. Azure Cosmos DB for MongoDB vCore 또는 Azure Database for PostgreSQL - 유연한 서버와 같은 Azure 데이터베이스에서 파워 벡터 유사성 검색을 포함합니다.
포함을 가져오는 방법
텍스트 조각에 대한 포함 벡터를 가져오려면 다음 코드 조각과 같이 포함 엔드포인트에 요청합니다.
using Azure;
using Azure.AI.OpenAI;
Uri oaiEndpoint = new ("https://YOUR_RESOURCE_NAME.openai.azure.com");
string oaiKey = "YOUR_API_KEY";
AzureKeyCredential credentials = new (oaiKey);
OpenAIClient openAIClient = new (oaiEndpoint, credentials);
EmbeddingsOptions embeddingOptions = new()
{
DeploymentName = "text-embedding-ada-002",
Input = { "Your text string goes here" },
};
var returnValue = openAIClient.GetEmbeddings(embeddingOptions);
foreach (float item in returnValue.Value.Data[0].Embedding.ToArray())
{
Console.WriteLine(item);
}
# Azure OpenAI metadata variables
$openai = @{
api_key = $Env:AZURE_OPENAI_API_KEY
api_base = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
api_version = '2024-02-01' # this may change in the future
name = 'YOUR-DEPLOYMENT-NAME-HERE' #This will correspond to the custom name you chose for your deployment when you deployed a model.
}
$headers = [ordered]@{
'api-key' = $openai.api_key
}
$text = 'Your text string goes here'
$body = [ordered]@{
input = $text
} | ConvertTo-Json
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/embeddings?api-version=$($openai.api_version)"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Post -ContentType 'application/json'
return $response.data.embedding
모범 사례
입력이 최대 길이를 초과하지 않는지 확인
최신 포함 모델의 최대 입력 텍스트 길이는 8192개 토큰입니다. 요청하기 전에 입력이 이 제한을 초과하지 않는지 확인해야 합니다.
단일 포함 요청으로 입력 배열을 보내는 경우 최대 배열 크기는 2048입니다.
제한 사항 및 위험
포함 모델은 신뢰할 수 없거나 특정 경우에 사회적 위험을 초래할 수 있으며 완화 조치가 없을 때 피해를 줄 수 있습니다. 책임감 있게 사용하는 방법에 대한 자세한 내용은 책임 있는 AI 콘텐츠를 검토하세요.
다음 단계
Azure OpenAI 및 포함을 사용하여 포함 자습서로 문서 검색을 수행하는 방법에 대해 자세히 알아봅니다.