adrianmtanase / laravel-vector-store
Laravel 框架的向量存储抽象层。
1.0.1
2024-07-07 05:16 UTC
Requires
- php: ^8.1
- probots-io/pinecone-php: ^1.0.1
- spatie/laravel-package-tools: ^1.14.0
- timkley/weaviate-php: 0.6.2
Requires (Dev)
- laravel/pint: dev-main
- orchestra/testbench: ^8.18
- phpstan/phpstan: ^1.4.7
- phpunit/phpunit: ^10.5.3
- vlucas/phpdotenv: ^5.6@dev
README
本包提供了多个向量数据库的实现(例如 Pinecone.io)。
支持我们
如果这对你有帮助,请考虑在 Patreon 或在 Github 上支持我的开发。
安装
需要 PHP ^8.1
composer require adrianmtanase/laravel-vector-store
当前支持
计划实现
- MySql - 一旦准备好
❗ 如果您来自版本 0.0.25 ❗
- 来自版本
0.0.25
的用户需要重新发布配置,因为 Pinecone 环境变量已被pinecone_host
替换。
php artisan vendor:publish
用法
使用 VectorStore
门面,您可以轻松访问任何提供者并执行操作。
VectorStore::instance() ->namespace('general') ->upsert( PineconeUpsertRequest::build() ->id('1') ->values([ -0.002739503, -0.01970483, -0.011307885, -0.011125952, -0.023119587, 0.0016207852, -0.003981551, -0.029249357, 0.00983842, -0.023721369 ]) ->metadata([ 'text' => 'Vector store is lit!' ]) );
默认提供者是 Pinecone.io
,这可以通过门面 VectorStore::provider(VectorStoreProviderType::PINECONE)
或直接在 vector-store
config 中轻松切换。
Weaviate
由于 Weaviate 通过 GraphQL 运行,查询语言很复杂。在 WeaviateQueryRequest
中有几个有用的方法可以帮助您更有效地查询数据。例如
VectorStore::provider(VectorStoreProviderType::WEAVIATE) ->instance() ->namespace('general') ->query( WeaviateQueryRequest::build() ->vector([ -0.002739503, -0.01970483, -0.011307885, -0.011125952, -0.023119587, 0.0016207852, -0.003981551, -0.029249357, 0.00983842, -0.023721369 ]) ->properties(['text']) ->withId() ->withParameters(WeaviateQueryParameters::build()->group('type: closest, force: 1')) );
由于系统复杂,包还支持 rawQuery
形式,甚至可以访问底层客户端。
Weaviate 原始查询
VectorStore::provider(VectorStoreProviderType::WEAVIATE) ->instance() ->namespace('general') ->rawQuery(' { Get { General(nearVector: { vector: [ -0.002739503, -0.01970483, -0.011307885, -0.011125952, -0.023119587, 0.0016207852, -0.003981551, -0.029249357, 0.00983842, -0.023721369 ] }) { text } } } ');
底层 Weaviate 客户端
VectorStore::provider(VectorStoreProviderType::WEAVIATE) ->instance() ->client() ->batchDelete('general')