curl - Accessing Pinecone via PHP - Stack Overflow

I am having trouble accessing Pinecone via PHP. I tried to follow the examples from the documentation,

I am having trouble accessing Pinecone via PHP. I tried to follow the examples from the documentation, but it does not seem to work.

<?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;
$pineconeIndex = 'my-index';

// Initialize clients
$pinecone = new Pinecone($pineconeApiKey);

$respons = $pinecone->index()->list();
if($response->successful()) {
    var_dump($response);
}

I am getting:

_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


Then, I tried to pass the environment, because I saw that in the code: new Pinecone($key, "my-index"); and I had to change to remove control() from the call ($response = $pinecone->control()->index()->list()).

And now I am getting:

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

How can I adjust the code so that it will work?

I am having trouble accessing Pinecone via PHP. I tried to follow the examples from the documentation, but it does not seem to work.

<?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;
$pineconeIndex = 'my-index';

// Initialize clients
$pinecone = new Pinecone($pineconeApiKey);

$respons = $pinecone->index()->list();
if($response->successful()) {
    var_dump($response);
}

I am getting:

_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


Then, I tried to pass the environment, because I saw that in the code: new Pinecone($key, "my-index"); and I had to change to remove control() from the call ($response = $pinecone->control()->index()->list()).

And now I am getting:

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: controller.my-index.pinecone.io (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://controller.my-index.pinecone.io/databases

How can I adjust the code so that it will work?

Share Improve this question edited Mar 27 at 10:57 Ionică Bizău asked Mar 27 at 8:37 Ionică BizăuIonică Bizău 114k94 gold badges310 silver badges487 bronze badges 3
  • Which version are you using? It says there were breaking changes with the 1.0.0 release, so I'm guessing the documentation doesn't reflect that yet. – C3roe Commented Mar 27 at 8:52
  • "I tried to pass the environment" - in the code, this second parameter is named $indexHost - is that what you are referring to, when you say "environment"? What actual value did you use for my-index(I don't assume this was meant literal)? cURL apparently can't resolve the host name, so I'm guessing that your my-index is either wrong, or needs to be registered with Pinecone first or something ...? – C3roe Commented Mar 27 at 8:56
  • I can't reach controller.my-index.pinecone.io either. Are you sure this is a programming-related problem? Did you try to run this with cURL on the command line with any other result? – Nico Haase Commented Mar 27 at 10:13
Add a comment  | 

2 Answers 2

Reset to default 1

Finally I ended by writing my own PHP wrapper for Pinecone. It is pretty raw, but very intuitive to use by knowing the docs.

<?php
  require "pinecone.php";

  $pinecone = new Pinecone(PINECONE_API_KEY, PINECONE_HOST);
  $indexes = $pinecone->getRequest("https://api.pinecone.io/indexes");

  header("Content-Type: application/json");

  // List the vector IDs
  $vectorIds = $pinecone->getRequest("/vectors/list", [
    "namespace" => "example-namespace"
  ]);
  echo json_encode($vectorIds);

  // Upsert vector
  $text = "Hello World";

  // Define the function to compute the embedding (via OpenAI etc)
  $embedding = getEmbedding($text);
  $vector = [
      'id' => md5($text),
      'values' => $embedding,
      'metadata' => [
          'title' => "Example"
      ]
  ];

  // Upsert the vector
  $res = $pinecone->postRequest("/vectors/upsert", [
      "vectors" => [$vector]
  ]);

The constructor is

    public function __construct(
        public string  $apiKey,
        public ?string $indexHost = null,
    ) {}

as per the permalink.

If you take a look at Git Blame, then you can see that this commit has changed the constructor from

    public function __construct(


        public string $apiKey,


        public string $environment,

    )

    {

        // (Temporary) Workaround for https://github/probots-io/pinecone-php/issues/3

        $this->sender()->addMiddleware(function (callable $handler) {

            return function (RequestInterface $request, array $options) use ($handler) {

                return $handler(FetchVectors::queryIdsWorkaround($request), $options);

            };

        });

    }

to

    public function __construct(


        public string  $apiKey,


        public ?string $indexHost = null,

    )

    {

        // (Temporary) Workaround for https://github/probots-io/pinecone-php/issues/3

        $this->sender()->addMiddleware(function (callable $handler) {

            return function (RequestInterface $request, array $options) use ($handler) {

                return $handler(FetchVectors::queryIdsWorkaround($request), $options);

            };

        });

    }

so it is clear that the commit we are discussing changed the second parameter from being a mandatory string for the environment into an optional String.

So you are using an older version than this commit and that obliges you to pass a second parameter.

There are two possible solutions: either you pass a string as a second parameter as per the version you currently use, or update the version, that is, pulling and checking out an appropriate branch, such as master.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744103487a4558633.html

相关推荐

  • curl - Accessing Pinecone via PHP - Stack Overflow

    I am having trouble accessing Pinecone via PHP. I tried to follow the examples from the documentation,

    9天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信