{"id":1295,"date":"2024-02-11T05:40:06","date_gmt":"2024-02-11T05:40:06","guid":{"rendered":"https:\/\/ai-box.eu\/?p=1295"},"modified":"2024-03-09T05:02:00","modified_gmt":"2024-03-09T05:02:00","slug":"rag-chat-applikation-langchain-ollama-streamlit","status":"publish","type":"post","link":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/","title":{"rendered":"RAG Chat-Applikation &#8211; Langchain + Ollama + Streamlit"},"content":{"rendered":"<p>In terms of technical requirements and architecture, this solution is not very complex and is therefore ideal for getting started with large language models. It is also guaranteed to give you an initial sense of achievement very quickly. All the components used can be easily installed and combined with each other. I have followed the description below and have added a few more pieces of information that were important to me.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Source:<\/strong> <a href=\"https:\/\/blog.duy-huynh.com\/build-your-own-rag-and-run-them-locally\/\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.duy-huynh.com\/build-your-own-rag-and-run-them-locally\/<\/a><\/p>\n<p>In the article &#8220;<a href=\"https:\/\/ai-box.eu\/en\/top-story-en\/ollama-ubuntu-installation-and-configuration\/1292\/\" target=\"_blank\" rel=\"noopener\">Ollama Ubuntu installation and configuration<\/a>&#8221; we have already installed Ollama. Now I would like to briefly explain the architecture of the application that we are now going to build. The following image briefly shows the structure. We have the LLM server Ollama and the virtual environment in which all the components are installed that our RAG application needs so that we can chat with a PDF file. Streamlit provides the user interface. We also have the user who has to upload a PDF file in order to be able to interact with it.<\/p>\n<div id=\"attachment_1208\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-1024x541.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1208\" class=\"wp-image-1208 size-large\" src=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-1024x541.png\" alt=\"RAG Chat-PDF app architecture\" width=\"1024\" height=\"541\" srcset=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-1024x541.png 1024w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-300x158.png 300w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-768x406.png 768w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-1536x811.png 1536w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture-1080x571.png 1080w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png 1611w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><p id=\"caption-attachment-1208\" class=\"wp-caption-text\">RAG Chat-PDF app architecture<\/p><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Video_Introductory_course\" >Video Introductory course<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Software_installation\" >Software installation<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Error_messages\" >Error messages:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#The_program_code\" >The program code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Run_the_RAG_Chat_application_program\" >Run the RAG Chat application program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#First_tests_and_chat_attempts\" >First tests and chat attempts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Creating_text_embeddings_%E2%80%93_background_knowledge\" >Creating text embeddings &#8211; background knowledge<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Hierarchical_Contextual_Augmentation\" >Hierarchical Contextual Augmentation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Summarizing_a_text_with_LangChain_and_Ollama_and_StableLM_2\" >Summarizing a text with LangChain and Ollama and StableLM 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Video_Kurs_%E2%80%93_Advanced_QA_over_a_lot_of_Tabular_Data_combine_text-to-SQL_with_RAG\" >Video Kurs &#8211; Advanced QA over a lot of Tabular Data (combine text-to-SQL with RAG)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Video_Introductory_course\"><\/span>Video Introductory course<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To familiarize yourself with the basic principles of a retrieval-augmented generation (RAG) application, I recommend watching the following videos at your leisure.<\/p>\n<ul>\n<li>RAG From Scratch: Part 1 (Overview)\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=wd7TZ4w1mSw\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=wd7TZ4w1mSw<\/a><\/li>\n<\/ul>\n<\/li>\n<li>RAG From Scratch: Part 2 (Indexing)\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=bjb_EMsTDKI\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=bjb_EMsTDKI<\/a><\/li>\n<\/ul>\n<\/li>\n<li>RAG From Scratch: Part 3 (Retrieval)\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=LxNVgdIz9sU\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=LxNVgdIz9sU<\/a><\/li>\n<\/ul>\n<\/li>\n<li>RAG From Scratch: Part 4 (Geneartion)\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=Vw52xyyFsB8\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=Vw52xyyFsB8<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>My article here goes straight into the development of the application and does not go into why something is done and how. I would like to mention once again that in this RAG application the data is not transferred to the Internet but everything runs locally on your computer.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Software_installation\"><\/span>Software installation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I always set up a virtual Anaconda environment for my projects. That&#8217;s what I&#8217;m doing here and if you haven&#8217;t installed Anaconda on your Ubuntu yet you can read here how to set up Anaconda.<\/p>\n<p style=\"padding-left: 40px;\"><strong>URL:<\/strong> <a href=\"https:\/\/ai-box.eu\/software\/installation-von-anaconda-auf-ubuntu-lts-version\/1170\/\" target=\"_blank\" rel=\"noopener\">https:\/\/ai-box.eu\/software\/installation-von-anaconda-auf-ubuntu-lts-version\/1170\/<\/a><\/p>\n<p>The following command creates an Anaconda environment with the name <code>ollama_rag<\/code>.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Befehl:<\/strong> <code>conda create --name ollama_rag<\/code><strong><br \/>\n<\/strong><\/p>\n<p>You still need to activate the newly created environment. To do this, please execute the following command.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Befehl:<\/strong> <code>conda activate ollama_rag<\/code><\/p>\n<p>Now please install the extensions with the following command in the virtual environment <code>ollama_rag<\/code>.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Befehl:<\/strong> <code>pip install langchain langchain-community chromadb fastembed streamlit streamlit_chat <\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Error_messages\"><\/span>Error messages:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>After installing the packages as described above, I received the following error messages. I will now continue to see how relevant these are. Just as an example, the fact that openai&gt;=0.26.4 is not installed should not be a problem for the further progress of the project.<\/p>\n<blockquote><p><code>ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.<\/code><br \/>\n<code>llama-index 0.6.12 requires openai&gt;=0.26.4, which is not installed.<\/code><br \/>\n<code>auto-gptq 0.3.0+cu117 requires datasets, which is not installed.<\/code><br \/>\n<code>transformers 4.26.1 requires tokenizers!=0.11.3,&lt;0.14,&gt;=0.11.1, but you have tokenizers 0.15.1 which is incompatible.<\/code><br \/>\n<code>llama-index 0.6.12 requires typing-extensions==4.5.0, but you have typing-extensions 4.9.0 which is incompatible.<\/code><br \/>\n<code>clip-interrogator 0.6.0 requires transformers&gt;=4.27.1, but you have transformers 4.26.1 which is incompatible.<\/code><br \/>\n<code>auto-gptq 0.3.0+cu117 requires transformers&gt;=4.29.0, but you have transformers 4.26.1 which is incompatible.<\/code><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"The_program_code\"><\/span>The program code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This small application consists of two Python files. One represents the logic for the interaction with the large language model mistral via the Ollama server. The other Python file represents the user interface and is based on the Python program with the logic. I have created a folder with the name rag and placed the following two Python programs in it.<\/p>\n<p>You can find the original program here on GitHub.<\/p>\n<p style=\"padding-left: 40px;\"><strong>URL:<\/strong> <a href=\"https:\/\/gist.github.com\/vndee\/7776debe50b5e6c2b174add8646a4625\" target=\"_blank\" rel=\"noopener\">https:\/\/gist.github.com\/vndee\/7776debe50b5e6c2b174add8646a4625<\/a><\/p>\n<p>Copy the following source code into a Python file with the name <code>rag.py<\/code>.<\/p>\n<hr \/>\n<div>\n<div style=\"padding-left: 40px;\"><code>from langchain.vectorstores import Chroma<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.chat_models import ChatOllama<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.embeddings import FastEmbedEmbeddings<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.schema.output_parser import StrOutputParser<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.document_loaders import PyPDFLoader<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.text_splitter import RecursiveCharacterTextSplitter<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.schema.runnable import RunnablePassthrough<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.prompts import PromptTemplate<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from langchain.vectorstores.utils import filter_complex_metadata<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>class ChatPDF:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 vector_store = None<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 retriever = None<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 chain = None<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 def __init__(self):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.model = ChatOllama(model=\"mistral\")<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1024, chunk_overlap=100)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.prompt = PromptTemplate.from_template(<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"\"\"<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;s&gt; [INST] You are an assistant for question-answering tasks. Use the following pieces of retrieved context<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 to answer the question. If you don't know the answer, just say that you don't know. Use three sentences<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0maximum and keep the answer concise. [\/INST] &lt;\/s&gt;<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [INST] Question: {question}<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Context: {context}<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Answer: [\/INST]<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"\"\"<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 )<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 def ingest(self, pdf_file_path: str):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 docs = PyPDFLoader(file_path=pdf_file_path).load()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 chunks = self.text_splitter.split_documents(docs)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 chunks = filter_complex_metadata(chunks)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 vector_store = Chroma.from_documents(documents=chunks, embedding=FastEmbedEmbeddings())<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.retriever = vector_store.as_retriever(<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 search_type=\"similarity_score_threshold\",<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 search_kwargs={<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"k\": 3,<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"score_threshold\": 0.5,<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 },<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 )<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.chain = ({\"context\": self.retriever, \"question\": RunnablePassthrough()}<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | self.prompt<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | self.model<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | StrOutputParser())<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 def ask(self, query: str):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 if not self.chain:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return \"Please, add a PDF document first.\"<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 return self.chain.invoke(query)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 def clear(self):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.vector_store = None<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.retriever = None<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 self.chain = None<\/code><\/div>\n<\/div>\n<div><\/div>\n<div>\n<hr \/>\n<\/div>\n<div>Now you need the second file that contains the user interface and includes the <code>rag.py<\/code> file. I also copied this from the following project on GitHub.<\/div>\n<div style=\"padding-left: 40px;\"><strong>URL:<\/strong> <a href=\"https:\/\/gist.github.com\/vndee\/09703717610b49c097af2f97da1654cc\" target=\"_blank\" rel=\"noopener\">https:\/\/gist.github.com\/vndee\/09703717610b49c097af2f97da1654cc<\/a><\/div>\n<div>Copy the following source code into a Python file with the name <code>rag-app.py<\/code>.<\/div>\n<div>\n<hr \/>\n<\/div>\n<div><\/div>\n<div>\n<div>\n<div style=\"padding-left: 40px;\"><code>import os<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>import tempfile<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>import streamlit as st<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from streamlit_chat import message<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>from rag import ChatPDF<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>st.set_page_config(page_title=\"ChatPDF\")<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>def display_messages():<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.subheader(\"Chat\")<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 for i, (msg, is_user) in enumerate(st.session_state[\"messages\"]):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 message(msg, is_user=is_user, key=str(i))<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.session_state[\"thinking_spinner\"] = st.empty()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>def process_input():<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 if st.session_state[\"user_input\"] and len(st.session_state[\"user_input\"].strip()) &gt; 0:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 user_text = st.session_state[\"user_input\"].strip()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 with st.session_state[\"thinking_spinner\"], st.spinner(f\"Thinking\"):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 agent_text = st.session_state[\"assistant\"].ask(user_text)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 st.session_state[\"messages\"].append((user_text, True))<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 st.session_state[\"messages\"].append((agent_text, False))<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>def read_and_save_file():<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.session_state[\"assistant\"].clear()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.session_state[\"messages\"] = []<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.session_state[\"user_input\"] = \"\"<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 for file in st.session_state[\"file_uploader\"]:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 with tempfile.NamedTemporaryFile(delete=False) as tf:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 tf.write(file.getbuffer())<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 file_path = tf.name<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 with st.session_state[\"ingestion_spinner\"], st.spinner(f\"Ingesting {file.name}\"):<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 st.session_state[\"assistant\"].ingest(file_path)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 os.remove(file_path)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>def page():<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 if len(st.session_state) == 0:<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 st.session_state[\"messages\"] = []<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 st.session_state[\"assistant\"] = ChatPDF()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.header(\"ChatPDF\")<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.subheader(\"Upload a document\")<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.file_uploader(<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 \"Upload document\",<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 type=[\"pdf\"],<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 key=\"file_uploader\",<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 on_change=read_and_save_file,<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 label_visibility=\"collapsed\",<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 \u00a0 \u00a0 accept_multiple_files=True,<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 )<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.session_state[\"ingestion_spinner\"] = st.empty()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 display_messages()<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 st.text_input(\"Message\", key=\"user_input\", on_change=process_input)<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>if __name__ == \"__main__\":<\/code><\/div>\n<div style=\"padding-left: 40px;\"><code>\u00a0 \u00a0 page()<\/code><\/div>\n<\/div>\n<div><\/div>\n<div>\n<hr \/>\n<\/div>\n<div>If you have saved both files then continue here in the following paragraph.<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Run_the_RAG_Chat_application_program\"><\/span>Run the RAG Chat application program<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now change to the rag folder on your computer in the console and execute the Python file <code>rag-app.py<\/code> with the following command.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Befehl: <\/strong><code>streamlit run rag-app.py<\/code><\/p>\n<p>If you now call up the IP address with port 8501 in the browser, the web interface of the small application should open.<\/p>\n<p style=\"padding-left: 40px;\"><strong>URL:<\/strong> <code>&lt;Eure IP-Adresse&gt;:8501<\/code><\/p>\n<p>My web interface now looks like this.<\/p>\n<div id=\"attachment_1212\" style=\"width: 815px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/simple_chat_pdf_app.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1212\" class=\"wp-image-1212 size-full\" src=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/simple_chat_pdf_app.jpg\" alt=\"simple chat pdf app\" width=\"805\" height=\"645\" srcset=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/simple_chat_pdf_app.jpg 805w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/simple_chat_pdf_app-300x240.jpg 300w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/simple_chat_pdf_app-768x615.jpg 768w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/a><p id=\"caption-attachment-1212\" class=\"wp-caption-text\">simple chat pdf app<\/p><\/div>\n<p>Now you have to upload a PDF file.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"First_tests_and_chat_attempts\"><\/span>First tests and chat attempts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For the first attempt I downloaded a travel guide about NewYork. You can find it here.<\/p>\n<p style=\"padding-left: 40px;\"><strong>URL:<\/strong> <a href=\"https:\/\/guides.tripomatic.com\/download\/tripomatic-free-city-guide-new-york-city.pdf\" target=\"_blank\" rel=\"noopener\">https:\/\/guides.tripomatic.com\/download\/tripomatic-free-city-guide-new-york-city.pdf<\/a><\/p>\n<p>Now load the file into the small app and wait briefly until the vector DB is set up. Then I have asked the following question which should be able to be answered from the PDF file.<\/p>\n<p style=\"padding-left: 40px;\"><strong>Frage:<\/strong> &#8220;I need your help as an travel guide for NewYork. I woul like to visit NewYork in March. Please tell what going on in NewYork in March.&#8221;<\/p>\n<p>The answer that came back was correct and can be found exactly as it is in the PDF file.<\/p>\n<div id=\"attachment_1214\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-1024x599.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1214\" class=\"wp-image-1214 size-large\" src=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-1024x599.png\" alt=\"RAG Chat app example\" width=\"1024\" height=\"599\" srcset=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-1024x599.png 1024w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-300x176.png 300w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-768x449.png 768w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-1536x899.png 1536w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example-1080x632.png 1080w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_example.png 1923w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><p id=\"caption-attachment-1214\" class=\"wp-caption-text\">RAG Chat app example<\/p><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Creating_text_embeddings_%E2%80%93_background_knowledge\"><\/span>Creating text embeddings &#8211; background knowledge<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now I would like to briefly discuss a very important point with you about this RAG Chat application. The PDF file is broken down into text embeddings and saved as vectors in the Chroma vector DB. Now creating the vectors is not so easy as they should ideally contain sections of the text that are linked together. If the text is split up rather unfavorably, the RAG application may not deliver good results. To help you visualize this better, <a href=\"https:\/\/twitter.com\/GregKamradt\" target=\"_blank\" rel=\"noopener noreferrer\">Greg Kamradt<\/a> has created the following mini-application which allows you to visualize the cutting of the text into text embeddings.<\/p>\n<p style=\"padding-left: 40px;\"><strong>URL:<\/strong> <a href=\"https:\/\/chunkviz.up.railway.app\/\" target=\"_blank\" rel=\"noopener\">https:\/\/chunkviz.up.railway.app\/<\/a><\/p>\n<p>In the rag.py program, the text is split using the <code>RecursiveCharacterTextSplitter<\/code> method and stored as a text embedding with a length of 1024 characters with an overlap of 100 characters as vectors.<\/p>\n<div>\n<div style=\"padding-left: 40px;\"><code>self.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1024, chunk_overlap=100)<\/code><\/div>\n<\/div>\n<p>I copied the overview with the events in NewYork from the PDF file and pasted it into ChunkViz. Depending on the settings, ChunkViz then generates an overview of how the chunks would be created and this then looks as shown below. It is also interesting to see that the parameter <code>chunk_overlap=100<\/code> is probably not used in the<code> RecursiveCharacterTextSplitter<\/code> method.<\/p>\n<div id=\"attachment_1216\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-1024x952.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1216\" class=\"wp-image-1216 size-large\" src=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-1024x952.jpg\" alt=\"ChunkViz version 0.1\" width=\"1024\" height=\"952\" srcset=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-1024x952.jpg 1024w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-300x279.jpg 300w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-768x714.jpg 768w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1-1080x1004.jpg 1080w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/ChunkViz_v_0_1.jpg 1342w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><p id=\"caption-attachment-1216\" class=\"wp-caption-text\">ChunkViz version 0.1<\/p><\/div>\n<p>But just try out for yourself how you can best transfer your text to the vector DB.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Hierarchical_Contextual_Augmentation\"><\/span>Hierarchical Contextual Augmentation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For those who found this excursion interesting, I recommend reading the following paper &#8220;<strong>A Hierarchical Contextual Augmentation RAG for Massive Documents QA<\/strong>&#8220;.<\/p>\n<p>The paper discusses the limitations of the traditional RAG (Retrieval-Augmented Generation) approach to accurate information retrieval in large documents with text, tables and images such as a HomeDepot product catalog or the Makita tool catalog. To overcome these challenges, the paper presents a hierarchical contextual augmentation (HCA) approach and introduces the MasQA dataset for evaluating multi-document question answering (MDQA) systems.<\/p>\n<p>The HCA approach consists of three main steps:<\/p>\n<ol>\n<li><strong>Markdown Formatter:<\/strong> Uses Language Model (LLM) to analyze documents in Markdown format and treats each chapter as a first-level heading with a numeric identifier. It also generates tables and extracts images using PDFImageSearcher.<\/li>\n<li><strong>Hierarchical Contextual Augmentor (HCA):<\/strong> Processes structural metadata, converts segments into embedding vectors and embeds captions generated by Very Large Models (VLMs). Data fields within tables are omitted during embedding.<\/li>\n<li><strong>Multi-way search:<\/strong> Combines vector search, elastic search and keyword matching to improve the precision of information searches.<\/li>\n<\/ol>\n<p>The evaluation of the approach introduces the Log-Rank Index measure to assess ranking effectiveness. The MasQA dataset includes a variety of materials, including technical manuals and financial reports, with a diverse selection of question types such as single and multiple choice, descriptive, table and calculation questions.<\/p>\n<div id=\"attachment_1224\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-1024x503.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1224\" class=\"wp-image-1224 size-large\" src=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-1024x503.jpg\" alt=\"HiQA Framework\" width=\"1024\" height=\"503\" srcset=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-1024x503.jpg 1024w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-300x147.jpg 300w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-768x377.jpg 768w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-1536x754.jpg 1536w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework-1080x530.jpg 1080w, https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/HiQA_Framework.jpg 1613w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><p id=\"caption-attachment-1224\" class=\"wp-caption-text\">HiQA Framework<\/p><\/div>\n<ul>\n<li>The scientific paper is available here: <a href=\"https:\/\/arxiv.org\/pdf\/2402.01767.pdf\" target=\"_blank\" rel=\"noopener\">A Hierarchical Contextual Augmentation RAG for Massive Documents QA<\/a><\/li>\n<li>The software is available here on GitHub: <a href=\"https:\/\/github.com\/TebooNok\/HiQA\" target=\"_blank\" rel=\"noopener\">Hierarchical Contextual Augmentation RAG for Massive Documents QA<\/a><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Summarizing_a_text_with_LangChain_and_Ollama_and_StableLM_2\"><\/span>Summarizing a text with LangChain and Ollama and StableLM 2<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Another interesting project that I would like to try out myself is this one: <a class=\"wb-break-all\" href=\"https:\/\/gist.github.com\/AI-Guru\/3f8f842219c3010d6daa678c14de9b7e#file-ollamalangchainsummary-py\" target=\"_blank\" rel=\"noopener\"><strong class=\"user-select-contain gist-blob-name css-truncate-target\">ollamalangchainsummary.py <\/strong><\/a><\/p>\n<ul>\n<li><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\">Setup: <\/span>\n<ul>\n<li><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\">My MacBookPro M3Max with 48 GB GPU.<\/span><\/li>\n<li><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\">Ollama as Language Model host. <\/span><\/li>\n<li><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\">Stability AI&#8217;s StableLM.\u00a0<\/span><\/li>\n<li><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\"> LangChain as the underlying toolbox.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Video_Kurs_%E2%80%93_Advanced_QA_over_a_lot_of_Tabular_Data_combine_text-to-SQL_with_RAG\"><\/span><span class=\"css-1qaijid r-bcqeeo r-qvutc0 r-poiln3\"><span class=\"r-b88u0q\">Video Kurs &#8211; Advanced QA over a lot of Tabular Data (combine text-to-SQL with RAG)<\/span><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li class=\"style-scope ytd-watch-metadata\"><a href=\"https:\/\/www.youtube.com\/watch?v=CeDS1yvw9E4\" target=\"_blank\" rel=\"noopener\">Introduction to Query Pipelines (Building Advanced RAG, Part 1)<\/a><\/li>\n<li class=\"style-scope ytd-watch-metadata\"><a href=\"https:\/\/www.youtube.com\/watch?v=L1o1VPVfbb0\" target=\"_blank\" rel=\"noopener\">LLMs for Advanced Question-Answering over Tabular\/CSV\/SQL Data (Building Advanced RAG, Part 2)<\/a><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I really enjoyed building and developing this small RAG chat application with the Ollama server and the two Python programs. Compared to August 2023 and now February 2024, the development is already much further along and building such small applications together with one of the large language models is a lot of fun. It is also no longer so difficult to get everything up and running. There are lots of up-to-date videos on YouTube and instructions on GitHub &amp; Co. So I&#8217;m happy about what a great time I&#8217;m living in and will be trying out a few more things here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In terms of technical requirements and architecture, this solution is not very complex and is therefore ideal for getting started with large language models. It is also guaranteed to give you an initial sense of achievement very quickly. All the components used can be easily installed and combined with each other. I have followed the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[162,50],"tags":[348,272,337,340,343,342,338,345,346,89,333,305,316,306,352,339,307,347,350,344,341,351,349,270],"class_list":["post-1295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-large-language-models-en","category-top-story-en","tag-advanced-qa","tag-anaconda-en","tag-architecture","tag-chatpdf","tag-chunkviz","tag-embeddings","tag-error-messages","tag-hierarchical-contextual-augmentation","tag-hiqa-framework","tag-installation-en","tag-langchain-en","tag-llm-en","tag-mistral-en","tag-ollama-en","tag-pdf-en","tag-python","tag-rag-en","tag-stablelm","tag-streamlit-en","tag-text-splitting","tag-user-interface","tag-vector-db-en","tag-video-course","tag-virtual-environment","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box<\/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:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box\" \/>\n<meta property=\"og:description\" content=\"In terms of technical requirements and architecture, this solution is not very complex and is therefore ideal for getting started with large language models. It is also guaranteed to give you an initial sense of achievement very quickly. All the components used can be easily installed and combined with each other. I have followed the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/\" \/>\n<meta property=\"og:site_name\" content=\"Exploring the Future: Inside the AI Box\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-11T05:40:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-09T05:02:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1611\" \/>\n\t<meta property=\"og:image:height\" content=\"851\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Maker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Ingmar_Stapel\" \/>\n<meta name=\"twitter:site\" content=\"@Ingmar_Stapel\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Maker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/\"},\"author\":{\"name\":\"Maker\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/#\\\/schema\\\/person\\\/cc91d08618b3feeef6926591b465eab1\"},\"headline\":\"RAG Chat-Applikation &#8211; Langchain + Ollama + Streamlit\",\"datePublished\":\"2024-02-11T05:40:06+00:00\",\"dateModified\":\"2024-03-09T05:02:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/\"},\"wordCount\":1482,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ai-box.eu\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/RAG_Chat_app_architecture.png\",\"keywords\":[\"advanced QA\",\"Anaconda\",\"architecture\",\"ChatPDF\",\"ChunkViz\",\"embeddings\",\"error messages\",\"hierarchical contextual augmentation\",\"HiQA framework\",\"Installation\",\"LangChain\",\"LLM\",\"mistral\",\"Ollama\",\"PDF\",\"Python\",\"RAG\",\"StableLM\",\"Streamlit\",\"text splitting\",\"user interface\",\"vector db\",\"video course\",\"virtual environment\"],\"articleSection\":[\"Large Language Models\",\"Top story\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/\",\"url\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/\",\"name\":\"RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ai-box.eu\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/RAG_Chat_app_architecture.png\",\"datePublished\":\"2024-02-11T05:40:06+00:00\",\"dateModified\":\"2024-03-09T05:02:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/#\\\/schema\\\/person\\\/cc91d08618b3feeef6926591b465eab1\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ai-box.eu\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/RAG_Chat_app_architecture.png\",\"contentUrl\":\"https:\\\/\\\/ai-box.eu\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/RAG_Chat_app_architecture.png\",\"width\":1611,\"height\":851,\"caption\":\"RAG Chat-PDF app architecture\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/top-story-en\\\/rag-chat-applikation-langchain-ollama-streamlit\\\/1295\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Start\",\"item\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RAG Chat-Applikation &#8211; Langchain + Ollama + Streamlit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/\",\"name\":\"Exploring the Future: Inside the AI Box\",\"description\":\"Inside the AI Box, we share our experiences and discoveries in the world of artificial intelligence.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/#\\\/schema\\\/person\\\/cc91d08618b3feeef6926591b465eab1\",\"name\":\"Maker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g\",\"caption\":\"Maker\"},\"description\":\"I live in Bavaria near Munich. In my head I always have many topics and try out especially in the field of Internet new media much in my spare time. I write on the blog because it makes me fun to report about the things that inspire me. I am happy about every comment, about suggestion and very about questions.\",\"sameAs\":[\"https:\\\/\\\/ai-box.eu\"],\"url\":\"https:\\\/\\\/ai-box.eu\\\/en\\\/author\\\/ingmars\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box","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:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/","og_locale":"en_US","og_type":"article","og_title":"RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box","og_description":"In terms of technical requirements and architecture, this solution is not very complex and is therefore ideal for getting started with large language models. It is also guaranteed to give you an initial sense of achievement very quickly. All the components used can be easily installed and combined with each other. I have followed the [&hellip;]","og_url":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/","og_site_name":"Exploring the Future: Inside the AI Box","article_published_time":"2024-02-11T05:40:06+00:00","article_modified_time":"2024-03-09T05:02:00+00:00","og_image":[{"width":1611,"height":851,"url":"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png","type":"image\/png"}],"author":"Maker","twitter_card":"summary_large_image","twitter_creator":"@Ingmar_Stapel","twitter_site":"@Ingmar_Stapel","twitter_misc":{"Written by":"Maker","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#article","isPartOf":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/"},"author":{"name":"Maker","@id":"https:\/\/ai-box.eu\/en\/#\/schema\/person\/cc91d08618b3feeef6926591b465eab1"},"headline":"RAG Chat-Applikation &#8211; Langchain + Ollama + Streamlit","datePublished":"2024-02-11T05:40:06+00:00","dateModified":"2024-03-09T05:02:00+00:00","mainEntityOfPage":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/"},"wordCount":1482,"commentCount":0,"image":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#primaryimage"},"thumbnailUrl":"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png","keywords":["advanced QA","Anaconda","architecture","ChatPDF","ChunkViz","embeddings","error messages","hierarchical contextual augmentation","HiQA framework","Installation","LangChain","LLM","mistral","Ollama","PDF","Python","RAG","StableLM","Streamlit","text splitting","user interface","vector db","video course","virtual environment"],"articleSection":["Large Language Models","Top story"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/","url":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/","name":"RAG Chat-Applikation - Langchain + Ollama + Streamlit - Exploring the Future: Inside the AI Box","isPartOf":{"@id":"https:\/\/ai-box.eu\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#primaryimage"},"image":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#primaryimage"},"thumbnailUrl":"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png","datePublished":"2024-02-11T05:40:06+00:00","dateModified":"2024-03-09T05:02:00+00:00","author":{"@id":"https:\/\/ai-box.eu\/en\/#\/schema\/person\/cc91d08618b3feeef6926591b465eab1"},"breadcrumb":{"@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#primaryimage","url":"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png","contentUrl":"https:\/\/ai-box.eu\/wp-content\/uploads\/2024\/02\/RAG_Chat_app_architecture.png","width":1611,"height":851,"caption":"RAG Chat-PDF app architecture"},{"@type":"BreadcrumbList","@id":"https:\/\/ai-box.eu\/en\/top-story-en\/rag-chat-applikation-langchain-ollama-streamlit\/1295\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Start","item":"https:\/\/ai-box.eu\/en\/"},{"@type":"ListItem","position":2,"name":"RAG Chat-Applikation &#8211; Langchain + Ollama + Streamlit"}]},{"@type":"WebSite","@id":"https:\/\/ai-box.eu\/en\/#website","url":"https:\/\/ai-box.eu\/en\/","name":"Exploring the Future: Inside the AI Box","description":"Inside the AI Box, we share our experiences and discoveries in the world of artificial intelligence.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ai-box.eu\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ai-box.eu\/en\/#\/schema\/person\/cc91d08618b3feeef6926591b465eab1","name":"Maker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e96b93fc3c7e50c1f21c5c6b1f146dc4867936141360830b328947b32cacf93a?s=96&d=mm&r=g","caption":"Maker"},"description":"I live in Bavaria near Munich. In my head I always have many topics and try out especially in the field of Internet new media much in my spare time. I write on the blog because it makes me fun to report about the things that inspire me. I am happy about every comment, about suggestion and very about questions.","sameAs":["https:\/\/ai-box.eu"],"url":"https:\/\/ai-box.eu\/en\/author\/ingmars\/"}]}},"_links":{"self":[{"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/posts\/1295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/comments?post=1295"}],"version-history":[{"count":1,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/posts\/1295\/revisions"}],"predecessor-version":[{"id":1296,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/posts\/1295\/revisions\/1296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/media\/1209"}],"wp:attachment":[{"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/media?parent=1295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/categories?post=1295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai-box.eu\/en\/wp-json\/wp\/v2\/tags?post=1295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}