How RAG works in Neuron AI
3.xRetrieval-Augmented Generation (RAG) in Neuron AI is implemented by extending the RAG class. A RAG system is composed of three core architectural components that must be defined within your class:
- Vector Store: A component that stores document embeddings to enable semantic search (implements
VectorStoreInterface). - Embeddings Provider: A component that converts raw text into vector embeddings (implements
EmbeddingsProviderInterface). - Retrieval Strategy: A component that determines the logic for searching and ranking retrieved documents (implements
RetrievalInterface).
To use RAG, you create a class that extends NeuronAI ag ag ag and overrides the provider(), embeddings(), and vectorStore() methods.
use NeuronAI\RAG\RAG;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\OpenAIEmbeddingProvider;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
use NeuronAI\RAG\VectorStore\PineconeVectorStore;
class MyChatBot extends RAG
{
protected function provider(): AIProviderInterface
{
return new Anthropic(
key: $_ENV['ANTHROPIC_API_KEY'],
model: 'claude-3-5-sonnet-20241022',
);
}
protected function embeddings(): EmbeddingsProviderInterface
{
return new OpenAIEmbeddingProvider(
key: $_ENV['OPENAI_API_KEY'],
model: 'text-embedding-3-small',
);
}
protected function vectorStore(): VectorStoreInterface
{
return new PineconeVectorStore(
key: $_ENV['PINECONE_API_KEY'],
indexUrl: $_ENV['PINECONE_INDEX_URL']
);
}
}