AI-Powered Selection of Asset Management Companies using MindsDB and LlamaIndex
Tags: mindsdb, llamaindex, ai, machinelearning
Published: 2023-09-18 14:21:40

Investors make use of Asset Management companies to efficiently manage their assets on their behalf without having any concerns, therefore choosing the correct company is very important which means investors need to query what they want to know in order to make a decision. Asset Management companies want to make sure that they can appeal to investors by providing them with information through their websites. Finding an asset management company that suits your needs and convincing investors to choose your asset management company to assist can be daunting for both parties. AI can alleviate this for both the investor and the asset management company by making sure the investor's questions are answered and the asset management company can answer questions without human interaction.

Asset Management companies rely on their website to provide information about their investment and financial services so that investors are willing to choose them, but how does an investor simplify the process of obtaining answers about an asset management company? This can be resolved with MindsDB's integration with LlamaIndex by creating a Q&A model.

[MindsDB](https://mindsdb.com/) is an AI Automation platform for building AI/ML powered features and applications. It works by connecting any data source with any AI/ML model or framework and automating how real-time data flows between them. MindsDB is integrated with LlamaIndex, which makes use of its data framework for connecting custom data sources to large language models. LlamaIndex data ingestion allows you to connect to data sources like PDF’s, webpages, etc., provides data indexing and a query interface that takes input prompts from your data and provides knowledge-augmented responses, thus making it easy to Q&A over documents and webpages.

For this case, let's explore how to create a Q&A model for the Asset Management company Blackrock that can help investors obtain information seamlessly. This can be done using LlamaIndex, OpenAI as the LLM, and [Blackrock’s About-Us webpage.](https://www.blackrock.com/za/individual/about-us)

[Blackrock](https://www.blackrock.com/corporate) is an asset management company that provides services to investors for investment, advisory and risk management solutions and makes a great example of how creating a Q&A model with MindsDB’s integration with LlamaIndex can be beneficial.

### How to create a Q&A model using MindsDB and LlamaIndex.

MindsDB has a great SQL Editor in it's Cloud GUI for you to use. If you would like to sign up for a demo Cloud account, you can do so [here.](https://cloud.mindsdb.com/)

To create a model, you will have to create the ML engine using the `CREATE ML_ENGINE` syntax in the SQL Editor.

```sql
CREATE ML_ENGINE engine_name
FROM llama_index
```

You can provide the name `llamaindex` to the ML_ENGINE.

On execution, you get:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qlkrt9mork3azcx51ab.png)


We will make use of a file that has been uploaded into the GUI. If you would like to know how to upload a file, you can check the documentation [here.](https://docs.mindsdb.com/sql/create/file). You can find a sample dataset [here.](https://github.com/chandrevdw31/mindsdb-tutorials/blob/main/Datasets/questions.csv)

To upload the file, navigate to the 'Add Icon' on the MindsDB Gui and `Upload File.`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1h6igj8inplq4r8iau4.png)

You can ensure that the data has been uploaded by selecting the file.

Run the following syntax:

```
SELECT * FROM files.about_blackrock LIMIT 10;
```

On execution, you get:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60ou7fpvhw3rrr73z2g4.png)

Once you have created the engine and successfully uploaded your file, you can create the model with the `CREATE MODEL` syntax.

```sql
CREATE MODEL model_name
FROM datasource
	(SELECT * FROM table_name)
PREDICT column_to_be_predicted
USING
  engine = 'llamaindex',
  index_class = 'vector_store_index',
  reader = 'reader_type',
  source_url_link = 'source_url_link',
  input_column = 'column_name',
  openai_api_key = 'your_api_key';
  ```

To ensure that the model is created based on the LlamaIndex engine, the `USING` clause is used to include the `engine` which is the ml_engine LlamaIndex, `index_class` is used to define the type of index class used, `reader` to define the type of reader for the data scrapping, `source_url_link` defines the URL link used to get the answers from, `input_column` defines the column used to prompt the model, and `openai_api_key` is defined with your OpenAI key to gain access to  OpenAI models.

