You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Node.js版PineconeClient Upsert向量报错,求正确调用方式

正确的Pinecone Node.js客户端Upsert调用方式

错误原因

你遇到的报错是因为Pinecone Node.js客户端的upsert方法要求参数是一个包含upsertRequest属性的对象,而非直接传入向量请求体。

修正后的代码

将index.upsert(upsertRequest)改为把请求体包裹在upsertRequest字段中:

const index = pinecone.Index("imagesindex");
const upsertRequest = {
  vectors: [
    {
      id: "vec1",
      values: [0.1, 0.2, 0.3, 0.4],
      metadata: {
        genre: "drama",
      },
    },
    {
      id: "vec2",
      values: [0.2, 0.3, 0.4, 0.5],
      metadata: {
        genre: "action",
      },
    },
  ],
  namespace: "example-namespace",
};
try {
  // 关键修改:将upsertRequest作为upsertRequest属性的值传入
  const upsertResponse = await index.upsert({ upsertRequest });  
} catch (error) {
  console.log(error);
}

说明

Pinecone的Node.js SDK(基于OpenAPI生成)的方法参数遵循固定结构,所有请求体都需要包裹在对应命名的属性中,这里就是upsertRequest。这样客户端才能正确识别并传递参数到API接口。

内容的提问来源于stack exchange,提问作者tthogho1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 01:05:09