開始使用免費開始

檢查維度數

你現在已經具備把向量匯入全新 Pinecone 索引的知識了!在開始之前,先確認這些向量與新索引的維度數相容。

已提供一個要匯入的紀錄清單 vectors(由多個字典組成)。其結構預覽如下:

vectors = [
    {
        "id": "0",
        "values": [0.025525547564029694, ..., 0.0188823901116848]
        "metadata": {"genre": "action", "year": 2024}
    },
        ...,
]

本練習屬於課程

使用 Pinecone 構建 AI 應用

檢視課程

練習說明

  • 使用你的 API 金鑰初始化 Pinecone 連線。
  • 建立一個名為 "datacamp-index" 的全新無伺服器 Pinecone 索引;其他設定維持不變。
  • 使用串列生成式(list comprehension)檢查 vectors 中每個向量的長度是否為 1536,並回傳單一的 TrueFalse,表示是否全部都符合此條件。

動手互動練習

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

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

# Create your Pinecone index
pc.____(
    name="____", 
    dimension=1536, 
    spec=____(
        cloud='aws', 
        region='us-east-1'
    )
)

# Check that each vector has a dimensionality of 1536
vector_dims = [____(vector['____']) == ____ for vector in ____]
print(____(vector_dims))
編輯並執行程式碼