We currently offer first-party support for the following vector store:
Memory 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).
use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\MemoryVectoreStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
class MyChatBot extends RAG
{
...
public function vectorStore(): VectorStoreInterface
{
return new MemoryVectoreStore();
}
}
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 application:
use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\PineconeVectoreStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
class MyChatBot extends RAG
{
...
public function vectorStore(): VectorStoreInterface
{
return new PineconeVectoreStore(
key: 'PINECONE_API_KEY',
indexUrl: 'PINECONE_INDEX_URL'
);
}
}
Or you can set the vector store at runtime:
$agent = MyChatBot::make()->setVectorStore(
new PineconeVectoreStore(
key: 'PINECONE_API_KEY',
indexUrl: 'PINECONE_INDEX_URL'
);
)->run(
new UserMessage('Hello!')
);
Elasticsearch's open source vector database offers an efficient way to create, store, and search vector embeddings.
To use Elasticseach as a vector store you have to import the official client:
composer require elasticsearch/elasticsearch
Here is how to create a RAG that uses Elasticsearch:
use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\ElasticsearchVectoreStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
class MyChatBot extends RAG
{
public function __construct(protected Client $elasticClient) {}
...
public function vectorStore(): VectorStoreInterface
{
return new ElasticsearchVectoreStore(
client: $this->elasticClient,
index: 'neuron-ai'
);
}
}
Passing the elasticsearch client instance to the agent:
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.
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,
) {
$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, int $k = 4): 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\AI\Agents;
use NeuronAI\Agent;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
class MyAgent extends Agent
{
public function vectorStore(): VectorStoreInterface
{
return new MyVectorStore (
key: 'VECTORSTORE_API_KEY',
index: 'neuron-ai',
);
}
}
We strongly recommend you to submit new vector store implementations via PR on the official repository or using other Inspector.dev support channels. The new implementation can receives an important boost in its advancement by the community.