The developer’s guide to building AI apps: Part 2

Andrew Tate
Andrew Tate
Technical writer

Jul 25, 2024

Welcome to the second part of our series on building powerful, ROI-driving AI apps. In the last post, we covered considerations around the AI stack and deployment—and some of the challenges you might face building and operating as quickly as you’d like. In this edition, we’ll explore ways to introduce more flexibility and speed into your process without cutting corners, allowing you to go from proof-of-concept to production-ready AI applications confidently. Let’s walk through a step-by-step tutorial on building your first AI app in Retool.

Why an AI chatbot? According to Retool’s 2024 State of AI report, 55.1% of people building AI apps have either built a chatbot or their company has. Another 46.5% think chatbots will be popular for a while. Let’s start with the basics and build a Q&A chatbot from scratch.

(If you aren’t currently a Retool user, you’ll want to create a free account to follow along.)

Add your data to Retool

Once you’re set up with a Retool account, start building by adding whichever data source you want to use to Retool. Navigate to your dashboard and use either UI components or Workflows. In this example, we’ll use Retool Vectors, where you can use a Retool-managed or third-party vector database to build a Q&A chatbot with your own data.

Here, we have an upload component that allows a user to either upload data via text input or upload via an application/pdf mime type. If you choose PDF, Retool will parse the PDF and then upsert it into the Retool database.

From there, Retool Vectors will take over. Retool Vectors combine the embedding process and the vector database, upserting, storing, and querying from above. Under the hood, Retool Vectors is using OpenAI embeddings, but all the process is abstracted away:

The embeddings stored in the Retool Vector database can now be used in the same way as the embeddings above.

Create your AI app’s interface

Now, we can create a chat interface using a pre-built chat component and attach a simple Retool AI query.

Retool AI allows you to use various AI models within your Retool applications. Here, we’ll use GPT-4o, but you can try any number of other models, like Claude, Gemini, Llama3, or Mixtral to find the right fit for your use case. (You can switch between them pretty darn seamlessly too—just use the Model dropdown to select your preferred LLM!)

All we need to do is pass it the lastMessage in the chat, the messageHistory from the chat, and our vectors for more context, along with a system prompt:

When this query is run, the matching embeddings are selected from our vector database and then sent with the query to our model to generate our answer:

We just bypassed all the extra code and infrastructure from part one of this series. You’ll still get the benefits of scalability, reliability, and flexibility of a microservices architecture, but without the complexity and troubleshooting hassles of your own deployment. And you can immediately deploy this application to users.

This allows you to go from proof-of-concept to a working application far more quickly than building out every part of your application from scratch.

Test and experiment with your AI app

Once you’ve built a working AI application, you can easily use Retool to experiment with and see how different LLMs might produce different results. You can change the model that a particular query uses with a single dropdown.

For example, you could build a Retool app, like the one in the image below, that takes the same prompt and shows you the output from four different models at the same time.

With this ability to test and research, you’ll be able to iterate on your Q&A chatbot to find and choose the most suitable model, test your prompts, and fine-tune them as needed.

Use this tutorial to build your first AI app

Layering in AI can transform what’s possible within your apps. With Retool, you can build a working AI app more efficiently in less time and with fewer engineering resources.

This tutorial is just the start. If you’re ready to keep exploring the possibilities of AI-powered tools for your team, here are a few more useful resources:

You can sign up for Retool and start building your first AI apps with Retool AI and Retool Vectors, or you can contact us to learn more about how Retool can help you build your AI applications.

Don’t forget to follow @Retool on X and show us what you’re working on. Happy building!

Reader

Andrew Tate
Andrew Tate
Technical writer
Andrew is an ex-neuroengineer-turned-developer and technical content marketer.
Jul 25, 2024
Copied