PHPackages                             lemukarram/vector-search - 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. [API Development](/categories/api)
4. /
5. lemukarram/vector-search

ActiveLibrary[API Development](/categories/api)

lemukarram/vector-search
========================

A powerful, driver-based RAG (Retrieval-Augmented Generation) package for Laravel. Automatically sync Eloquent models to a vector database and get AI-powered answers.

1.0.4(3mo ago)25MITPHPPHP ^8.1|^8.2

Since Nov 16Pushed 3mo agoCompare

[ Source](https://github.com/lemukarram/vector-search)[ Packagist](https://packagist.org/packages/lemukarram/vector-search)[ RSS](/packages/lemukarram-vector-search/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (5)Used By (0)

Laravel Vector Search (RAG)
===========================

[](#laravel-vector-search-rag)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Author](https://camo.githubusercontent.com/99c6d429dadd303d3cd4cae9cd9fbaa8ecf301cf94b9d91a7a1308b1b33fb0de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d54656368253230776974682532306d756b2d7265642e737667)](https://github.com/lemukarram)

A powerful, driver-based RAG (Retrieval-Augmented Generation) package for Laravel. Give your Eloquent models a "long-term memory" and build powerful, context-aware AI chatbots in minutes.

Developed by **[Mukarram Hussain](https://github.com/lemukarram)** of **Tech with muk**.

---

The Concept
-----------

[](#the-concept)

This package makes Retrieval-Augmented Generation (RAG) dead simple.

1. **Sync:** You add a simple `VectorSearchable` trait to your `Post`, `Product`, or `User` models.
2. **Magic:** The package automatically syncs your model data with a vector database (like Upstash, Chroma, or Pinecone) every time a model is `saved` or `deleted`.
3. **Search:** Use `VectorSearch::similar()` to find Eloquent models that are semantically similar to a user's query.
4. **Chat:** Use `VectorSearch::chat()` to get a direct answer from an AI (like Gemini, OpenAI, or DeepSeek) that uses your model data as its *only* context.

Features
--------

[](#features)

- 🧠 **Eloquent Auto-Sync:** Just add a Trait to your models.
- 🚀 **Driver-Based Architecture:**
    - **Vector Stores:** Upstash, Chroma, and Pinecone (fully extensible).
    - **AI Models:** OpenAI, Gemini, and DeepSeek (fully extensible).
- 📈 **RAG Out-of-the-Box:** A simple `VectorSearch::chat()` method provides full RAG.
- ✨ **Clean Facade:** A powerful, simple API.

⚠️ Important: Vector Dimensions
-------------------------------

[](#️-important-vector-dimensions)

Before you start, you must understand **Dimensions**. Different AI models output vectors of different sizes. Your Vector Database Index **must** match the dimension size of your chosen AI Model.

AI ProviderModel NameDimension Size**OpenAI**`text-embedding-3-small`**1536****Gemini**`gemini-embedding-001`**768****DeepSeek**`deepseek-embedder`**1024** (Check docs)**Crucial:** If you create an Upstash index with 1536 dimensions for OpenAI, and then switch your `.env` to use Gemini (768), **it will fail**. You must create a separate index for each model type.

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

[](#installation)

1. **Install via Composer**

    ```
    composer require lemukarram/vector-search
    ```

    *(Note: If installing from a local path during development, add the repository to your composer.json first).*
2. **Publish the Config File**

    ```
    php artisan vendor:publish --tag="vector-search-config"
    ```
3. **Add Environment Variables**Add your chosen driver keys to your `.env` file.

    **Option A: Using OpenAI (1536 Dimensions)**

    ```
    VECTOR_STORE=upstash
    UPSTASH_VECTOR_URL=[https://your-openai-index.upstash.io](https://your-openai-index.upstash.io)
    UPSTASH_VECTOR_TOKEN=your_token

    VECTOR_EMBEDDING_MODEL=openai
    VECTOR_CHAT_MODEL=openai
    OPENAI_API_KEY=sk-...
    ```

    **Option B: Using Google Gemini (768 Dimensions)**

    ```
    VECTOR_STORE=upstash
    # Make sure this Upstash Index was created with 768 dimensions!
    UPSTASH_VECTOR_URL=[https://your-gemini-index.upstash.io](https://your-gemini-index.upstash.io)
    UPSTASH_VECTOR_TOKEN=your_token

    VECTOR_EMBEDDING_MODEL=gemini
    VECTOR_CHAT_MODEL=gemini
    GEMINI_API_KEY=AIza...
    ```

How to Use
----------

[](#how-to-use)

### Step 1: "Teach" Your Models

[](#step-1-teach-your-models)

Add the `VectorSearchable` trait to any Eloquent model and define the `getVectorColumns()` method.

```