```sql
CREATE MODEL qa_blackrock
FROM files
	(SELECT * FROM about_blackrock)
PREDICT Answers
USING
  engine = 'llamaindex',
  index_class = 'GPTVectorStoreIndex',
  reader = 'DFReader',
  source_url_link = 'https://www.blackrock.com/za/individual/about-us',
  input_column = 'Questions',
  openai_api_key = 'your_api_key';
  ```

On execution, you get:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbwn1z9i42bhll0z2iu0.png)

Where:

| Expression                         	| Description                                		|
|---------------------------------------|----------------------------------------------------------|
| `qa_blackrock`                     	| The name provided to the model.        	|
| `engine`                           	| The engine used, which is Llamaindex.    	|
| `qa_blackrock`                     	| The name provided of the model.        	 |
| `engine`                           	| The engine name - here, LlamaIndex.    	 |
| `index_class`                      	| The vector store index used.        	   	 |
| `reader`                           	|The reader that reads the data/webpage.      |
| `input_column`                     	| prompt provided as a question to the model.|
| `openai_api_key`                  | API key of the LLM OpenAI.             	  |
| `source_url_link`                  	| The webpage link.            		          	  |
| `input_column`                     	| The column that stores prompt to the model.|
| `openai_api_key`                  | OpenAI API key.                      	   	  |


The status of the model can be verified that it has trained successfully into a complete status by using the `DESCRIBE` syntax.

```sql
DESCRIBE qa_blackrock
```

On execution, you get:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/too99isimz7bf615zgdz.png)



### Querying the Q&A model

The Q&A model has been successfully created and can now be prompted with questions with the `SELECT` statement.

```sql
SELECT Questions,Answers
FROM mindsdb.qa_blackrock
WHERE Questions = 'What is the best long term investment with minimal risks for private investors';
```

On execution, you get:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb2l96wwzx1hr3llzxo3.png)

The answer provided is:
```sql
The best long-term investment with minimal risks for private investors is a diversified portfolio of low-cost index funds. These funds typically track a broad market index, such as the S&P 500, and provide exposure to a wide variety of publicly traded companies with minimal risk. Blackrock is one of the largest asset management companies in the world, and offers a range of index funds, exchange-traded funds, and other investment products for private investors.
```

You can also query batch predictions using the `JOIN` clause.

```sql
SELECT a.Questions,b.Answers
FROM mindsdb.qa_blackrock as b
JOIN files.about_blackrock as a;
```

On execution, you get:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2m6uo7lhtsbo2quur1q6.png)

The Q&A model has successfully retrieved information from the webpage and answered the questions prompted


### How can Investors and Asset Management companies incorporate a Q&A model?

Not only can the investors create this Q&A model for themself for decision-making about multiple asset management companies, but also the asset management company can use it to make sure that possible clients are equipped to have their questions answered.

Asset Management companies can embed this Q&A model into their webpage which allows a reader/investor to prompt the model questions about the given webpage, therefore sparing time of having to read through the whole webpage and allowing investors to obtain the information they are looking for.

### AI Workflows with MindsDB

Being able to have users come to your website and QA your webpage is great, but being notified about the questions your webpage is receiving is even better.

An AI workflow can be created by sending the questions prompting the Q&A model as slack notifications in an organization's Slack channel using MindsDB's application integration with Slack.

Connecting Slack to MindsDB can be done in quick easy steps:
- Connecting an existing Slack Application to MindsDB OR
- Create a new Slack application to connect to MindsDB

