Retrieval Augmented Generation
This is a general-purpose Retrieval Augmented Generation handler that can be used to create, train, and depoy models within MindsDB.
It supports the following:
- Large language models such as OpenAI and Writer.
- Vector databases such as ChromaDB and FAISS.
- Embedding models compatible with the Hugging Face sentence_transformers library.
Setup
MindsDB provides the RAG handler that enables you to use RAG methods for training models within MindsDB.
AI Engine
Before creating a model, it is required to create an AI engine based on the provided handler.
If you installed MindsDB locally, make sure to install all RAG dependencies by running pip install .[rag]
or from the requirements.txt file.
You can create a RAG engine using this command and providing either OpenAI or Writer parameters:
The name of the engine (here, rag_engine
) should be used as a value for the engine
parameter in the USING
clause of the CREATE MODEL
statement.
AI Model
The CREATE MODEL
statement is used to create, train, and deploy models within MindsDB.
Where:
Name | Description |
---|---|
llm_type | It defines which LLM is used. |
url | It is used to provide training data from a website. |
vector_store_folder_name | It is a folder name to which the vector db data in between sessions is persisted. |
input_column | It is a column name which stores the input to the model. |
When creating a RAG model, it is required to provide training data either in the url
parameter or in the FROM
clause.
Usage
Simple Example
Below is a complete usage example of the RAG handler.
Create an ML engine - here, we are going to use OpenAI.
Create a model using this engine.
Check the status of the model.
Now you can use the model to answer your questions.
On execution, we get:
Advanced Examples
OpenAI
Create the RAG engine providing credentials for LLM you want to use.
Create a model and embed input data.
Now that the model is created, trained, and deployed, you can query for predictions.
Writer
Create the RAG engine providing credentials for LLM you want to use.
Create a model and embed input data.
Now that the model is created, trained, and deployed, you can query for predictions.