कलेक्शन में डेटा जोड़ना
अब अपनी कलेक्शन में Netflix की फ़िल्में और टीवी शोज़ जोड़ने का समय है! आपको डॉक्यूमेंट IDs और टेक्स्ट्स की एक सूची दी गई है, जो क्रमशः ids और documents में स्टोर हैं. इन्हें netflix_titles.csv से नीचे दिए गए कोड द्वारा निकाला गया है:
ids = []
documents = []
with open('netflix_titles.csv') as csvfile:
reader = csv.DictReader(csvfile)
for i, row in enumerate(reader):
ids.append(row['show_id'])
text = f"Title: {row['title']} ({row['type']})\nDescription: {row['description']}\nCategories: {row['listed_in']}"
documents.append(text)
एंबेड होने वाली जानकारी का एक उदाहरण देने के लिए, documents का पहला डॉक्यूमेंट यहाँ है:
Title: Dick Johnson Is Dead (Movie)
Description: As her father nears the end of his life, filmmaker Kirsten Johnson stages his death in inventive and comical ways to help them both face the inevitable.
Categories: Documentaries
सारी ज़रूरी functions और packages इम्पोर्ट कर दिए गए हैं, और एक persistent client बना कर client को असाइन कर दिया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
OpenAI API के साथ Embeddings परिचय
अभ्यास निर्देश
- अपनी
netflix_titlesकलेक्शन को दोबारा बनाएँ. - डॉक्यूमेंट्स और उनके IDs कलेक्शन में जोड़ें.
collectionमें डॉक्यूमेंट्स की संख्या और पहली दस आइटम्स प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Recreate the netflix_titles collection
collection = client.____(
name="netflix_titles",
embedding_function=OpenAIEmbeddingFunction(model_name="text-embedding-3-small", api_key="")
)
# Add the documents and IDs to the collection
____
# Print the collection size and first ten items
print(f"No. of documents: {____}")
print(f"First ten documents: {____}")