Slack-SDK is used to implement this handler, which is a Python Library offering a package for each of Slack’s APIs. As we are sending notifications to Slack,the Slack app token for authentication will be used to set up a Slack application to receive notifications. You can follow Method 1 in this [guide](https://docs.mindsdb.com/integrations/app-integrations/slack) to see how you can set up a Slack app and a Bot User OAuth Token.


### Connecting Slack to MindsDB

Once you have created a Slack app or have an existing one, you can go ahead and connect the Slack application to MindsDB.

The `CREATE DATABASE` syntax would be used to establish a connection between Slack and MindsDB using the Bot User OAuth Token.

```sql
CREATE DATABASE slack_app
WITH
  ENGINE = 'slack',
  PARAMETERS = {
  	"token": "xoxb-your_token"
	};
```

On execution, you get:
```sql
Query successfull
```

### Setting up an AI Workflow.

As this use case is for a Q&A  model being embedded into a website, the model's data source will be adjusted.

The question that will prompt the model will first be saved into a database, and then the model will be trained and provided an answer on the webpage.

Instead of the model, that needs to be embedded into the website, which syntax is this:

```sql
CREATE MODEL qa_blackrock
FROM files
	(SELECT * FROM about_blackrock)
PREDICT Answers
USING
  engine = 'blackrock_qa',
  index_class = 'GPTVectorStoreIndex',
  reader = 'DFReader',
  source_url_link = 'https://www.blackrock.com/za/individual/about-us',
  input_column = 'Questions',
  openai_api_key = 'your_api_key';
  ```
 
  The syntax will rather look like this:
 
  ```sql
  CREATE MODEL qa_blackrock
FROM database
	(SELECT * FROM schema.table)
PREDICT Answers
USING
  engine = 'blackrock_qa',
  index_class = 'GPTVectorStoreIndex',
  reader = 'DFReader',
  source_url_link = 'https://www.blackrock.com/za/individual/about-us',
  input_column = 'Questions',
  openai_api_key = 'your_api_key';
  ```

For the sake of this example,we will continue to use files as the datasource.

Here is how to send messages to a Slack channel:

```sql
INSERT INTO slack_app.channels (channel, text)
VALUES("llama_test", "Here are questions from potential investors");
```

On execution, you get:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m33q36dcyol4ftzs4qmm.png)

In the Slack channel you will see the message notification:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5fbrv8xneyukc92uk20.png)

Now you can set up a job to receive notifications each time your webpage gets prompted a question. The `CREATE JOB` syntax will be used.

```sql
CREATE JOB investor_questions (

RETRAIN qa_blackrock
 USING
join_learn_process = true;

INSERT INTO slack_app.channels (channel, text)
VALUES("llama_test", "Here are questions from potential investors");

INSERT INTO slack_app.channels(channel, text)
  SELECT "llama_test" AS channel,
	concat('Question: ', a.Questions, chr(10), 'Answer: ', b.Answers) as text
  FROM mindsdb.qa_blackrock as b
  JOIN files.about_blackrock as a
  LIMIT 3;
)
EVERY 5 minutes;
```

You will receive notifications every 5 minutes if the Q&A model is prompted:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otxi4d18w43oz1ovwrig.png)
You have successfully set up a Q&A model that can be used to be embedded into your webpage and also have an AI workflow that sends notifications to your slack channel each time your model is prompted.

This creates an overview of the kind of information that investors are looking for. It can help you see what services you lack and can implement into your business model. You can take these questions and enhance your webpage’s information. Thus improving the quality of your webpage even further. With the power of Large Language Models, MindsDB makes it possible to serve your potential interested investors, improving the consumer experience and leveraging the power of AI workflows to improve the quality of your company’s presentation as a website.

You check out MindsDB by signing up for a [demo account](https://cloud.mindsdb.com/). If you would like to learn more you can visit [MindsDB's Documentation](https://docs.mindsdb.com/what-is-mindsdb). If you want to contribute to MindsDB, visit their [Github repository](https://github.com/mindsdb/mindsdb) and if you like it give it a star. MindsDB has a vibrant Slack Community and amazing team that provides technical support, if you would like to join you can sign up [here. ](https://mindsdb.com/joincommunity)

_Twitter:[Chan_vdw](https://twitter.com/Chan_vdw)_
_Github: [chandrevdw31](https://github.com/chandrevdw31)_