How to Build an AI-based Real Estate Recommendation Agent

mindsdbteam

MindsDB Team

Posted on February 2, 2024

How to Build an AI-based Real Estate Recommendation Agent

Real estate investors are always looking for golden opportunities to invest and build their portfolios.

But finding a suitable company to help guide those investments can be tedious.

How can real estate investors choose the right company to partner with and ensure that they'll be making solid, profitable bets? This can be solved by creating a Q&A model to answer any investor's questions about a property investment company. MindsDB's integration with LlamaIndex assists with querying the company's website and providing information to help the investor make an informed decision.

What is MindsDB?

MindsDB is an AI automation platform that connects any source of data with any AI/ML framework, automating how real-time data flows between them. It’s a unique tool that can help you to build AI-powered features and applications quickly and easily.

In this tutorial, we'll explore how to create a Q&A model that can query the website of Global Investments Inc., a property investment company focused on making U.S. investments simple and accessible for investors. We'll zoom in specifically on the company's investment properties in Detroit, a hotspot for American real estate investors.

We'll use LlamaIndex as the engine and OpenAI as the LLM.

Creating a Q&A model with MindsDB and LlamaIndex

In order to create a model, you'll create the ML engine using the CREATE ML_ENGINE syntax in the SQL Editor. Use llama_index as the engine name.

CREATE ML_ENGINE llama_index_engine
FROM llama_index;
Enter fullscreen mode Exit fullscreen mode

On execution, you get:

Query successfully completed
Enter fullscreen mode Exit fullscreen mode

Once you've created the engine, you can create the model with the CREATE MODEL syntax. The datasource will be uploaded as a file.

Read more documentation on how to upload a file to MindsDB here. You can find a sample dataset here.

CREATE MODEL global_investment_qa
FROM files
   (SELECT * FROM global_investment)
PREDICT answer
USING
   engine = 'llama_index_engine',
   index_class = 'GPTVectorStoreIndex',
   reader = 'DFReader',
   source_url_link = 'https://globalinvestsinc.com/detroit-investment-guide/',
   input_column = 'question',
   openai_api_key = 'your_openai_api_key';
Enter fullscreen mode Exit fullscreen mode

Where:

Expression Description
global_investment_qa 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.
source_url_link The webpage link.
input_column The column that stores prompt to the model.
openai_api_key OpenAI API key.

On execution, your screen will look like this:

Image description

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

DESCRIBE global_investment_qa
Enter fullscreen mode Exit fullscreen mode

On execution, your screen will look like this:

Image description

Prompting the Q&A model

Once the model is successfully created, you can query the model with the SELECT syntax.

SELECT question,answer
FROM mindsdb.global_investment_qa
WHERE question = 'Why should investors invest into Detroit?';
Enter fullscreen mode Exit fullscreen mode

On execution, your screen looks like this:

Image description

The model answered the question with the below:

Investing in Detroit can be a great opportunity for investors due to the city's low cost of living, growing job market, low business taxes, and vibrant cultural scene. Detroit's economy is experiencing a resurgence, with new businesses, restaurants, and housing developments popping up across the city. Additionally, with the rise of the automotive industry, Detroit is a great place for investors to get in early and capitalize on the city's growth.

You can also query batch predictions using the JOIN clause.

SELECT a.question,b.answer
FROM files.global_investment as a
JOIN mindsdb.global_investment_qa as b
LIMIT 4;
Enter fullscreen mode Exit fullscreen mode

On execution, this looks like:

Image description

The model provides answers to the questions prompted.

How does this benefit real estate investors?

Savvy real estate investors might use this model to help them decide if a property investment company is suitable. Using AI minimizes the amount of time spent doing research on the company and asking questions manually.

On the flip side, property investment companies could have such a Q&A model embedded into the front-end design of their websites, so that investors could easily query the page and see if the company passes muster.

Using the power of MindsDB and LlamaIndex, the investor's experience is smooth. An investor can retrieve information seamlessly from any website they like and make an informed decision.

AI Workflows with MindsDB

Let's say you're running a property investment website and want to answer potential queries quickly. But how do the questions get to you?

One solution is to build an AI workflow that sends investor questions from the Q&A model as Slack notifications to your own company Slack channel. You can do this using MindsDB's application integration with Slack.

Connecting Slack to MindsDB

Connecting Slack to MindsDB can be done in the follwing 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.

Once you have created a Slack app or have an existing one, you can go ahead and connect the Slack application to MindsDB. You can follow this guide to see how to set up a Slack app and a Bot User OAuth Token.

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

CREATE DATABASE slack_app
WITH
   ENGINE = 'slack',
   PARAMETERS = {
      "token": "xoxb-your_token"
   };
Enter fullscreen mode Exit fullscreen mode

On execution, you get:

Query successfully completed
Enter fullscreen mode Exit fullscreen mode

Setting up an AI Workflow

As you build your AI Workflow, the questions that flow into the Q&A model will need to be saved in a data source. This way, when notifications are sent to the Slack channel, both the question and answer are included.

For the sake of this tutorial, we will continue to use Files as the data source, however when embedding the model, you will make use of a model with the below syntax:

CREATE MODEL global_investment_qa
FROM database
   (SELECT * FROM schema.table)
PREDICT answer
USING
   engine = 'llama_index_engine',
   index_class = 'GPTVectorStoreIndex',
   reader = 'DFReader',
   source_url_link = 'https://globalinvestsinc.com/detroit-investment-guide/',
   input_column = 'question',
   openai_api_key = 'your_openai_api_key';
Enter fullscreen mode Exit fullscreen mode

Let’s continue, using Files as a data source.

Here is how to send messages to a Slack channel:

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

The notification will be sent to your Slack channel:

Image description

Now let’s set up an AI Workflow by creating a job. The CREATE JOB syntax will be used.

CREATE JOB property_investor_questions (

    RETRAIN global_investment_qa
    FROM files (SELECT * FROM global_investment)
    USING
    join_learn_process = true;

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

    INSERT INTO slack_app.channels(channel, text)
        SELECT "llama_test" AS channel,
        concat('question: ', a.question, chr(10), 'answer: ', b.answer) as text
        FROM mindsdb.global_investment_qa as b
        JOIN files.global_investment as a
        LIMIT 3;

)
EVERY 5 minutes;
Enter fullscreen mode Exit fullscreen mode

On execution, you get:

Query successfully completed
Enter fullscreen mode Exit fullscreen mode

Your Slack channel will get this notification:

Image description

The job was successfully created and Slack notification sent.

With MindsDB, you can leverage the power of Large Language Models and AI workflows to guide your own investment choices or improve your webpage’s information and services for potential investors.

Explore MindsDB further at What is MindsDB. Or, check us out on GitHub. (Love what we’re doing? Give us a high five and star our repo.)

Questions about this tutorial or others? Join our Slack community.

💖 💪 🙅 🚩
mindsdbteam
MindsDB Team

Posted on February 2, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related