Semantic Search with RAG
This documentation describes the Retrieval Augmented Generation integration that can be used to create, train, and deploy 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.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or use MindsDB Cloud.
- To use RAG within MindsDB, install the required dependencies following this instruction.
- Obtain the OpenAI or Writer API key.
Setup
Create an AI engine from the RAG handler. You can create a RAG engine using this command and providing either OpenAI or Writer parameters:
Create a model using the rag_engine
:
Where:
Name | Description |
---|---|
llm_type | It defines which LLM is used. |
url | It is used to find the knowlege 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 that stores the input to the model. |
When creating a RAG model, it is required to provide data either in the url
parameter or in the FROM
clause.
Usage
The following examples illustrate various ways to integrate RAG with different data sources, including files, URLs, databases, and vector databases.
From a URL
The following example utilize rag_engine
to create a model with the CREATE MODEL
statement.
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:
answer | source_documents | question |
---|---|---|
MindsDB supports various machine learning use cases such as anomaly detection, forecasting, recommenders, classification, and regression. It also supports multimedia use cases such as video and text semantic search, text to audio, text to video, and text to image. | {} | What ML use cases does MindsDB support? |
From Database
The following example utilize rag_engine
to create a model with the CREATE MODEL
statement and MySQL
database as a knowlege base.
Connect to MySQL database:
Create a model using this engine and include the FORM clause:
Now you can use the model to answer your questions.
On execution, we get:
answer | source_documents | question |
---|---|---|
ShopRite Arthritis Pain Acetaminophen is not specifically designed for treating a cold. It may help to temporarily relieve minor aches and pains associated with a cold, but it is not the best product for treating a cold. It is always best to consult with a doctor or pharmacist for the most appropriate medication for treating a cold. | {"column":["full_ingredients","indications_and_usage","intended_purpose_of_product","active_ingredient"],"sources_content":["ShopRite Arthritis ..."],"sources_document":["dataframe"],"sources_row":[1,1,1,1]} | what product is best for treating a cold? |
From File
The following example utilize rag_engine
to create a model with the CREATE MODEL
statement and uploaded file as a knowlege base.
Upload a file using the GUI Upload File
option. Create a model using this engine and include the FORM clause:
Now you can use the model to answer your questions.
On execution, we get:
answer | source_documents | question |
---|---|---|
ShopRite Arthritis Pain Acetaminophen is not specifically designed for treating a cold. It may help to temporarily relieve minor aches and pains associated with a cold, but it is not the best product for treating a cold. It is always best to consult with a doctor or pharmacist for the most appropriate medication for treating a cold. | {"column":["full_ingredients","indications_and_usage","intended_purpose_of_product","active_ingredient"],"sources_content":["ShopRite Arthritis ..."],"sources_document":["dataframe"],"sources_row":[1,1,1,1]} | what product is best for treating a cold? |