Skip to content

Commit

Permalink
Merge branch 'feature/pinecone-api-upgrade' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
derpoho committed Feb 21, 2024
2 parents a425b4b + 88d3415 commit 67bf3e1
Show file tree
Hide file tree
Showing 110 changed files with 1,783 additions and 1,922 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Pinecone PHP

A beautiful, extendable PHP Package to communicate with your [pinecone.io](https://pinecone.io) indices, collections and
vectors, powered by [Saloon](https://github.com/sammyjo20/saloon).
vectors, powered by [Saloon](https://github.com/saloonphp/saloon).

> **Info**
> This package is still in active development, but is already used in some production scenarios.
> Check Todo list below for more information what's missing.
> This package is not yet usable. Working on Upgrading to the latest Pinecone API.
[![probots.io](art/probots-banner-1000x400.png)](https://probots.io)

Expand Down
Binary file added art/pinecone-php-img-1200x600.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/probots-banner-1000x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
],
"require": {
"php": "^8.1",
"saloonphp/saloon": "^2.7"
"php": "^8.2",
"saloonphp/saloon": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
811 changes: 409 additions & 402 deletions composer.lock

Large diffs are not rendered by default.

67 changes: 34 additions & 33 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Probots\Pinecone;

use Probots\Pinecone\Contracts\ClientContract;
use Probots\Pinecone\Requests\Index\Vectors\Fetch;
use Probots\Pinecone\Resources\CollectionResource;
use Probots\Pinecone\Resources\IndexResource;
use Probots\Pinecone\Requests\Data\FetchVectors;
use Probots\Pinecone\Requests\Exceptions\MissingHostException;
use Probots\Pinecone\Resources\ControlResource;
use Probots\Pinecone\Resources\DataResource;
use Psr\Http\Message\RequestInterface;
use Saloon\Http\Connector;
use Saloon\Http\PendingRequest;
use Saloon\Traits\Plugins\AcceptsJson;
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;

Expand All @@ -17,52 +19,51 @@ class Client extends Connector implements ClientContract

protected ?string $response = Response::class;

/**
* @param string $apiKey
* @param string $environment
*/
protected string $baseUrl = 'https://api.pinecone.io';

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

// (Temporary) Workaround for https://github.com/probots-io/pinecone-php/issues/3
public function handlePsrRequest(RequestInterface $request, PendingRequest $pendingRequest): RequestInterface
{
// (Temporary) Workaround for https://github.com/probots-io/pinecone-php/issues/3
$this->sender()->addMiddleware(function (callable $handler) {
return function (RequestInterface $request, array $options) use ($handler) {
return $handler(Fetch::queryIdsWorkaround($request), $options);
};
});
return FetchVectors::queryIdsWorkaround($request);
}

/**
* @return string
*/
public function resolveBaseUrl(): string
{
return 'https://controller.' . $this->environment . '.pinecone.io';
return $this->baseUrl;
}

/**
* @param string|null $name
* @return IndexResource
*/
public function index(?string $name = null): IndexResource
public function control(): ControlResource
{
return new IndexResource($this, $name);
return new ControlResource($this);
}

/**
* @param string|null $name
* @return CollectionResource
* @throws MissingHostException
*/
public function collections(?string $name = null): CollectionResource
public function data(): DataResource
{
return new CollectionResource($this, $name);
$this->baseUrl = $this->indexHost;

if (!$this->indexHost) {
throw new MissingHostException('Index host is missing');
}

return new DataResource($this);
}

/**
* @return array
*/
public function setIndexHost(string $indexHost): self
{
$this->indexHost = $indexHost;

return $this;
}


protected function defaultHeaders(): array
{
return [
Expand Down
12 changes: 6 additions & 6 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ final class Factory
private ?string $apiKey = null;

/**
* The environment for the requests.
* The host for the Data requests.
*/
private ?string $environment = null;
private ?string $host = null;


/**
Expand All @@ -26,11 +26,11 @@ public function withApiKey(string $apiKey): self
}

/**
* Sets environment for the requests.
* Sets the index host for Data Operations
*/
public function withEnvironment(?string $environment): self
public function withHost(?string $host): self
{
$this->environment = $environment;
$this->host = $host;

return $this;
}
Expand All @@ -41,7 +41,7 @@ public function withEnvironment(?string $environment): self
*/
public function make(): Client
{
return new Client($this->apiKey, $this->environment);
return new Client($this->apiKey, $this->host);
}

}
4 changes: 2 additions & 2 deletions src/Pinecone.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ final class Pinecone
/**
* Creates a new Open AI Client with the given API token.
*/
public static function client(string $apiKey, string $environment = null): Client
public static function client(string $apiKey, string $indexHost = null): Client
{
return self::factory()
->withApiKey($apiKey)
->withEnvironment($environment)
->withHost($indexHost)
->make();
}

Expand Down
73 changes: 0 additions & 73 deletions src/Requests/Collections/Create.php

This file was deleted.

53 changes: 0 additions & 53 deletions src/Requests/Collections/Delete.php

This file was deleted.

56 changes: 0 additions & 56 deletions src/Requests/Collections/Describe.php

This file was deleted.

Loading

0 comments on commit 67bf3e1

Please sign in to comment.