Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BitValentine's avatar

AI Powers with Laravel: Vector Databases

I'm embarking on an adventurous journey to build an AI application and I'm eager to dive into the world of Laravel and vector databases. My goal? To unlock the potential of what these technologies can offer.

I've discovered that Postgres can handle vector databases through an extension called PGvector. Given that Laravel supports Postgres, this seems like a seamless and logical pathway to integrate vectors within Laravel.

Recently, I stumbled upon Larachain. It's caught my attention, but I'm pondering if it's the best starting point for my AI ambitions. Alternatively, I'm considering the PHPopenai package. Which of these would be more suitable for a beginner in this domain?

I'm also curious to know if there are other self-hosted vector databases that are compatible with Laravel. Any recommendations?

And lastly, I'm all ears for any suggestions on resources, tools, or courses that can assist me in this exciting AI venture with Laravel.

Looking forward to your insights and tips!

1 like
2 replies
LaryAI's avatar
Level 58

Hello there!

It's great to hear about your interest in combining AI with Laravel. Let's break down your questions and provide some guidance.

PGvector with Laravel

You're correct that Postgres can handle vector databases through the PGvector extension. To integrate this with Laravel, you would need to ensure that you have the extension installed and configured in your Postgres database. Laravel's database layer, Eloquent, doesn't natively support vector types, but you can use raw queries or create a custom database type to handle this.

Here's a basic example of how you might execute a raw query with vector operations in Laravel:

use Illuminate\Support\Facades\DB;

$results = DB::select('SELECT * FROM your_table WHERE vector_column <-> ? LIMIT 10', [$yourVector]);

In the above example, <-> is a placeholder for the vector operation you want to perform, and $yourVector would be the vector you're comparing against.

Larachain vs PHPopenai

Larachain is a package that integrates blockchain technology with Laravel, which might not be directly related to your AI ambitions unless you're looking to incorporate blockchain as well.

PHPopenai, on the other hand, is a package that provides a PHP client for the OpenAI API. If you're looking to leverage AI models like GPT-3, this could be a more suitable starting point for you as a beginner in AI.

Self-hosted Vector Databases

As for self-hosted vector databases compatible with Laravel, you might want to look into:

  • Milvus: An open-source vector database designed for AI applications.
  • Pinecone: A scalable vector database service that's easy to use.

Both of these can be integrated with Laravel through their respective APIs, but you'll need to write custom integration code to communicate with these services.

Resources, Tools, or Courses

For resources, you might want to start with:

  • Laravel's official documentation to get a solid understanding of the framework.
  • Tutorials on integrating external services with Laravel, which can give you insights into how to connect to vector databases or AI APIs.
  • Online courses on machine learning and AI to get a foundational understanding of the concepts you'll be working with.

Remember, integrating AI into your Laravel applications often involves working with external services and APIs, so having a good grasp of HTTP client usage in Laravel, such as using Guzzle or Laravel's HTTP client, will be beneficial.

Good luck on your AI journey with Laravel!

benbjurstrom's avatar

Kind of a late reply, but I just published a Pgvector driver for Laravel Scout that makes it really easy to search and maintain your pgvector embeddings.

Scout works really well with pgvector since its model observers will automatically keep you vector embeddings up to date.

Would love to get some feedback on the design decisions, especially around customizability.

https://github.com/benbjurstrom/pgvector-scout

1 like

Please or to participate in this conversation.