Neuron AI
GitHubForumNewsletter
  • Getting Started
    • Introduction
  • Key Concepts
  • Installation
  • Agent
  • Tools & Function Calls
  • Streaming
  • RAG
  • Attachments (Documents & Images)
  • Advanced
    • Structured Output
    • Logging & Observability
    • MCP Connector
    • Error Handling
  • Post Processor
  • Components
    • AI provider
    • Chat History & Memory
    • Embeddings Provider
    • Vector Store
    • Data loader
  • Examples
    • YouTube Agent
Powered by GitBook
On this page
  • Memory Vector Store
  • File Vector Store
  • Pinecone
  • Elasticsearch
  • Typesense
  • Qdrant
  • ChromaDB
  • Meilisearch
  • Implement a new Vector Store
  1. Components

Vector Store

We currently offer first-party support for the following vector store:

Memory Vector Store

This is an implementation of a volatile vector store that keeps your embeddings into the machine memory for the current session. It's useful when you don't need to store the generated embeddings for long term use, but just during current interaction sessions (or for local use).

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\MemoryVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new MemoryVectorStore();
    }
}

File Vector Store

File storage could be useful for low volume use case or local and staging environments. Embedded documents will be stored in the file system and processed during similarity search.

FileVectorStore uses PHP generators to read the embedded documents from the file systems. It will never keep more than topK items in memory while iterating very fast. You can store thousands of documents in your local filesystem only taking care on the maximum time you can accept to perform the similarity search.

You can also use this component to release agents with some knowledge already incorporated in a file.

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\FileVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new FileVectorStore(
            directory: storage_path(),
            topK: 4
        );
    }
}

Pinecone

Pinecone makes it easy to provide long-term memory for high-performance AI applications. It’s a managed, cloud-native vector database with a simple API and no infrastructure hassles. Pinecone serves fresh, filtered query results with low latency at the scale of billions of vectors.

Here is how to use Pinecone in your agent:

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\PineconeVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new PineconeVectorStore(
            key: 'PINECONE_API_KEY',
            indexUrl: 'PINECONE_INDEX_URL'
        );
    }
}

Or you can set the vector store at runtime:

namespace App\Neuron;

use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\Observability\AgentMonitoring;
use NeuronAI\RAG\VectorStore\PineconeVectorStore;

// The Inspector instance in your application - https://inspector.dev/
$inspector = new \Inspector\Inspector(
    new \Inspector\Configuration('INSPECTOR_INGESTION_KEY')
);

$agent = MyChatBot::make()
    ->observe(new AgentMonitoring($inspector))
    ->setVectorStore(
        new PineconeVectorStore(
            key: 'PINECONE_API_KEY',
            indexUrl: 'PINECONE_INDEX_URL'
        );
    )->chat(
        new UserMessage('Hello!')
    );

Elasticsearch

Elasticsearch's open source vector database offers an efficient way to create, store, and search vector embeddings. To use Elasticseach as a vector store in your agents implementation you have to import the official client:

composer require elasticsearch/elasticsearch

Here is how to create a RAG that uses Elasticsearch:

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\ElasticsearchVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    public function __construct(protected Client $elasticClient) {}

    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new ElasticsearchVectorStore(
            client: $this->elasticClient,
            index: 'neuron-ai'
        );
    }
}

Passing the elasticsearch client instance to the agent:

// The Inspector instance in your application - https://inspector.dev/
$inspector = new \Inspector\Inspector(
    new \Inspector\Configuration('INSPECTOR_INGESTION_KEY')
);

$elasticClient = ClientBuilder::create()
   ->setHosts(['<elasticsearch-endpoint>'])
   ->setApiKey('<api-key>')
   ->build();
   
$response = MyChatBot::make($elasticClient)
    ->observe(new AgentMonitoring($inspector))
    ->chat(new UserMessage('Hello!'));

echo $response->getContent();

Typesense

composer require typesense/typesense-php

Once you have the official client installed in your app you can return an instance of the TypesenseVectorStore in your RAG agent:

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\TypesenseVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    public function __construct(protected Client $typesenseClient) {}

    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new TypesenseVectorStore(
            client: $this->typesenseClient,
            collection: 'neuron-ai',
            vectorDimension: 1024
        );
    }
}

Passing the instance of the typesense client to the Agent:

// The Inspector instance in your application - https://inspector.dev/
$inspector = new \Inspector\Inspector(
    new \Inspector\Configuration('INSPECTOR_INGESTION_KEY')
);

$typesenseClient = new Client([
    'api_key' => 'TYPESENSE_API_KEY',
    'nodes' => [
        [
            'host' => 'TYPESENSE_NODE_HOST',
            'port' => 'TYPESENSE_NODE_PORT',
            'protocol' => 'TYPESENSE_NODE_PROTOCOL'
        ],
    ]
]);

