Microsoft에서 관리하는 전 세계 데이터 센터 네트워크를 통해 애플리케이션과 서비스를 빌드, 배포, 관리하기 위한 클라우드 컴퓨팅 플랫폼 및 인프라입니다.
안녕하세요 이상인.
Microsoft Q&A에 질문을 제출해 주셔서 감사합니다. 제 답변은 영어를 한국어로 번역한 것이므로, 문법적인 오류가 있더라도 양해 부탁드립니다.
문제 해결 방법
제공된 정보에 따르면, 문제는 Azure Function에서 반환되는 데이터 형식에 있습니다. Collection(Edm.Double) 오류는 Azure Search Indexer가 Web API Skill로부터 JSON 배열을 수신할 때, Python의 기본 부동 소수점(float) 데이터 형식을 Double로 인식하여 발생하는 문제입니다. np.float32로 변환하고 tolist()를 호출해도, Python의 json.dumps()는 numpy 배열이 아닌 일반 Python float 리스트를 받기 때문에, float를 double로 직렬화하는 기본 동작을 유지합니다.
이 문제를 해결하기 위해서는 다음 두 가지 방법을 사용할 수 있습니다.
1. Azure Function에서 반환되는 데이터 형식 명시적 수정 (권장)
가장 확실한 방법은 Azure Function에서 JSON 문자열을 생성할 때, 각 부동 소수점 숫자를 Single (32비트 부동 소수점) 형식으로 변환하는 것입니다.
A. AzureOpenAIVectorizerSkill 대신 WebApiSkill 사용 시
• json 라이브러리를 사용하여 직접 변환하기는 어렵습니다. 대신, Python에서 json 모듈을 사용하되, 반환되는 숫자를 16진수(hex) 문자열로 인코딩하여 Azure Search에게 Single로 해석하도록 유도하거나, 더 간단하게는 decimal 모듈을 사용하여 정밀도를 제한할 수 있습니다.
• 그러나 가장 안정적인 방법은 Azure Function에서 numpy.float32 배열을 반환하는 것입니다.
B. Azure Function 코드 수정
import json
import logging
import azure.functions as func
import numpy as np
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
req_body = req.get_json()
except ValueError:
return func.HttpResponse("Please pass a JSON object in the request body", status_code=400)
# ---------------------------------------------------------------------------------
# NOTE: Your logic to call AOAI and get embedding data goes here.
# For this example, we'll use a dummy array.
# Replace this with your actual AOAI call.
# ---------------------------------------------------------------------------------
# Assuming `embedding_data` is the list of floats returned by AOAI (Edm.Double)
embedding_data = [i * 0.1 for i in range(1536)] # Dummy data for illustration
# Convert the list of floats to a numpy array of type float32.
# This is the key step to force the data type.
emb = np.array(embedding_data, dtype=np.float32)
# The tolist() method will convert the numpy array to a list of Python floats.
# The crucial part is how Azure Search handles the serialized JSON.
# The error message indicates it's a serialization issue, not a Python issue.
# The following code *should* work, but it's not.
# The problem is that json.dumps serializes Python `float` as `Double`.
# A better approach for WebApiSkill is to ensure the payload is correctly formatted
# and the index field mapping handles the incoming data.
# The `outputFieldMappings` in your indexer configuration looks correct.
response_payload = {
"values": [
{
"recordId": req_body["values"][0]["recordId"],
"data": {
"vectorContent": emb.tolist() # Ensure the name matches the index field
}
}
]
}
return func.HttpResponse(
json.dumps(response_payload),
mimetype="application/json",
status_code=200
)
중요한 참고:
• 이 문제는 json.dumps()가 float를 double로 직렬화하는 Python의 기본 동작과 Azure Search의 엄격한 데이터 형식 검증 사이의 충돌입니다.
• Web API Skill은 JSON 응답을 그대로 전달하기 때문에, Azure Search의 Indexer는 double 배열을 받게 되고, Collection(Edm.Single)로 설정된 인덱스 필드에 매핑하려 할 때 데이터 형식 불일치 오류가 발생합니다.
2. AzureOpenAIVectorizerSkill을 사용한 대체 방법
WebApiSkill 대신 AzureOpenAIVectorizerSkill을 사용하는 것이 더 안정적이고 권장됩니다. 이 내장 스킬은 Azure OpenAI 서비스와 직접 통신하며, 반환된 임베딩 값을 **자동으로 올바른 형식(Edm.Single)**으로 변환하여 인덱서에 전달합니다. 따라서 수동으로 데이터 형식을 변환할 필요가 없습니다.
A. skillset 수정 WebApiSkill을 제거하고 AzureOpenAIVectorizerSkill을 추가합니다.
{
"name": "pdf-skillset",
"skills": [
// ... DocumentExtractionSkill
// ... SplitSkill
{
"@odata.type": "#Microsoft.Skills.Text.AzureOpenAIVectorizerSkill",
"name": "aoaiVectorizer",
"context": "/document/extContent/pages/*",
"modelName": "text-embedding-ada-002",
"resourceUri": "<your-aoai-resource-uri>",
"apiKey": "<your-aoai-api-key>",
"inputs": [
{
"name": "text",
"source": "/document/extContent/pages/*"
}
],
"outputs": [
{
"name": "vector",
"targetName": "vectorContent"
}
]
}
]
}
B. indexer 수정 outputFieldMappings에서 sourceFieldName을 "/document/extContent/pages//vectorContent"에서 "/document/extContent/pages//vector"로 변경해야 합니다.
{
"name": "indexer-1751518729265",
"dataSourceName": "azureblob-1751502489056-datasource",
"skillsetName": "pdf-skillset",
"targetIndexName": "lsiindex01",
"fieldMappings": [
{
"sourceFieldName": "metadata_storage_path",
"targetFieldName": "id",
"mappingFunction": {
"name": "base64Encode"
}
}
],
"outputFieldMappings": [
{
"sourceFieldName": "/document/extContent/pages/*",
"targetFieldName": "pageContent"
},
{
"sourceFieldName": "/document/extContent/pages/*/vector", // 변경된 부분
"targetFieldName": "vectorContent"
}
],
"parameters": {
"batchSize": 100,
"maxFailedItems": -1,
"maxFailedItemsPerBatch": -1,
"configuration": {
"parsingMode": "default",
"allowSkillsetToReadFileData": true,
"dataToExtract": "contentAndMetadata"
}
}
}
결론: WebApiSkill을 통해 직접 임베딩을 관리하는 것은 데이터 형식 변환 문제로 인해 복잡합니다. AzureOpenAIVectorizerSkill은 이 과정을 자동화하고 Azure Search와의 완벽한 호환성을 보장하므로, 가능한 경우 이 스킬을 사용하는 것이 가장 좋습니다. 만약 WebApiSkill 사용이 필수적이라면, Azure Function에서 반환되는 JSON 데이터가 정확히 Collection(Edm.Single) 형식과 일치하도록 응답 형식을 세밀하게 조정해야 합니다.