| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
- 파라미터 힌트
 - 아기동화
 - 동화책
 - 제로샷
 - 퓨샷
 - 조건문
 - Compute
 - 도커
 - Cognitive Search
 - dask
 - Docker
 - Cognitive Service
 - UDF
 - 모험
 - Python
 - 토끼
 - AI 동화
 - Ai
 - 검색
 - 대스크
 - 프롬프트 튜닝
 - 컨텍스트 매니져
 - 인자 힌트
 - 인컨텍스트 러닝
 - Redshift
 - Azure
 - 반복문
 - 파이썬
 - FOR
 - GPT
 
- Today
 
- Total
 
호랭이 분석가
[Azure] Cognitive Search 검색 스코어링 프로파일 설정 (Python) 본문
[Azure] Cognitive Search로 검색 및 필터 설정 (Python)
[Azure] Cognitive Search Index 생성, 삭제, 업로드 Python을 이용하여 Azure Cognitive Search의 Indexes를 생성할 때, 사용할 수 있는 Class는 무엇이 있는지 알아보겠습니다. Azure Cognitive Search client library for Python Ta
dataiger.tistory.com
Azure Cognitive Search로 인덱스를 생성할 때
ScoringProfile을 통해 각 필드별로 가중치를 준다면
검색의 순서를 조절할 수 있습니다.
그럼 인덱스를 생성할 때,
ScoringProfile과 String Type 필드에 사용할 수 있는
TextWeights에 대해 알아보겠습니다.
from azure.core.credentials import AzureKeyCredential
from azrue.search.documents.indexes import SearchIndexClient
search_service_name = 'your-service-name'
key = 'your-api-key'
endpoint = f'https://{serach_service_name}.search.windows.net/'
# 서비스 클라이언트를 생성
index_client = SearchIndexClient(endpoint, AzureKeyCredential(key))
우선 사용 중인 Azure의 정보를 통해
index_client를 생성합니다.
from azure.search.documents.indexes.models import (
    ComplexField,
    CorsOptions,
    SearchIndex,
    SearchFieldDataType,
    SimpleField,
    SearchableField
)
# 생성할 인덱스명 설정
index_name = 'test'
fields = [
        SimpleField(name="testId", type=SearchFieldDataType.String, key=True),
        SearchableField(name="testRate", type=SearchFieldDataType.Double, 
                        filterable=True),
        SearchableField(name="description", type=SearchFieldDataType.String),
        SearchableField(name="testTag", type=SearchFieldDataType.String, 
                        filterable=True, collection=True)
    ]
description, testTag는 String 타입의 필드이고
testTag를 우선적으로 검색에 활용하도록
scoring_profiles를 작성해 보도록 하겠습니다.
from azure.search.documents.indexes.models import (
    ScoringProfile,
    TextWeights
)
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
scoring_profile = ScoringProfile(
        name = 'testProfile',
        text_weights = TextWeights(
        	weight = {
            	'description' : 0.5,
                'testTag' : 1.0
            }
        )
    )
scoring_profiles = []
scoring_profiles.append(scoring_profile)
index = SearchIndex(
    name=index_name,
    fields=fields,
    scoring_profiles=scoring_profiles,
    cors_options=cors_options)
result = index_client.create_index(index)
TextWeights를 통해 testTag 필드에는 1.0의 가중치를
description 필드에는 0.5의 가중치를 할당함으로
testTag에 검색 우선순위를 주었습니다.
TextWeights에서 가중치를 설정하실 때
주의사항으로는 음수(-)와 0.0으로 설정은 불가능하며
0.0보다 큰 수치로만 설정할 수 있습니다.
아래에 Azure Cognitive Search의 Scoring Profile 링크를 참고로 하시면
더 많은 정보를 확인하실 수 있습니다.
azure.search.documents.indexes.models.ScoringProfile class
Defines parameters for a search index that influence scoring in search queries. All required parameters must be populated in order to send to Azure.
learn.microsoft.com
'Azure > Cognitive Search' 카테고리의 다른 글
| [Azure] Cognitive Search Vector Search 벡터 유사도 검색(Python) (0) | 2023.07.11 | 
|---|---|
| [Azure] Cognitive Search로 자동 완성 검색 구현하기 Suggest API(Python) (0) | 2023.07.07 | 
| [Azure] Cognitive Search로 검색 및 필터 설정 (Python) (0) | 2023.07.05 | 
| [Azure] Cognitive Search Index 생성, 삭제, 업로드 (Python) (0) | 2023.07.04 | 
| [Azure] Cognitive Search Index Field 종류 (Python) (0) | 2023.07.04 |