{"id":140699,"date":"2025-03-18T01:14:53","date_gmt":"2025-03-18T01:14:53","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/how-to-build-a-custom-chatbot-using-qwen-2-5-and-langchain\/"},"modified":"2025-03-18T01:14:53","modified_gmt":"2025-03-18T01:14:53","slug":"how-to-build-a-custom-chatbot-using-qwen-2-5-and-langchain","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=140699","title":{"rendered":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"article-start\">\n<p>In today\u2019s digital world, businesses and individuals aim to provide instant and accurate answers to website visitors. With increased demand for seamless communication, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2021\/10\/complete-guide-to-build-your-ai-chatbot-with-nlp-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">AI-driven chatbots<\/a> have become a crucial tool for user interaction and offering useful information in a split second. Chatbots can search, comprehend, and utilize website data efficiently, making customers satisfied and enhancing the customer experience for companies. In this article, we will explain how to build a chatbot that fetches information from a website, processes it efficiently, and engages in meaningful conversations with the assistance of <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2025\/02\/claude-3-7-sonnet-vs-qwen-2-5-coder\/\" target=\"_blank\" rel=\"noreferrer noopener\">Qwen-2.5<\/a>, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2023\/10\/a-comprehensive-guide-to-using-chains-in-langchain\/\" target=\"_blank\" rel=\"noreferrer noopener\">LangChain<\/a>, and FAISS. we will learn the main components and integration process.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-learning-objectives\">Learning Objectives<\/h4>\n<ul class=\"wp-block-list\">\n<li>Understand the importance of AI-powered chatbots for businesses.<\/li>\n<li>Learn how to extract and process website data for chatbot use.<\/li>\n<li>Gain insights into using FAISS for efficient text retrieval.<\/li>\n<li>Explore the role of Hugging Face embeddings in chatbot intelligence.<\/li>\n<li>Discover how to integrate Qwen-2.5-32b for generating responses.<\/li>\n<li>Build an interactive chatbot interface using Streamlit.<\/li>\n<\/ul>\n<p><em><strong>This article was published as a part of the\u00a0<\/strong><\/em><a href=\"https:\/\/www.analyticsvidhya.com\/datahack\/blogathon\" target=\"_blank\" rel=\"noreferrer noopener\"><em><strong>Data Science Blogathon.<\/strong><\/em><\/a><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-why-use-a-website-chatbot\">Why Use a Website Chatbot?<\/h2>\n<p>Many businesses struggle with handling large volumes of customer queries efficiently. Traditional customer support teams often face delays, leading to frustrated users and increased operational costs. Moreover, hiring and training support agents can be expensive, making it difficult for companies to scale effectively.<\/p>\n<p>A chatbot helps by offering instant and automated responses to user questions without needing a human. Businesses are able to cut support costs considerably, increase customer interaction, and provide users with instant answers to their questions. AI-based chatbots are capable of handling large volumes of data, determining the right information in a matter of seconds, and reacting correctly based on the context, making them very beneficial for businesses nowadays.<\/p>\n<p>Website chatbots are mostly used in E-learning platforms, E-commerce websites, <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2025\/03\/customer-support-voice-agent\/\" target=\"_blank\" rel=\"noreferrer noopener\">customer support<\/a> platforms, and <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2025\/03\/news-agent-hugging-face\/\" target=\"_blank\" rel=\"noreferrer noopener\">news websites<\/a>.<\/p>\n<p><em>Also Read: <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2025\/03\/writing-assistant\/\" target=\"_blank\" rel=\"noreferrer noopener\">Building a Writing Assistant with LangChain and Qwen-2.5-32B<\/a><\/em><\/p>\n<h4 class=\"wp-block-heading\" id=\"h-key-components-of-the-chatbot\">Key Components of the Chatbot<\/h4>\n<ul class=\"wp-block-list\">\n<li><b>Unstructured URL Loader: <\/b>Extracts content from the website.<\/li>\n<li><b>Text Splitter: <\/b>Breaks down large documents into manageable chunks.<\/li>\n<li><b>FAISS (Facebook AI Similarity Search):<\/b> Stores and retrieves document embeddings efficiently.<\/li>\n<li><b>Qwen-2.5-32b:<\/b> A powerful language model that understands queries and generates responses.<\/li>\n<li><b>Streamlit<\/b>: A framework to create an interactive chatbot interface.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-how-does-this-chatbot-work\">How Does This Chatbot Work?<\/h2>\n<p>Here\u2019s a flowchart explaining the working of our chatbot.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"431\" height=\"635\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/chatbot_flow.webp\" alt=\"How the chatbot works\" class=\"wp-image-226671\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/chatbot_flow.webp 431w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/chatbot_flow-204x300.webp 204w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/chatbot_flow-150x221.webp 150w\" sizes=\"(max-width: 431px) 100vw, 431px\"\/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-building-a-custom-chatbot-using-qwen-2-5-32b-and-langchain\">Building a Custom Chatbot Using Qwen-2.5-32b and LangChain<\/h2>\n<p>Now let\u2019s see how to build a custom website chatbot using Qwen-2.5-32b, LangChain, and FAISS.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-1-setting-up-the-foundation\">Step 1: Setting Up the Foundation<\/h3>\n<p>Let\u2019s begin by setting up the prerequisites.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-1-environment-setup\">1. Environment Setup<\/h4>\n<pre class=\"wp-block-code\"><code># Create a Environment\npython -m venv env\n\n# Activate it on Windows\n.\\env\\Scripts\\activate\n\n# Activate in MacOS\/Linux\nsource env\/bin\/activate<\/code><\/pre>\n<h4 class=\"wp-block-heading\" id=\"h-2-install-the-requirements-txt\">2. Install the Requirements.txt<\/h4>\n<pre class=\"wp-block-code\"><code>pip install -r https:\/\/raw.githubusercontent.com\/Gouravlohar\/Chatbot\/refs\/heads\/main\/requirements.txt<\/code><\/pre>\n<h4 class=\"wp-block-heading\" id=\"h-3-api-key-setup\">3. API Key Setup<\/h4>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"384\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_aQNQvbZ.webp\" alt=\"API key setup\" class=\"wp-image-226672\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_aQNQvbZ.webp 872w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_aQNQvbZ-300x132.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_aQNQvbZ-768x338.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_aQNQvbZ-150x66.webp 150w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\"\/><\/figure>\n<p>Paste the API key in .env file.<\/p>\n<pre class=\"wp-block-code\"><code>API_KEY=\"Your API KEY PASTE HERE\"<\/code><\/pre>\n<p>Now let\u2019s get into the actual coding part.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-2-handling-windows-event-loop-for-compatibility\">Step 2: Handling Windows Event Loop (For Compatibility)<\/h3>\n<pre class=\"wp-block-code\"><code>import sys\nimport asyncio\n\nif sys.platform.startswith(\"win\"):\n    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())<\/code><\/pre>\n<p>Ensures compatibility with Windows by setting the correct event loop policy for asyncio, as Windows uses a different default event loop.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-3-importing-required-libraries\">Step 3: Importing Required Libraries<\/h3>\n<pre class=\"wp-block-code\"><code>import streamlit as st\nimport os\nfrom dotenv import load_dotenv<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Streamlit is used to create the chatbot UI.<\/li>\n<li>os is used to set environment variables.<\/li>\n<li>dotenv helps load API keys from a .env file.<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code>os.environ[\"STREAMLIT_SERVER_FILEWATCHER_TYPE\"] = \"none\"  <\/code><\/pre>\n<p>This disables Streamlit\u2019s file watcher to improve performance by reducing unnecessary file system monitoring.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-4-importing-langchain-modules\">Step 4: Importing LangChain Modules<\/h3>\n<pre class=\"wp-block-code\"><code>from langchain_huggingface import HuggingFaceEmbeddings  \nfrom langchain_community.vectorstores import FAISS\nfrom langchain_community.document_loaders import UnstructuredURLLoader\nfrom langchain.text_splitter import RecursiveCharacterTextSplitter\nfrom langchain_groq import ChatGroq\nfrom langchain.chains import create_retrieval_chain\nfrom langchain.chains.combine_documents import create_stuff_documents_chain\nfrom langchain_core.prompts import ChatPromptTemplate<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li><b>HuggingFaceEmbeddings<\/b> : Converts text into vector embeddings.<\/li>\n<li><b>FAISS : <\/b>Stores and retrieves relevant document chunks based on queries.<\/li>\n<li><b>UnstructuredURLLoader :<\/b> Loads text content from web URLs.<\/li>\n<li><b>RecursiveCharacterTextSplitter :<\/b> Splits large text into smaller chunks for processing.<\/li>\n<li><b>ChatGroq : <\/b>Uses the Groq API for AI-powered responses.<\/li>\n<li><b>create_retrieval_chain <\/b>\u2013 Constructs a pipeline that retrieves relevant documents before passing them to the LLM.<\/li>\n<li><b>create_stuff_documents_chain <\/b>\u2013 Combines retrieved documents into a format suitable for LLM processing.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-step-5-loading-environment-variables\">Step 5: Loading Environment Variables<\/h3>\n<pre class=\"wp-block-code\"><code>load_dotenv()\ngroq_api_key = os.getenv(\"API_KEY\")\n\nif not groq_api_key:\n    st.error(\"Groq API Key not found in .env file\")\n    st.stop()<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Loads the Groq API key from the .env file.<\/li>\n<li>If the key is missing, the app shows an error and stops execution.<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\" id=\"h-nbsp-1-function-to-load-website-data\">\u00a01. Function to Load Website Data<\/h4>\n<pre class=\"wp-block-code\"><code>def load_website_data(urls):\n    loader = UnstructuredURLLoader(urls=urls)\n    return loader.load()<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Uses UnstructuredURLLoader to fetch content from a list of URLs.<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\" id=\"h-2-function-to-chunk-documents\">2. Function to Chunk Documents<\/h4>\n<pre class=\"wp-block-code\"><code>def chunk_documents(docs):\n    text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)\n    return text_splitter.split_documents(docs)<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Splits large text into 500-character chunks with 50-character overlap for better context retention.<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\" id=\"h-3-function-to-build-faiss-vector-store\">3. Function to Build FAISS Vector Store<\/h4>\n<pre class=\"wp-block-code\"><code>def build_vectorstore(text_chunks):\n    embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers\/all-MiniLM-L6-v2\")\n    return FAISS.from_documents(text_chunks, embeddings)<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Converts text chunks into vector embeddings using all-MiniLM-L6-v2.<\/li>\n<li>Stores embeddings in a FAISS vector database for efficient retrieval.<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\" id=\"h-4-function-to-load-nbsp-qwen-2-5-32b\">4. Function to Load\u00a0Qwen-2.5-32b<\/h4>\n<pre class=\"wp-block-code\"><code>def load_llm(api_key):\n    return ChatGroq(groq_api_key=api_key, model_name=\"qwen-2.5-32b\", streaming=True)<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Loads Groq\u2019s Qwen-2.5-32b model for generating responses.<\/li>\n<li>Enables streaming for a real-time response experience.<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\" id=\"h-5-streamlit-ui-setup\">5. Streamlit UI Setup<\/h4>\n<pre class=\"wp-block-code\"><code>st.title(\"Custom Website Chatbot(Analytics Vidhya)\")<\/code><\/pre>\n<h4 class=\"wp-block-heading\" id=\"h-6-conversation-history-setup\">6. Conversation History Setup <\/h4>\n<pre class=\"wp-block-code\"><code>if \"conversation\" not in st.session_state:\n    st.session_state.conversation = []<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Stores chat history in st.session_state so messages persist across interactions.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-step-6-fetching-and-processing-website-data\">Step 6: Fetching and Processing Website Data<\/h3>\n<pre class=\"wp-block-code\"><code>urls = [\"https:\/\/www.analyticsvidhya.com\/\"]\ndocs = load_website_data(urls)\ntext_chunks = chunk_documents(docs)<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Loads content from Analytics Vidhya.<\/li>\n<li>Splits the content into small chunks.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-step-7-building-faiss-vector-store\">Step 7: Building FAISS Vector Store<\/h3>\n<pre class=\"wp-block-code\"><code>vectorstore = build_vectorstore(text_chunks)\nretriever = vectorstore.as_retriever()<\/code><\/pre>\n<p>Stores processed text chunks in FAISS . Then Converts the FAISS vectorstore into a retriever that can fetch relevant chunks based on user queries.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-8-loading-the-groq-llm\">Step 8: Loading the Groq LLM<\/h3>\n<pre class=\"wp-block-code\"><code>llm = load_llm(groq_api_key)<\/code><\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-step-9-nbsp-setting-up-retrieval-chain\">Step 9:\u00a0Setting Up Retrieval Chain<\/h3>\n<pre class=\"wp-block-code\"><code>system_prompt = (\n    \"Use the given context to answer the question. \"\n    \"If you don't know the answer, say you don't know. \"\n    \"Use detailed sentences maximum and keep the answer accurate. \"\n    \"Context: {context}\"\n)\n\nprompt = ChatPromptTemplate.from_messages([\n    (\"system\", system_prompt),\n    (\"human\", \"{input}\"),\n])\n\ncombine_docs_chain = create_stuff_documents_chain(llm, prompt)\nqa_chain = create_retrieval_chain(\n    retriever=retriever,\n    combine_docs_chain=combine_docs_chain\n)<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Defines a system prompt to ensure accurate, context-based answers.<\/li>\n<li>Uses <b>ChatPromptTemplate <\/b>to format the chatbot\u2019s interactions.<\/li>\n<li>Combines retrieved documents (combine_docs_chain) to provide context to the LLM.<\/li>\n<\/ul>\n<p>This step creates a <b>qa_chain <\/b>by linking the retriever (FAISS) with the LLM, ensuring responses are based on retrieved website content.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-10-displaying-chat-history\">Step 10: Displaying Chat History<\/h3>\n<pre class=\"wp-block-code\"><code>for msg in st.session_state.conversation:\n    if msg[\"role\"] == \"user\":\n        st.chat_message(\"user\").write(msg[\"message\"])\n    else:\n        st.chat_message(\"assistant\").write(msg[\"message\"])<\/code><\/pre>\n<p>This displays previous conversation messages.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-step-11-accepting-user-input\">Step 11: Accepting User Input<\/h3>\n<pre class=\"wp-block-code\"><code>user_input = st.chat_input(\"Type your message here\") if hasattr(st, \"chat_input\") else st.text_input(\"Your message:\")<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Uses st.chat_input (if available) for a better chat UI.<\/li>\n<li>Falls back to st.text_input for compatibility.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-step-12-processing-user-queries\">Step 12: Processing User Queries <\/h3>\n<pre class=\"wp-block-code\"><code>if user_input:\n    st.session_state.conversation.append({\"role\": \"user\", \"message\": user_input})\n    if hasattr(st, \"chat_message\"):\n        st.chat_message(\"user\").write(user_input)\n    else:\n        st.markdown(f\"**User:** {user_input}\")\n\n    with st.spinner(\"Processing...\"):\n        response = qa_chain.invoke({\"input\": user_input})  \n\n    \n    assistant_response = response.get(\"answer\", \"I'm not sure, please try again.\")\n    st.session_state.conversation.append({\"role\": \"assistant\", \"message\": assistant_response})\n\n    if hasattr(st, \"chat_message\"):\n        st.chat_message(\"assistant\").write(assistant_response)\n    else:\n        st.markdown(f\"**Assistant:** {assistant_response}\")<\/code><\/pre>\n<p>This code handles user input, retrieval, and response generation in a\u00a0 chatbot. When a user enters a message, it is stored in <b>st.session_state.conversation<\/b> and displayed in the chat interface. A loading spinner appears while the chatbot processes the query using <b>qa_chain.invoke({\u201cinput\u201d: user_input})<\/b>, which retrieves relevant information and generates a response. The assistant\u2019s reply is extracted from the response dictionary, ensuring a fallback message if no answer is found. Finally, the assistant\u2019s response is stored and displayed, maintaining a smooth and interactive chat experience.<\/p>\n<p>Get the full code on GitHub <a href=\"https:\/\/github.com\/Gouravlohar\/Chatbot\" target=\"_blank\" rel=\"nofollow noopener\">here<\/a><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-final-output\">Final Output<\/h3>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"556\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_ic06IxR.webp\" alt=\"Custom Website Chatbot Using Qwen-2.5-32b, LangChain, and FAISS\" class=\"wp-image-226673\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_ic06IxR.webp 781w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_ic06IxR-300x214.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_ic06IxR-768x547.webp 768w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_ic06IxR-150x107.webp 150w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\"\/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"h-testing-the-chatbot\">Testing the Chatbot<\/h2>\n<p>Now let\u2019s try out a few prompts on the chatbot we just built.<\/p>\n<p><strong>Prompt: <\/strong><em>\u201cCan you list some ways to engage with the Analytics Vidhya community?\u201d<\/em><\/p>\n<p><strong>Response<\/strong>:<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"460\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_yql1cfm.webp\" alt=\"Custom Website Chatbot Using Qwen-2.5-32b, LangChain, and FAISS\" class=\"wp-image-226674\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_yql1cfm.webp 658w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_yql1cfm-300x210.webp 300w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_yql1cfm-150x105.webp 150w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\"\/><\/figure>\n<p><strong>Prompt: <\/strong><em>\u201cwhat other programs they offers?\u201d<\/em><\/p>\n<p><strong>Response<\/strong>:<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"491\" height=\"500\" src=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_6ERB1n0.webp\" alt=\"output 2\" class=\"wp-image-226675\" srcset=\"https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_6ERB1n0.webp 491w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_6ERB1n0-295x300.webp 295w, https:\/\/cdn.analyticsvidhya.com\/wp-content\/uploads\/2025\/03\/image_6ERB1n0-150x153.webp 150w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\"\/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n<p>AI chatbots have transformed the manner in which people communicate on the internet. Using advanced models like Qwen-2.5-32b, businesses and individuals can make sure that their chatbot responds well and suitably. As technology continues to advance, using AI chatbots on websites will be the order of the day, and people will be able to access information easily.<\/p>\n<p>In the future, developments like having long conversations, voice questioning, and interacting with bigger knowledge pools can further advance chatbots even more.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-key-takeaways\">Key Takeaways<\/h4>\n<ul class=\"wp-block-list\">\n<li>The chatbot fetches content from the Analytics Vidhya website, processes it, and stores it in a FAISS vector database for quick retrieval.<\/li>\n<li>It splits website content into 500-character chunks with a 50-character overlap, ensuring better context retention when retrieving relevant information.<\/li>\n<li>The chatbot uses Qwen-2.5-32b to generate responses, leveraging retrieved document chunks to provide accurate, context-aware answers.<\/li>\n<li>Users can interact with the chatbot using a chat interface in Streamlit, and conversation history is stored for seamless interactions.<\/li>\n<\/ul>\n<p><strong>The media shown in this article is not owned by Analytics Vidhya and is used at the Author\u2019s discretion.<\/strong><a href=\"https:\/\/www.analyticsvidhya.com\/blog\/author\/adarsh2039075\/\"\/><a href=\"https:\/\/www.analyticsvidhya.com\/blog\/author\/mimi6\/\"\/><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-frequently-asked-questions\">Frequently Asked Questions<\/h2>\n<div class=\"schema-faq wp-block-yoast-faq-block\">\n<div class=\"schema-faq-section\" id=\"faq-question-1742220064349\"><strong class=\"schema-faq-question\">Q1. How does this chatbot fetch data from a website?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. It uses UnstructuredURLLoader from LangChain to extract content from specified URLs.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1742220076788\"><strong class=\"schema-faq-question\">Q2. Why is FAISS used in this chatbot?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. FAISS (Facebook AI Similarity Search) helps store and retrieve relevant text chunks efficiently based on user queries.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1742220092006\"><strong class=\"schema-faq-question\">Q3. What model is used for generating responses?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. The chatbot uses Groq\u2019s Qwen-2.5-32B, a powerful LLM, to generate answers based on retrieved website content.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1742220104155\"><strong class=\"schema-faq-question\">Q4. Can this chatbot be extended to multiple websites?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. Yes! Simply modify the urls list to include more websites, and the chatbot will fetch, process, and retrieve information from them.<\/p>\n<\/p><\/div>\n<div class=\"schema-faq-section\" id=\"faq-question-1742220136238\"><strong class=\"schema-faq-question\">Q5. How does the chatbot ensure accurate responses?<\/strong> <\/p>\n<p class=\"schema-faq-answer\">A. It follows a Retrieval-Augmented Generation (RAG) approach, meaning it retrieves relevant website data first and then generates an answer using LLM.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"border-top py-3 author-info my-4\">\n<div class=\"author-card d-flex align-items-center\">\n<div class=\"flex-shrink-0 overflow-hidden\">\n                                    <a href=\"https:\/\/www.analyticsvidhya.com\/blog\/author\/gourav3493022\/\" class=\"text-decoration-none active-avatar\"><br \/>\n                                                                       <img decoding=\"async\" src=\"https:\/\/av-eks-lekhak.s3.amazonaws.com\/media\/lekhak-profile-images\/converted_image_b56toW7.webp\" width=\"48\" height=\"48\" alt=\"Gourav Lohar\" loading=\"lazy\" class=\"rounded-circle\"\/><\/p>\n<p>                                <\/a>\n                                <\/div>\n<\/p><\/div>\n<p>Hi I&#8217;m Gourav, a Data Science Enthusiast with a medium foundation in statistical analysis, machine learning, and data visualization. My journey into the world of data began with a curiosity to unravel insights from datasets.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<p><h4 class=\"fs-24 text-dark\">Login to continue reading and enjoy expert-curated content.<\/h4>\n<p>                        <button class=\"btn btn-primary mx-auto d-table\" data-bs-toggle=\"modal\" data-bs-target=\"#loginModal\" id=\"readMoreBtn\">Keep Reading for Free<\/button>\n                    <\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>In today\u2019s digital world, businesses and individuals aim to provide instant and accurate answers to website visitors. With increased demand for seamless communication, AI-driven chatbots have become a crucial tool for user interaction and offering useful information in a split second. Chatbots can search, comprehend, and utilize website data efficiently, making customers satisfied and enhancing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":140700,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[5815,5293,28812,834,37075,33999],"dealstore":[],"offerexpiration":[],"class_list":["post-140699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-blogathon","tag-build","tag-chatbot","tag-custom","tag-langchain","tag-qwen2-5"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=140699\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"In today\u2019s digital world, businesses and individuals aim to provide instant and accurate answers to website visitors. With increased demand for seamless communication, AI-driven chatbots have become a crucial tool for user interaction and offering useful information in a split second. Chatbots can search, comprehend, and utilize website data efficiently, making customers satisfied and enhancing [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=140699\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-18T01:14:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"872\" \/>\n\t<meta property=\"og:image:height\" content=\"473\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=140699#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain\",\"datePublished\":\"2025-03-18T01:14:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699\"},\"wordCount\":1386,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp\",\"keywords\":[\"Blogathon\",\"Build\",\"chatbot\",\"Custom\",\"LangChain\",\"Qwen2.5\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=140699#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=140699\",\"url\":\"https:\/\/fivemor.com\/?p=140699\",\"name\":\"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp\",\"datePublished\":\"2025-03-18T01:14:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=140699#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=140699\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=140699#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp\",\"width\":872,\"height\":473},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=140699#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=140699","og_locale":"en_US","og_type":"article","og_title":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network","og_description":"In today\u2019s digital world, businesses and individuals aim to provide instant and accurate answers to website visitors. With increased demand for seamless communication, AI-driven chatbots have become a crucial tool for user interaction and offering useful information in a split second. Chatbots can search, comprehend, and utilize website data efficiently, making customers satisfied and enhancing [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=140699","og_site_name":"Som2ny Network","article_published_time":"2025-03-18T01:14:53+00:00","og_image":[{"width":872,"height":473,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp","type":"image\/webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=140699#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=140699"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain","datePublished":"2025-03-18T01:14:53+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=140699"},"wordCount":1386,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=140699#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp","keywords":["Blogathon","Build","chatbot","Custom","LangChain","Qwen2.5"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=140699#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=140699","url":"https:\/\/fivemor.com\/?p=140699","name":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=140699#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=140699#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp","datePublished":"2025-03-18T01:14:53+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=140699#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=140699"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=140699#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/langchain.webp.webp","width":872,"height":473},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=140699#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"How to Build a Custom Chatbot Using Qwen-2.5 and LangChain"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/140699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=140699"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/140699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/140700"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=140699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=140699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=140699"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=140699"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=140699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}