更改距离度量
默认情况下,Pinecone 使用余弦相似度作为距离度量来计算向量之间的相似度分数,并在查询时用于查找最相似的向量。Pinecone 还支持其他距离度量,包括欧几里得距离和点积。
距离度量在创建索引时设置,之后无法更改。在本练习中,您将练习创建一个使用点积距离度量的索引。
本练习是课程的一部分
使用 Pinecone 构建 AI 应用
练习说明
- 使用您的 API 密钥初始化 Pinecone 连接。
- 创建一个名为
"dotproduct-index"的新索引,并将距离度量设为点积。 - 列出您的索引,验证它已创建且度量设置正确。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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(____)