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

PHP接入Pinecone遇错求助:参数错误及连接失败问题排查

解决PHP访问Pinecone的常见错误

错误原因分析

1. 构造函数参数不足

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Probots\Pinecone\Client::__construct(), 1 passed in /home/.../pinecone.php on line 16 and exactly 2 expected in /home/.../probots-io/pinecone-php/src/Client.php:24

Probots\Pinecone\Client的构造函数需要两个必填参数:API密钥和Pinecone环境标识,你只传入了API密钥,导致参数数量不匹配。

2. 环境参数传错导致域名解析失败

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: controller.my-index.pinecone.io...

你误将索引名当作环境参数传入,客户端据此生成了错误的API请求域名(controller.my-index.pinecone.io),而正确的域名格式应为controller.{你的环境标识}.pinecone.io,因此出现域名解析失败。

修正后的代码示例

首先从Pinecone控制台获取你的索引所在的环境标识(比如us-east1-gcp,可在索引详情页查看),然后调整代码如下:

<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

require 'vendor/autoload.php';
require 'config.php';
require 'embeddings.php';

use \Probots\Pinecone\Client as Pinecone;

$pineconeApiKey = PINECONE_API_KEY;
// 替换成你实际的Pinecone环境标识
$pineconeEnvironment = 'us-east1-gcp';
$pineconeIndex = 'my-index';

// 正确初始化客户端:传入API密钥+环境标识
$pinecone = new Pinecone($pineconeApiKey, $pineconeEnvironment);

// 调用control()接口获取索引列表,同时修正变量拼写错误
$response = $pinecone->control()->index()->list();
if($response->successful()) {
    var_dump($response);
}

关键注意事项

  • 区分环境与索引名:环境是Pinecone集群的区域标识,索引名是你创建的具体索引名称,两者不可混淆。
  • 修正变量拼写:原代码中$respons是拼写错误,必须改为$response,否则会触发未定义变量错误。
  • 网络权限检查:确保服务器防火墙允许访问Pinecone的API域名(格式为controller.{环境标识}.pinecone.io)。

内容的提问来源于stack exchange,提问作者Ionică Bizău

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 16:05:55