开始使用免费开始使用

带元数据的向量写入

开始写入数据吧!您将写入 vectors,它是一个由字典组成的列表,包含向量取值、ID,以及相关的元数据。它们已经按可直接插入索引的格式准备好,无需再做处理。

下面再次提醒一下 vectors 的结构。

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

本练习是课程的一部分

使用 Pinecone 构建 AI 应用

查看课程

练习说明

  • 使用您的 API 密钥初始化 Pinecone 连接。
  • 连接到名为 "datacamp-index" 的索引。
  • vectors upsert 到该索引中。
  • 打印该索引的描述性统计信息。

交互式实操练习

通过完成这段示例代码来试试这个练习。

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

# Connect to your index
index = pc.____("datacamp-index")

# Ingest the vectors and metadata
____

# Print the index statistics
print(____)
编辑并运行代码