Download the PHP package timm49/similar-content-laravel without Composer

On this page you can find all versions of the php package timm49/similar-content-laravel. 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 similar-content-laravel

Similar Content Laravel

Add content recommendations (e.g. “Related articles” or “You might also like”) and semantic search to your Laravel applications in a breeze with the power of AI.

What this package does

This package simplifies adding content recommendations and semantic search to your Laravel application. You don't need any prior knowledge of AI, vectors, or embeddings—this package handles the complexity for you.

Generate embeddings of your databases content

Use the built-in Artisan command to generate embeddings for all existing records for all defined models. Once that's done you'll probably want to add a couple of lines your application code to handle it automatically when new records are created or updated. The embeddings are stored in your database. Optionally, you can enable auto_generation, which generates embeddings automatically using model events (saved).

Get similar content

Retrieve similar content for a specific record and use it for a recommendation section, semantic searching or any other embedding related feature.

See it in action

A simple example application using this package can be found here: timm49/example-app-similar-content

Installation

Install via Composer:

Run the installation command:

Then run migrations:

Configuration

OpenAI API Key

config/similar_content.php

Add the SIMILAR_CONTENT_OPENAI_API_KEY to your .env file

Auto Generate

If you want the package to automatically create/update embeddings using model events, you can do so by setting 'auto_generate' in the config to true.

Use carefully as this will call the API on every "saved" hook!

Mark the models you want to retrieve similar content for

Add the #[HasEmbeddings] attribute to the models you want to store embeddings for. Embeddings are necessary to find and compare similar items.

Generating embeddings for existing records

Run the artisan command to generate and store embeddings for the marked models:

To generate embeddings for all records, including existing items, use the --force flag:

To generate and store embeddings for a record from within your application code, use this:

Retrieving similar content

Retrieving similar items for a record is as simple as:

This will return an array of SimilarContentResult objects, each representing a similar record and its similarity score.

Semantic search

You can also use this package to find records similar to a search query string, enabling semantic search in your application. Unlike traditional search, which matches exact words or phrases, semantic search understands the meaning behind the query — allowing users to find relevant results even if the wording doesn't exactly match.

Behind the scenes, the package sends the query (e.g. 'Donald Trump') to the OpenAI API to generate an embedding and compares it to your stored model embeddings.

Retrieving content similar to a query is as simple as:

This will search for similar content for ALL target types (models)

This will return an array of SearchResult objects, each representing a similar record and its similarity score.

To search only in "articles" and "pages", you can pass an array of models:

Customizing Embedding Data

The package ships with a HasSimilarContent trait which you can use in your models. You can customize the default behavior by overriding the getEmbeddingData() method:

This gives you full control over:

📘 It's very important to include the right data for the right embedding purposes. I've added some links at the bottom of this README which should be helpful to get familiar with vector databases, embedding, etc.

How similarity is calculated

This package uses cosine similarity to compare content embeddings. After generating an embedding (a high-dimensional vector) for each model, it calculates the similarity between two records by measuring the cosine of the angle between their vectors.

All similarity comparisons are done in PHP by loading and comparing vectors in memory.

⚠️ Database & Performance Notes

This package does not require a dedicated vector database but now also supports pgvector for PostgreSQL users, in addition to working with standard SQL databases like MySQL and SQLite.

✅ Benefits

⚠️ Considerations

There are two different ways similarity is calculated, depending on your database setup:

PostgreSQL with pgvector support:

Standard SQL databases (MySQL, SQLite, non-pgvector PostgreSQL, etc.):

ℹ️ If you're running PostgreSQL and expect to work with a high volume of embeddings, enabling pgvector is highly recommended for better performance and scalability.

Useful resources

Here's some good resources to get you started:

Alternatives

Similar packages with a slightly different approach:

Contributing

Contributions are welcome! Please submit issues and pull requests.

License

MIT © Timm49


All versions of similar-content-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
guzzlehttp/guzzle Version ^7.9
illuminate/http Version *
illuminate/support Version *
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 timm49/similar-content-laravel contains the following files

Loading the files please wait ...