메타데이터를 활용한 필터링
데이터베이스에서 메타데이터를 활용하면 추가 조건에 따라 결과를 더 쉽게 필터링할 수 있어요. 여러분이 만든 영화 추천이 사용자 선호 설정에 접근해, 그 기준으로 결과를 더 좁힐 수 있다고 상상해 보세요.
이번 연습에서는 추가 메타데이터를 사용해 Netflix 영화 추천을 필터링해 보겠습니다. netflix_titles 컬렉션에는 각 제목에 메타데이터가 추가되었고, 여기에는 제목의 연령 등급인 'rating'과 최초 공개 연도인 'release_year'가 포함되어 있어요.
업데이트된 항목 예시는 다음과 같아요:
{'ids': ['s999'],
'embeddings': None,
'metadatas': [{'rating': 'TV-14', 'release_year': 2021}],
'documents': ['Title: Searching For Sheela (Movie)\nDescription: Journalists and fans await Ma Anand Sheela as the infamous former Rajneesh commune’s spokesperson returns to India after decades for an interview tour.\nCategories: Documentaries, International Movies'],
'uris': None,
'data': None}
이 연습은 강의의 일부입니다
OpenAI API로 시작하는 임베딩 Introduction
연습 안내
reference_texts를 사용해 컬렉션에서 결과 2개를 쿼리하세요.'G'등급이면서2019년 이전에 공개된 제목만 결과로 필터링하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
collection = client.get_collection(
name="netflix_titles",
embedding_function=OpenAIEmbeddingFunction(model_name="text-embedding-3-small", api_key="")
)
reference_texts = ["children's story about a car", "lions"]
# Query two results using reference_texts
result = collection.query(
____,
____,
# Filter for titles with a G rating released before 2019
____={
____: [
{"____":
{____}
},
{"____":
{____}
}
]
}
)
print(result['documents'])