開始使用免費開始

擷取向量

在這個練習中,已提供一個 ids 清單,裡面包含你在 'datacamp-index' 索引中的不同紀錄 ID。你將使用這些 ID 取回對應的紀錄,並查看其中繼資料。

本練習屬於課程

使用 Pinecone 構建 AI 應用

檢視課程

練習說明

  • 使用你的 API 金鑰初始化 Pinecone 連線。
  • 從已連線的索引中,取回 ids 清單所列 ID 的向量。
  • 建立一個由字典組成的清單,內容為 fetched_vectors 中每筆紀錄的中繼資料。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")

index = pc.Index('datacamp-index')
ids = ['2', '5', '8']

# Fetch the vectors from the connected Pinecone index
fetched_vectors = ____

# Extract the metadata from each result in fetched_vectors
metadatas = [fetched_vectors['____'][____]['____'] for id in ids]
print(metadatas)
編輯並執行程式碼