Building Local RAG Chatbots Without Coding Using LangFlow and Ollama – Towards Data Science

Welcome to the forefront of conversational AI as we explore the fascinating world of AI chatbots in our dedicated blog series. Discover the latest advancements, applications, and strategies that propel the evolution of chatbot technology. From enhancing customer interactions to streamlining business processes, these articles delve into the innovative ways artificial intelligence is shaping the landscape of automated conversational agents. Whether you’re a business owner, developer, or simply intrigued by the future of interactive technology, join us on this journey to unravel the transformative power and endless possibilities of AI chatbots.
Publish AI, ML & data-science insights to a global community of data professionals.
A Quick Way to Prototype RAG Applications Based on LangChain
⁤Remember the days when building a smart chatbot took months of coding?
Frameworks like LangChain have definitely streamlined development, but hundreds of lines of code can still be a hurdle for those who aren’t programmers. ⁤
Is there a simpler way ? (Find the friend link here to read the full story if you are not already a member of Medium and please consider subscribing to Medium membership to support writers)
That’s when I discovered "Lang Flow," an open-source package that builds upon the Python version of LangChain. It lets you create an AI application without needing to write a single line of code. It provides you a canvas where you can just drag components around and link them up to build your chatbot.
In this post, we’ll use LangFlow to build a smart AI chatbot prototype in minutes. For the backend, we’ll use Ollama for embedding models and Large Language Model, meaning that the application runs locally and free of charge! Finally, we’ll convert this flow into a Streamlit application with minimal coding.
In this project, we’re going to build an AI chatbot, and let’s name it "Dinnerly – Your Healthy Dish Planner." It aims to recommend healthy dish recipes, pulled from a recipe PDF file with the help of Retrieval Augmented Generation (RAG).
Before diving into how we’re going to make it happen, let’s quickly go over the main ingredients we’ll be using in our project.
RAG (Retrieval-Augmented Generation) helps Large Language Models (LLMs) by feeding them relevant information from external sources. This allows LLMs to consider this context when generating responses, making them more accurate and up-to-date.
The RAG pipeline includes typically following steps, as described in A Guide to Retrieval Augmented Generation :
"
"
An open-source framework built around LLMs, LangChain facilitates the design and development of various GenAI applications, including chatbots, summarization, and much more.
The core idea of the library is to "chain" together different components to simplify complex AI tasks and create more advanced use cases around LLMs.
LangFlow is a web tool designed specifically for LangChain. It offers a user interface where users can simply drag and drop components to build and test LangChain applications without any coding.
However, you first need to have a basic understanding of how LangChain works and its different components in order to use LangFlow to design your AI application flow.
Ollama
Ollama is, for me, the best and also the easiest way to get up and running with open source LLMs. It supports, among others, the most capable LLMs such as Llama 2 and Mistral, and you can find the list of available models on ollama.ai/library.
First, go to Ollama download page, pick the version that matches your operating system, download and install it.
With Ollama installed, open your command terminal and enter the following commands. These commands will download the models and run them locally on your machine.
For this project, we’ll be using Llama2 as our Large Language Model (LLM) and "nomic-embed-text" for the embedding model. "Nomic-embed-text" is a powerful open-source embedding model with a large context window. This lets us run the entire application locally, without needing any cloud services!
Before we get started with LangFlow, it’s important to check that Python is installed on your computer. Your Python version should be above 3.9 but older than 3.12.
Installing LangFlow
Next, let’s move on to installing LangFlow. I recommend doing this within a virtual environment. This approach helps manage dependencies neatly within its own space. On my Mac, I use Conda to set things up. Just enter the following commands in a command-line terminal to create a virtual environment named "langflow" with Python 3.11.
If you don’t have Conda, you can also set up a virtual environment directly with Python, with the following commands.
After wrapping up the installation, starting LangFlow is as simple as entering "langflow run" into your terminal.
Then, take the URL it gives you (in the example above, it is http://127.0.0.1: 7860) , paste it into your web browser, and voilà! You should see an interface that looks something like this. This page displays all your projects.
It’s time to craft your first flow!
Start by clicking "New project," which opens up a blank canvas for you. On the left pane, you’ll notice a variety of components ready to be dragged and dropped into your workspace.
For our project, we’re building a chatbot capable of answering questions from a PDF file. Remember the RAG pipeline we talked about earlier? We’ll need certain elements to piece this together:
Drag and drop all these components onto the canvas and set the required fields like the PDF file path and LLM model name. It’s okay to leave other settings at their default.
Next, connect these components to form your flow.
Once everything’s connected, hit the "lightning" button in the bottom right to compile the flow. If all goes well, the button should turn green, indicating success.
After successfully compiling the flow, click the "chatbot" icon to test out your creation.
Several Tips:
Diving into LangFlow with pre-built examples can offer great inspiration and help you get started. Here’s how:
Now, if the flow is set up just right, it’s time to integrate it into your application. After building your flow, LangFlow makes it easy by offering the necessary code snippet. Just hit the "Code" button found in the Sidebar.
Let’s move forward with integrating this flow into a Streamlit chatbot.
3. Building a Chat Function: In the same python file, we’ll define a function dedicated to chatting. This function runs the flow to fetch a response with each new query from the user. Then, it streams this response on the interface.
4. Crafting the Interface : Now we´ll build a simple Streamlit user interface with the following code in the same python file.
Once you run the Streamlit app, you’ll be able to chat with your very own dish planner! It will help you create delicious and healthy meals.
Tips:
You can use the same code and interface for different flows. Just change the FLOW_ID to test and integrate a new flow into your application.
In this post, we’ve crafted a smart, RAG-based chatbot. We utilized LangFlow to establish the RAG pipeline without needing to code, leveraged on open-source models for embedding and LLM processing to keep our application running locally and free of inference costs, and finally, we transformed this setup into a Streamlit application.
I’ve particularly appreciated LangFlow’s no-code way and I do believe it could be a game changer in how we build and prototype AI applications.
However, it’s worth mentioning that some components are still under development, sometimes they may not work as expected. When these moments arise, there is a lack of visibility into the issue or guidance on troubleshooting. Another improvement could be providing the underlying Python codes directly to offer greater customization.
Overall, I find LangFlow a valuable tool for quick prototyping needs.
How I Analyzed My Finance With A Local AI
If you liked my story and you want to support me:
Get an email whenever Yanli Liu publishes.
Written By

Share This Article
Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.
Step-by-step code guide to building a Convolutional Neural Network
A deep dive on the meaning of understanding and how it applies to LLMs
A beginner’s guide to forecast reconciliation
Here’s how to use Autoencoders to detect signals with anomalies in a few lines of…
Feature engineering, structuring unstructured data, and lead scoring
Solving the resource constrained project scheduling problem (RCPSP) with D-Wave’s hybrid constrained quadratic model (CQM)
An illustrated guide on essential machine learning concepts
Your home for data science and Al. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

source

Scroll to Top