PHPackages                             dejwcake/ada-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dejwcake/ada-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dejwcake/ada-laravel
====================

This package allows you to enhance your Laravel applications by seamlessly integrating word embeddings.

0.1.1(11mo ago)044MITPHPPHP ^8.2

Since May 22Pushed 11mo agoCompare

[ Source](https://github.com/dejwCake/ada-laravel)[ Packagist](https://packagist.org/packages/dejwcake/ada-laravel)[ Docs](https://github.com/5am-code/ada-laravel)[ RSS](/packages/dejwcake-ada-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

ada-laravel
===========

[](#ada-laravel)

[![Packagist Version](https://camo.githubusercontent.com/34c983b9664d4f91a1dfa3b25dee7ee80e2fb6316cfb9a8f0f68f2d178d37a3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66697665616d2d636f64652f6164612d6c61726176656c3f696e636c7564655f70726572656c6561736573267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/34c983b9664d4f91a1dfa3b25dee7ee80e2fb6316cfb9a8f0f68f2d178d37a3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66697665616d2d636f64652f6164612d6c61726176656c3f696e636c7564655f70726572656c6561736573267374796c653d666f722d7468652d6261646765)

The package `ada-laravel` allows you to enhance your Laravel applications by seamlessly integrating text embeddings and querying capabilities for your models. Utilizing OpenAI by default, it enables your models to generate and query embeddings using nearest neighbors techniques. This package requires a PostgreSQL database with the vector extension to store and manage these embeddings efficiently as well as at least Laravel 11.

Originally created as a demo for the talk [»Have you met ada? - Word Embeddings with Laravel and OpenAI«](https://dianaweb.dev/talk/ada) by Diana Scharf, this package is functional yet designed to encourage further development and contributions.

Warning

Please note that this package is still in development and may not be suitable for production use.

Installation
------------

[](#installation)

```
composer require fiveam-code/ada-laravel
```

Ensure that your database is configured to use PostgreSQL with the vector extension. The package will enable the extension via a migration if it is not already enabled.

You can publish the migrations (optional) and run them:

```
php artisan vendor:publish --provider="Ada\AdaServiceProvider" --tag="ada-migrations"
php artisan migrate
```

This will enable the `vector` extension in your database and create a table `embeddings` to store the embeddings.

Configuration
-------------

[](#configuration)

Set the OpenAI API key in your `.env` file:

```
ADA_CLIENT_TOKEN=your_openai_api_key
```

Please note that you need an OpenAI key for API access, not just ChatGPT access.

Optionally, you can publish the configuration file if you want to make changes to the default settings:

```
php artisan vendor:publish --provider="Ada\AdaServiceProvider" --tag="ada-config"
```

The default configuration is as follows:

```
return [
    'client_token' => env('ADA_CLIENT_TOKEN'),
    'index_class' => \Ada\Index\DefaultIndex::class,
    'default_prompt_view' => 'ada::default-prompt'
];
```

If you want to implement your own engine to handle embeddings, you can create a new class that implements the `Index`interface with the appropriate engine and set it in the configuration.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

First, add the `HasEmbeddings` trait to your Eloquent model:

```
