chencongbao/pinecone

此包为 Pinecone API 提供了 Laravel 封装。

dev-main 2023-10-23 02:19 UTC

This package is not auto-updated.

Last update: 2024-09-24 04:49:32 UTC


README

Latest Version on Packagist tests static analysis License

此包为 Laravel 提供了对 Pinecone 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 的索引,其中包含两个 fieldsfield1field2

可用方法

以下方法通过 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 许可