adrianmejias/pinecone

此包已被废弃且不再维护。未建议替代包。

此包提供了Pinecone API的Laravel包装。

v1.0.12 2023-04-11 00:01 UTC

This package is auto-updated.

Last update: 2024-04-29 22:59:38 UTC


README

Latest Version on Packagist tests static analysis License

此包提供了LaravelPinecone API的包装。它使您能够在Laravel项目中轻松地与Pinecone API交互。

安装

您可以通过composer安装此包

composer require adrianmejias/pinecone

您也可以选择使用以下命令发布配置文件

php artisan vendor:publish --provider="AdrianMejias\Pinecone\PineconeServiceProvider" --tag="config"

这将发布一个位于您的配置目录中的pinecone.php文件,您可以按需进行自定义。

配置

在使用此包之前,您需要设置Pinecone API密钥和环境。您可以通过设置环境变量PINECONE_API_KEYPINECONE_PROJECT_IDPINECONE_ENVIRONMENT,或通过更新config/pinecone.php文件中的值来完成此操作。

您还可以选择设置环境变量PINECONE_CONTROLLER_HOST/PINECONE_INDEX_HOST或更新config/pinecone.php文件中的controller_host/index_host值以指定自定义的控制器/索引主机。

使用方法

您可以使用Pinecone外观与Pinecone API交互。以下是一个创建索引的示例

use AdrianMejias\Pinecone\Facades\Pinecone;

// Create an index
$response = Pinecone::index('my-index')->create([
    'metric' => 'cosine',
    'pods' => 1,
    'replicas' => 1,
    'pod_type' => 'p1.x1',
]);

// Query with namespace
$response = Pinecone::vector('my-index')->namespace('my-namespace')->query(10);

这将创建一个名为my-index的索引,包含两个字段field1field2

可用方法

以下方法可通过Pinecone外观使用

  • setApiKey(string $apiKey): Pinecone: 设置用于Pinecone请求的API密钥
  • setEnvironment(string $environment): Pinecone: 设置要使用的Pinecone环境
  • setProjectId(string $projectId): Pinecone: 设置要使用的Pinecone项目ID
  • setEndpoint(string $endpoint): Pinecone: 设置要使用的Pinecone控制器主机
  • getApiKey(): ?string: 获取当前正在使用的API密钥
  • getEnvironment(): ?string: 获取当前正在使用的Pinecone环境
  • getProjectId(): ?string: 获取当前正在使用的Pinecone项目ID
  • getEndpoint(): ?string: 获取当前正在使用的Pinecone控制器主机
  • vector(string $indexName): Pinecone: 向量操作
  • index(?string $indexName = null): Pinecone: 索引操作
  • collection(?string $collectionName = null): 索引集合操作

有关如何使用API的更多信息,请参阅官方Pinecone API参考

许可证

Pinecone PHP包是开源软件,受MIT许可证许可。