सेमांटिक सर्च के लिए वेक्टर क्वेरी करना
इस अभ्यास में, आप प्रश्न 'What is in front of the Notre Dame Main Building?' से एक क्वेरी वेक्टर बनाएँगे. इस एम्बेडेड क्वेरी का उपयोग करते हुए, आप 'pinecone-datacamp' इंडेक्स के 'squad_dataset' नेमस्पेस को क्वेरी करेंगे और सबसे मिलते-जुलते शीर्ष पाँच वेक्टर लौटाएँगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Pinecone के साथ AI Applications बनाना
अभ्यास निर्देश
- अपनी API key के साथ Pinecone क्लाइंट इनिशियलाइज़ करें (OpenAI क्लाइंट
clientके रूप में उपलब्ध है). - दिए गए
queryको उसी OpenAI embedding मॉडल से एम्बेड करके एक क्वेरी वेक्टर बनाएँ, जिसका उपयोग आपने बाकी वेक्टर एम्बेड करने में किया था. query_embका उपयोग करके"squad_dataset"नेमस्पेस को क्वेरी करें और सबसे मिलते-जुलते शीर्ष पाँच परिणाम लौटाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Initialize the Pinecone client
pc = Pinecone(api_key="____")
index = pc.Index('pinecone-datacamp')
query = "What is in front of the Notre Dame Main Building?"
# Create the query vector
query_response = ____(
input=____,
model="text-embedding-3-small"
)
query_emb = query_response.data[0].embedding
# Query the index and retrieve the top five most similar vectors
retrieved_docs = ____
for result in retrieved_docs['matches']:
print(f"{result['id']}: {round(result['score'], 2)}")
print('\n')