$response = MyChatBot::make($typesenseClient)
    ->observe(new AgentMonitoring($inspector))
    ->chat(new UserMessage('Hello!'));

echo $response->getContent();

Qdrant

Once you have the collection URL you can attach the QdrantVectorStore instance to your agent.

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\QdrantVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new QdrantVectorStore(
            collectionUrl: 'http://localhost:6333/collections/neuron-ai/',
            key: 'QDRANT_API_KEY'
        );
    }
}

ChromaDB

Once you have the collection created on your Chroma instance you can attach the ChromaVectorStore instance to the agent:

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\ChromaVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new ChromaVectorStore(
            collection: 'neuron-ai',
            //host: 'http://localhost:8000', <-- This is by default
            topK: 5
        );
    }
}

Meilisearch

Once you have configured your index you can add the component to your RAG:

namespace App\Neuron;

use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\MeilisearchVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    ...
    
    protected function vectorStore(): VectorStoreInterface
    {
        return new MeilisearchVectorStore(
            indexUid: 'MEILISEARCH_INDEXUID',
            host: 'http://localhost:8000', // Or use the cloud URL
            key: 'MEILISEARCH_API_KEY',
            embedder: 'default',
            topK: 5
        );
    }
}

Implement a new Vector Store

If you want to create a new provider you have to implement the VectorStoreInterface interface:

namespace NeuronAI\RAG\VectorStore;

use NeuronAI\RAG\Document;

interface VectorStoreInterface
{
    public function addDocument(Document $document): void;

    /**
     * @param  array<Document>  $documents
     */
    public function addDocuments(array $documents): void;

    /**
     * Return docs most similar to the embedding.
     *
     * @param  float[]  $embedding
     * @return array<Document>
     */
    public function similaritySearch(array $embedding, int $k = 4): iterable;
}

There are two different methods for adding single document or a collection because many database provides different APIs for these use cases. If the database you want to communicate doesn't handle these requests differently you can implement addDocument() as a placeholder.

This is the basic template for a new AI provider implementation.

namespace App\Neuron\VectorStores;

use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use NeuronAI\RAG\Document;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyVectorStore implements VectorStoreInterface
{
    protected Client $client;

    public function __construct(
        string $key,
        protected string $index,
        protected int $topK = 5
    ) {
        $this->client = new Client([
            'base_uri' => 'https://api.vector-store.com',
            'headers' => [
                'Accept' => 'application/json',
                'Content-Type' => 'application/json',
                'Authorization' => "Bearer {$key}",
            ]
        ]);
    }

    public function addDocument(Document $document): void
    {
        $this->addDocuments([$document]);
    }

    public function addDocuments(array $documents): void
    {
        $this->client->post("indexes/{$this->index}", [
            RequestOptions::JSON => \array_map(function (Document $document) {
                return [
                    'vector' => $document->embedding,
                ];
            }, $documents)
        ]);
    }

    public function similaritySearch(array $embedding): iterable
    {
        // perform similarity search and return an array of Document objects
    }
}

After creating your own implementation you can use it in the agent:

namespace App\Neuron;

use App\Neuron\VectorStores\MyVectorStore;
use NeuronAI\Agent;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyAgent extends Agent
{
    protected function vectorStore(): VectorStoreInterface
    {
        return new MyVectorStore(
            key: 'VECTORSTORE_API_KEY',
            index: 'neuron-ai',
        );
    }
}
PreviousEmbeddings ProviderNextData loader

Last updated 3 days ago

Take a look at the Pinecone official documentation to better understand the configuration parameters:

is an open source alternative to the options above. To use Typesense in your agents you need to install its official client:

is an open source vector database with strong similarity search capabilities. To use Qdrant in your agents you have to provide a collectionUrl. This means you will first need to create a collection on Qdrant with its attributes like: name, similarity search algorithm, vector dimension, etc.

is an open source database designed to be an AI application data source. To use ChromaDB in your agents you have to provide the name of an internal collection where you want to store the embeddings.

is a hybrid search engine, but the Neuron implementation uses it exclusively as a vector store for embeddings and similarity search.

Before attaching the MeilisearchVectorStore to your RAG agent you must create an index using the Meilisearch Admin Console and associate a custom embedder to the index configuring as Dimension the same value of the vector dimension generated by your .

We strongly recommend you to submit new vector store implementations via PR on the official repository or using other support channels. The new implementation can receives an important boost in its advancement by the community.

https://docs.pinecone.io/reference/api/authentication#add-headers-to-an-http-request
Typesense
Qdrant
Chroma
Meilisearch
Embeddings Provider
Inspector.dev