islambaraka90/pinecone-php-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

islambaraka90/pinecone-php-client

Composer 安装命令:

composer require islambaraka90/pinecone-php-client

包简介

A PHP client for connecting to Pinecone DB

README 文档

README

This is a PHP client implementation for handling all of the Pinecone endpoints. This library was created because there was no existing PHP client for Pinecone vector database.

Pinecone Vector Database

Pinecone is a vector database designed for high-performance similarity search and other similarity-related tasks. It provides a simple API for inserting and querying high-dimensional vectors, making it easy to build intelligent search applications that can handle large amounts of data.

Pinecone is used by OpenAI applications as part of its long-term memory architecture. By storing high-dimensional vectors in Pinecone, OpenAI applications can retrieve them quickly and efficiently when needed, allowing it to build complex models that can learn from large amounts of data and make more accurate predictions.

Pinecone's vector database is highly scalable and can handle millions or even billions of vectors with ease. It's designed to work with a variety of machine learning frameworks and libraries, making it easy to integrate into your existing workflow.

One of the key benefits of using Pinecone is its ability to perform fast, accurate similarity searches. This makes it ideal for applications such as image search, product recommendations, and personalized content delivery. By using Pinecone, you can build intelligent search applications that can handle large amounts of data and provide accurate results in real-time.

Overall, Pinecone is a powerful tool for anyone who needs to work with high-dimensional vectors and wants to build intelligent search applications that can handle large amounts of data. Whether you're building a recommendation engine, an image search application, or a personalized content delivery system, Pinecone can help you achieve your goals quickly and easily.

Important Note:

This library isn't restricted to only OpenAI embedding and can be used with any other embedding.

Make sure to check the dimensions of your embedding before using it with this library.

Installation

To install the Pinecone PHP Client, you can use Composer. Run the following command:

composer require islambaraka90/pinecone-php-client

Usage

Initialization

To use the Pinecone PHP Client, you need to first initialize it with your API key and Pinecone endpoint. You can do this by creating a new instance of the Pinecone client:

use IslamBaraka90\PineconeClient;

$this->api_key =  $_ENV['PINCONE_KEY'] ?: '';
$this->environment = $_ENV['PINCONE_ENV'] ?: 'us-east1-gcp';
$this->client = new PineconePhpClient( $this->api_key ,  $this->environment );

Listing Indexes

To list all indexes available in your Pinecone instance, you can use the listIndexes method:

$response = $this->client->listIndexes();

Creating an Index

To create a new index, you can use the createIndex method:

$name = 'my-index';
$dimension = 1536;
$result = $this->client->createIndex($name, $dimension);

Deleting an Index

To delete an index, you can use the deleteIndex method:

$response = $this->client->deleteIndex('my-index');

Describing an Index

To get information about an index, you can use the describeIndex method:

$this->client->describeIndex('my-index');

Working with an Index

To work with a specific index, you can use the Index method to get an instance of the Index interface. Here are some examples of methods available on the Index interface:

Describe Index Stats

To get statistics about an index, you can use the describeIndexStats method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

Upsert Vectors

To insert or update vectors in an index, you can use the upsert method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

// Upsert 20 vectors
$vectorsFile = __DIR__ . '/vectors_objects.json';
$vectors = json_decode(file_get_contents($vectorsFile), true);
$project_id = 'project-0000'.rand(1,99);
$response = $index->upsert($project_id,$vectors['vectors']);

Query Vectors

To query vectors from an index, you can use the query method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

// Query vectors
$vectorsFile = __DIR__ . '/query.json';
$vectors = json_decode(file_get_contents($vectorsFile), true);
$response = $index->query('project-000001',$vectors, [],3);
$response = json_decode($response, true);

Fetch Vectors

To fetch vectors from an index, you can use the fetch method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

// Fetch vectors
$id = "DEeSvRP8XKZwzpWD";
$response = $index->fetch([$id], 'project-000001');
$response = json_decode($response, true);

Update Vectors

To update vectors in an index, you can use the update method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

// Update vectors
$id = "DEeSvRP8XKZwzpWD";
$response = $index->update($id, 'project-000001',null,null,['testing' => 'testing5']);
$response = json_decode($response, true);

Delete Vectors

To delete vectors from an index, you can use the delete method:

$index = $this->client->Index('my-index');
$state = $index->describeIndexStats();

// Delete vectors
$id = "DEeSvRP8XKZwzpWD";
$response = $index->delete($id, 'project-000001');

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

islambaraka90/pinecone-php-client 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 973
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 20
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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