visit
Previous Piece —
In this example, I will use Langchain (which raised $10M at a $100M valuation) to access open AI’s API.
As a Product Manager at Azure Files, the most important information I would like to interact with is the publicly available . I downloaded this in the form of a PDF for this exercise. If you are following along download whatever information you want to build your chatbot on in the form of one or more PDFs. You can also use other formats but I will be sticking to PDF format in this example.
The process in which we will build this chatbot is often referred to as retrieval augmented generation (RAG). The following image explains the different steps involved in creating the chatbot that will help me do my job better and faster.
Let’s write the code to create our chatbot. I am using Langchain along with OpenAI to create the chatbot. You would need an OpenAI secret key and IDE of your choice to follow along. I am using VS Code and a virtual Python environment.
An embedding vector of a text block captures the context/meaning of the text. Texts that have similar meanings/contexts will have similar vectors. To convert the splits into their embedding vector versions we use OpenAIEmbeddings. A special type of database is required to store these embeddings, known as a vector database. In our example, we will chrome it since it can be stored in memory. After storing embedding for my splits in the chroma vector db I also persist it to reuse in the next steps.
We have stored our embedding in the chroma db. In our chatbot experience when the user asks a question. We send that question to the vector db and retrieve data splits that might have the answer. Retrieving the right data splits is a huge and evolving subject. There are a lot of ways you can retrieve based on your application needs. I am using a common method of retrieval called Maximal Marginal Relevance (MMR). You can learn more techniques like basic semantic similarity, LLM-aided retrieval & more. I will write a separate post talking about MMR and others in a separate post. For this post consider retrieval as a process of getting the top 3 data chunks that could have the context/answer for the question that a user asked the chatbot. Once we retrieve the relevant chunks, we pass them to Open AI LLM and ask it to generate an answer by using the prompt. See my previous post about writing good prompts.
AI PRODUCT IDEA ALERT 1: All organizations would want to chat with your data applications and would also want their employees to create customer chats with your data applications based on their needs without writing any code. Microsoft and other companies are launching products and features to enable large organizations to do this via Azure OpenAI. But I think there will be startups competing for this space as well.
AI PRODUCT IDEA ALERT 2: Chat GPT for doctors. It won’t be trained on the internet, but instead on curated data that is from all relevant textbooks, recent research, and best practices as put forward by a respectable board, etc., I see immense value in a properly curated LLM tuned for doctors.
AI PRODUCT IDEA ALERT 3: Similar to idea 2. Think of LLMs fine-tuned for educational use cases. Where all the info is vetted and accurate. Moreso, I think other verticals need curated data sets instead of the whole internet.
I write a newsletter called Above Average where I talk about the second-order insights behind everything that is happening in big tech. If you are in tech and don’t want to be average, .
Follow me on , for latest updates on 100 days of AI. If you are in tech you might be interested in joining my community of tech professionals .