回傳最相似的向量
查詢向量是許多 AI 應用的基礎。它包含將使用者輸入做成嵌入向量(embedding)、與資料庫中的向量比較,並回傳最相似的向量。
在這個練習中,你會拿到一個名為 vector 的神祕向量,並用它查詢名為 'datacamp-index' 的索引。
本練習屬於課程
使用 Pinecone 構建 AI 應用
練習說明
- 使用你的 API 金鑰初始化 Pinecone 連線。
- 取回與
vector最相似的「3」筆向量紀錄。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")
index = pc.Index('datacamp-index')
# Retrieve the top three most similar records
query_result = ____
print(query_result)