시작하기무료로 시작하기

컬렉션에서 항목 업데이트 및 삭제하기

문서를 벡터 데이터베이스에 저장했다고 해서, 컬렉션에 새로 추가하거나 기존 항목을 업데이트하지 못하는 것은 아니에요.

이 연습 문제에서는 new_data에 저장된 Netflix 신규 타이틀 두 개가 제공돼요:

[{"id": "s1001", "document": "Title: Cats & Dogs (Movie)\nDescription: A look at the top-secret, high-tech espionage war going on between cats and dogs, of which their human owners are blissfully unaware."},
 {"id": "s6884", "document": 'Title: Goosebumps 2: Haunted Halloween (Movie)\nDescription: Three teens spend their Halloween trying to stop a magical book, which brings characters from the "Goosebumps" novels to life.\nCategories: Children & Family Movies, Comedies'}]

이 ID들이 컬렉션에 이미 있는지 여부에 따라 데이터베이스에서 추가하거나 업데이트하게 될 거예요.

이 연습은 강의의 일부입니다

OpenAI API로 시작하는 임베딩 Introduction

강의 보기

연습 안내

  • new_data에서 ID와 문서를 추출한 후, 하나의 메서드로 netflix_titles 컬렉션에 이미 존재하면 업데이트하고, 없으면 추가하세요.
  • 항목을 추가/업데이트한 뒤, ID가 's95'인 항목을 삭제하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

collection = client.get_collection(
  name="netflix_titles",
  embedding_function=OpenAIEmbeddingFunction(model_name="text-embedding-3-small", api_key="")
)

# Update or add the new documents
____(
    ids=____,
    documents=____
)

# Delete the item with ID "s95"
____

result = collection.query(
    query_texts=["films about dogs"],
    n_results=3
)
print(result)
코드 편집 및 실행