Download the PHP package benbjurstrom/pgvector-scout without Composer

On this page you can find all versions of the php package benbjurstrom/pgvector-scout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pgvector-scout

Logo

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

Pgvector driver for Laravel Scout

Use the pgvector extension with Laravel Scout for vector similarity search.

To see a full example showing how to use this package check out benbjurstrom/pgvector-scout-demo.

πŸš€ Quick Start

1. Install the package using composer:

2. Publish the scout config and the package config:

This is the contents of the published pgvector-scout.php config file. By default it contains 3 different indexes, one for OpenAI, one for Google Gemini, and one for testing. The rest of this guide will use the OpenAI index as an example.

3. Set the scout driver to pgvector in your .env file and add your OpenAI API key:

4. Run the scout index command to create a migration file for your embeddings:

5. Update the model you wish to make searchable:

Add the HasEmbeddings and Searchable traits to your model. Additionally add a searchableAs() method that returns the name of your index. Finally implement toSearchableArray() with the content from the model you want converted into an embedding.

πŸ” Usage

Create embeddings for your models:

Laravel Scout uses eloquent model observers to automatically keep your search index in sync anytime your Searchable models change.

This package uses this functionality automatically generate embeddings for your models when they are saved or updated; or remove them when your models are deleted.

If you want to manually generate embeddings for existing models you can use the artisan command below. See the Scout documentation for more information.

Search using vector similarity:

You can use the typical Scout syntax to search your models. For example:

Note that the text of your query will be converted into a vector embedding using the model index's configured handler. It's important that the same model is used for both indexing and searching.

Search using existing vectors:

You can also pass an existing embedding vector as a search parameter. This can be useful to find related models. For example:

Evaluate search results:

All search queries will be ordered by similarity to the given input and include the embedding relationship. The value of the nearest neighbor search can be accessed as follows:

The larger the distance the less similar the result is to the input.

πŸ› Using custom handlers

By default this package uses OpenAI to generate embeddings. To do this it uses the OpenAiHandler class paired with the openai index found in the packages config file.

You can generate embeddings from other providers by adding a custom Handler. A handler is a simple class defined in the HandlerContract that takes a string, a config object, and returns a Pgvector\Laravel\Vector object.

Whatever api calls or logic is needed to turn a string into a vector should be defined in the handle method of your custom handler.

If you need to pass api keys, embedding dimensions, or any other configuration to your handler you can define them in the config/pgvector-scout.php file.

Installing pgvector when using DBngin

If you're using DBngin for local development you can install the pgvector extention by doing the following:

  1. Add PostgreSQL to your path:

  2. Then install pgvector:

πŸ‘ Credits

πŸ“ License

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


All versions of pgvector-scout with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0||^11.0
laravel/scout Version ^10.11
pgvector/pgvector Version ^0.2.0
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package benbjurstrom/pgvector-scout contains the following files

Loading the files please wait ....