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

使用Pinecone向量数据库遇JsonException:缺少upsertedCount属性

解决Pinecone C# SDK Upsert操作的JSON反序列化错误

问题根源

错误提示的upsertedCount字段缺失,本质是你使用的Pinecone .NET SDK版本与Pinecone官方API的响应结构不兼容——旧版SDK期望响应包含该字段,但当前API返回的响应中没有,导致反序列化失败。

修复方案

  • 升级SDK到最新版本:打开NuGet包管理器,将Pinecone包更新至最新版,新版SDK已适配当前API的响应格式。
  • 检查索引配置:若使用的是服务器less类型索引,旧版SDK对这类索引的响应处理存在兼容性问题,升级SDK即可解决。
  • 调整索引名称:当前代码中的索引名包含空格("pinecone pdfai"),建议改为无空格的命名(如"pinecone-pdfai"),避免潜在的解析异常。
  • 验证API响应:可通过Pinecone官方API文档或直接调用Upsert接口,确认实际返回的响应结构,若确实无upsertedCount字段,说明必须升级SDK。

调整后的示例代码

public static async Task SaveToDatabase(List<float> vector)
{
    string apiKey = "你的API密钥";
    using var pinecone = new PineconeClient(apiKey);
    var index = await pinecone.GetIndex("pinecone-pdfai");
    var vectors = new[]
    {
        new Vector
        {
            Id = "vector1",
            Values = vector.ToArray(),
            Metadata = new MetadataMap
            {
                ["genre"] = "horror",
                ["duration"] = 120
            }
        }
    };
    await index.Upsert(vectors);
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 00:12:08