Transform your text into vector representations! Embeddings let you add Retrieval-Augmented Generation () into your AI applications.
Generate Embeddings
Here's how to generate embeddings with just a few lines of code:
$provider = new VoyageEmbeddingProvider(
key: 'VOYAGE_API_KEY',
model: 'VOYAGE_EMBEDDINGS_MODEL',
);
$embeddings = $provider->embedText("Hi, I'm Valerio, CTO of Inspector.dev");
Available Embeddings Providers
The framework already includes the following embeddings provider.
Ollama
With Ollama you can run embedding models locally. Documentation -
Use in the RAG agent:
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\OllamaEmbeddingsProvider;
use NeuronAI\RAG\RAG;
class MyRAG extends RAG
{
...
protected function embeddings(): EmbeddingsProviderInterface
{
return new OllamaEmbeddingsProvider(
model: 'OLLAMA_EMBEDDINGS_MODEL'
);
}
}
Or in a data loading pipeline:
use NeuronAI\RAG\Embeddings\OllamaEmbeddingsProvider;
$provider = new OllamaEmbeddingsProvider(
model: 'OLLAMA_EMBEDDINGS_MODEL'
);
$embeddings = $provider->embedText('Content to convert.');
Voyage AI
Use in the RAG agent:
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\VoyageEmbeddingsProvider;
use NeuronAI\RAG\RAG;
class MyRAG extends RAG
{
...
protected function embeddings(): EmbeddingsProviderInterface
{
return new VoyageEmbeddingsProvider(
key: 'VOYAGE_API_KEY',
model: 'VOYAGE_EMBEDDINGS_MODEL'
);
}
}
Or in a data loading pipeline:
use NeuronAI\RAG\Embeddings\VoyageEmbeddingsProvider;
$provider = new VoyageEmbeddingsProvider(
key: 'VOYAGE_API_KEY',
model: 'VOYAGE_EMBEDDINGS_MODEL'
);
$embeddings = $provider->embedText('Content to convert.');
OpenAI
Use in the RAG agent:
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\OpenAIEmbeddingsProvider;
use NeuronAI\RAG\RAG;
class MyRAG extends RAG
{
...
protected function embeddings(): EmbeddingsProviderInterface
{
return new OpenAIEmbeddingsProvider(
key: 'OPENAI_API_KEY',
model: 'OPENAI_EMBEDDINGS_MODEL'
);
}
}
Or in a data loading pipeline:
use NeuronAI\RAG\Embeddings\OpenAIEmbeddingsProvider;
$provider = new OpenAIEmbeddingsProvider(
key: 'OPENAI_API_KEY',
model: 'OPENAI_EMBEDDINGS_MODEL'
);
$embeddings = $provider->embedText('Content to convert.');
Implement a new Provider
To create a custom provider you just have to extend the AbstractEmbeddingsProvider class. This class already implement the framework specific methods and let's you free to implement the only provider specific HTTP call into the embedText() method:
You should adjust the HTTP request based on the APIs of the custom provider.
How to use Embeddings providers
Other than attaching the embedding providers to the RAG agent, you can use them as standalone component to create your data loading pipeline to fill vector database with your embedded text.
To create a data loading pipeline you need the ability to convert all the files and information you have into text so you can generate embeddings, and save these information into a vector store.
$provider = new OllamaEmbeddingsProvider(
model: 'OLLAMA_EMBEDDINGS_MODEL',
);
// Use the file data loader component
$embeddedDocuments = $provider->embedDocuments(
FileDataLoader::file(__DIR__.'/readme.md')->getDocuments()
);
Documentation -
Documentation -
Neuron gives you several tools () to simplify this process.
Go to the next section to learn how to use and extend .