darcher / pinecone-php
PHP Pinecone API 客户端
dev-master
2023-04-15 22:56 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- guzzlehttp/psr7: ^2.4
- islambaraka90/pinecone-php-client: ^0.1.1
- nyholm/psr7: ^1.6
- symfony/property-access: ^6.2
Requires (Dev)
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-09-14 17:32:14 UTC
README
这个 PHP Pinecone API 客户端是一个强大且易于使用的库,允许您与 Pinecone 向量数据库进行交互。Pinecone 是一个可扩展且高性能的向量数据库,旨在存储、搜索和管理大量高维向量。
此库提供了一种方便且高效的方式,使用 PHP 与 Pinecone 进行交互。
入门指南
先决条件
要使用此包,您需要在您的机器上安装 PHP 8.1 或更高版本。您还需要 Pinecone 帐户和 API 密钥。
安装
要安装此包,您可以使用 composer
composer require darcher/pinecone-php
使用方法
索引
要开始使用,您需要创建 IndexApi 类的一个实例
use Darcher\PineconePhp\IndexApi; $apiKey = 'your-api-key'; $environment = 'us-west1-gcp'; $pinecone = IndexApi::build($apiKey, $environment);
一旦您有了 IndexApi 类的实例,您就可以使用它来对您的 Pinecone 索引执行各种操作。例如,您可以列出所有索引
$indexes = $pinecone->list();
您也可以创建一个新的索引
$name = 'my-new-index'; $dimension = 256; $response = $pinecone->create($name, $dimension);
有关可用方法和它们的参数的更多信息,请参阅 IndexApi 类中的内联文档。
使用方法:要开始使用,您需要创建 VectorApi 类的一个实例
向量
如果您不知道主机
use Darcher\PineconePhp\VectorApi; $apiKey = 'your-api-key'; $environment = 'us-west1-gcp'; $indexName = 'your-index-name'; $pinecone = VectorApi::build($apiKey, null, $indexName, $environment);
一旦您有了 VectorApi 类的实例,您就可以使用它来对您的 Pinecone 向量执行各种操作。例如,您可以通过 ID 查询向量
$id = 'your-vector-id'; $topK = 10; $response = $pinecone->queryById($id, $topK);
您也可以更新一个向量集合
use Darcher\PineconePhp\Vector; use Darcher\PineconePhp\VectorCollection; $vectors = new VectorCollection([ new Vector('vector-id-1', [1, 2, 3]), new Vector('vector-id-2', [4, 5, 6]), ]); $response = $pinecone->upsertCollection($vectors);
或者使用工厂类
use Darcher\PineconePhp\VectorCollectionFactory; $response = $pinecone->upsertCollection(VectorCollectionFactory::create([ ['vector-id-1', [1, 2, 3]], ['vector-id-2', [3, 4, 5]], ]));
您也可以使用单个向量的 upsert
use Darcher\PineconePhp\Vector; $response = $pinecone->upsertOne(new Vector('vector-id-1', [1, 2, 3]));
有关可用方法和它们的参数的更多信息,请参阅 VectorApi 类中的内联文档。
贡献
如果您想为此包做出贡献,请随时在 GitHub 仓库上打开一个 pull request 或 issue。
许可
此包受 MIT 许可证许可。