定制 probots-io/pinecone-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

probots-io/pinecone-php

Composer 安装命令:

composer require probots-io/pinecone-php

包简介

Unofficial PHP Client for Pinecone Vector Database (pinecone.io)

README 文档

README

A beautiful, extendable PHP Package to communicate with your pinecone.io indices, collections and vectors, powered by Saloon.

Info From Version 1.x onwards we are using the latest Pinecone API which support serverless. If you need the legacy API please use a version before 1.0.0!

probots.io

Introduction

This API provides a feature rich, elegant baseline for working with the pinecone.io API. Developers can install and leverage this API to help them integrate pinecone.io easily and beautifully.

Installation

composer require probots-io/pinecone-php

Features

Currently supports all of the available endpoints in the pinecone.io API based on the official documentation

Authentication

Authentication via Api Key is the only available authentication methods currently supported. First, you will need to create an Api Key in your pinecone.io instance.

use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';

// Initialize Pinecone
$pinecone = new Pinecone($apiKey);

// Now you are ready to make requests, all requests will be authenticated automatically.

Quick Start

There are two ways to initialize the SDK. You can either provide an index during initialization or you can provide it later on.

use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';
$pinecone = new Pinecone($apiKey);

// all control methods are available now, create an index or similar
// e.g. $pinecone->control()->index()

// later on you can provide the index
$pinecone->setIndexHost('INDEX_HOST_FROM_PINECONE');

// data methods are available now

// e.g. $pinecone->data()->vectors()

or

use \Probots\Pinecone\Client as Pinecone;

$apiKey = 'YOUR_PINECONE_API_KEY';
$indexHost = 'INDEX_HOST_FROM_PINECONE';

$pinecone = new Pinecone($apiKey, $indexHost);

// all control AND data methods are available now

Info The index host should include https://, which you may need to prepend to the value returned from Pinecone.

Info The index host should include https://, which you may need to prepend to the value returned from Pinecone.

Responses

All responses are returned as a Response object. Please check the Saloon documentation to see all available methods.

Control Pane

Index Operations

Work(s) with your indices.

Create Index (POD)

Pinecone Docs

$response = $pinecone->control()->index('my-index')->createPod(
    dimension: 1536,
    metric: 'cosine',
    podType: 'p1.x1',
    replicas: 1
    // ... more options    
);

if($response->successful()) {
    // 
}

Create Index (Serverless)

Pinecone Docs

$response = $pinecone->control()->index('my-index')->createServerless(
    dimension: 1536,
    metric: 'cosine',
    cloud: 'aws',
    region: 'us-west-2'
    // ... more options    
);

if($response->successful()) {
    // 
}

Describe Index

Pinecone Docs

$response = $pinecone->control()->index('my-index')->describe();

if($response->successful()) {
    // 
}

List Indices

Pinecone Docs

$response = $pinecone->control()->index()->list();

if($response->successful()) {
    // 
}

Configure Index

Pinecone Docs

$response = $pinecone->control()->index('my-index')->configure(
    pod_type: 'p1.x1',
    replicas: 1
);

if($response->successful()) {
    // 
}

Delete Index

Pinecone Docs

$response = $pinecone->control()->index('my-index')->delete();

if($response->successful()) {
    // 
}

Collection Operations

Work(s) with your collections too.

Create Collection

Pinecone Docs

$response = $pinecone->control()->collection('my-collection')->create(
    source: 'my-index'
);

if($response->successful()) {
    // 
}

Describe Collection

Pinecone Docs

$response = $pinecone->control()->collection('my-collection')->describe();

if($response->successful()) {
    // 
}

List Collections

Pinecone Docs

$response = $pinecone->control()->collection()->list();

if($response->successful()) {
    // 
}

Delete Collections

Pinecone Docs

$response = $pinecone->control()->collection('my-collection')->delete();

if($response->successful()) {
    // 
}

Data Pane

Info These operations need the index to be set. You can set the index during initialization or later on. See description at the beginning.

Vector Operations

Vectors are the basic unit of data in Pinecone. Use them.

Get Index Stats

Pinecone Docs

$response = $pinecone->data()->vectors()->stats();

if($response->successful()) {
    // 
}

Update Vector

Pinecone Docs

$response = $pinecone->data()->vectors()->update(
    id: 'vector_1',
    values: array_fill(0, 128, 0.14),
    setMetadata: [
        'meta1' => 'value1',
    ]
);

if($response->successful()) {
    // 
}

Upsert Vectors

Pinecone Docs

$response = $pinecone->data()->vectors()->upsert(vectors: [
    'id' => 'vector_1',
    'values' => array_fill(0, 128, 0.14),
    'metadata' => [
        'meta1' => 'value1',
    ]
]);

if($response->successful()) {
    // 
}

Query Vectors

Pinecone Docs

$response = $pinecone->data()->vectors()->query(
    vector: array_fill(0, 128, 0.12),
    topK: 1,
);

if($response->successful()) {
    // 
}

Delete Vectors

Pinecone Docs

$response = $pinecone->data()->vectors()->delete(
    deleteAll: true
);

if($response->successful()) {
    // 
}

Fetch Vectors

Pinecone Docs

$response = $pinecone->data()->vectors()->fetch([
    'vector_1', 'vector_2'
]);

if($response->successful()) {
    // 
}

Testing

Testing is done via PestPHP. You can run the tests by running ./vendor/bin/pest in the root of the project. Copy .env.example to .env and update accordingly.

Credits

License

The MIT License (MIT). Please see License File for more information.

TODO - Submit PR if you want to contribute:

  • validate parameters based on API docs - needs more checking
  • Implement Custom Exceptions
  • Add failure tests
  • Add some examples
  • Finish docs

probots-io/pinecone-php 适用场景与选型建议

probots-io/pinecone-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 456.25k 次下载、GitHub Stars 达 75, 最近一次更新时间为 2023 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「client」 「sdk」 「vector」 「pinecone」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 probots-io/pinecone-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 probots-io/pinecone-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 probots-io/pinecone-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 456.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 75
  • 点击次数: 24
  • 依赖项目数: 6
  • 推荐数: 3

GitHub 信息

  • Stars: 75
  • Watchers: 3
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-14