การอัปเดตและลบรายการออกจากคอลเลกชัน
การจัดเก็บเอกสารไว้ในฐานข้อมูลเวกเตอร์แล้ว ไม่ได้หมายความว่าจะแก้ไขหรือเพิ่มเติมข้อมูลไม่ได้อีก
ในแบบฝึกหัดนี้ มีชื่อ Netflix ใหม่ 2 รายการที่เก็บอยู่ใน new_data:
[{"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 เหล่านี้ในฐานข้อมูล ขึ้นอยู่กับว่ามีอยู่ในคอลเลกชันแล้วหรือไม่
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้าง Embeddings ด้วย OpenAI API
คำแนะนำการฝึกหัด
- ดึง ID และเอกสารออกจาก
new_dataแล้วใช้เมธอดเดียวเพื่ออัปเดตรายการที่มีอยู่แล้วในคอลเลกชัน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)