開始使用免費開始

變更距離度量

預設情況下,Pinecone 使用 cosine similarity(餘弦相似度)來計算向量之間的相似度分數,這些分數會在查詢時用來找出最相似的向量。Pinecone 也支援其他距離度量,包括歐式距離(Euclidean distance)與點積(dot product)。

距離度量是在建立索引時設定,之後無法變更。在本練習中,你將練習建立一個使用 dot product 作為距離度量的索引。

本練習屬於課程

使用 Pinecone 構建 AI 應用

檢視課程

練習說明

  • 使用你的 API 金鑰初始化 Pinecone 連線。
  • 建立一個名為 "dotproduct-index"、且使用 dot product 距離度量的新索引。
  • 列出你的索引,確認它已建立且度量方式正確。

動手互動練習

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

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

# Create an index that uses the dot product distance metric
pc.create_index(
    name="____",
    dimension=1536,
    ____,
    spec=ServerlessSpec(
        cloud='aws',
        region='us-east-1'
    )
)

# Print a list of your indexes
print(____)
編輯並執行程式碼