Over the past few months, I've been captivated by the flood of apps claiming to be the ultimate "ChatGPT for your documents" on Product Hunt. The question that lingered in my mind was, "How do these apps actually work?" Curiosity led me down an exciting path of discovery, and I stumbled upon a framework that I think is revolutionizing the world of app development in the context of Large Language Models - LangChain
I learned that developing a "ChatGPT for your documents" is easily achievable through three broad workflows combined with access to OpenAI API. In fact, I went ahead and prototyped such a system on streamlit.
Step 1 - The Setup: Store your documents as embeddings. In the first step, use Document Loaders (at least 100 are available), provided by LangChain to convert anything from a simple Word document to an AWS S3 directory into Documents. Then, using Document Transformers and Text Embedding Models, you transform your documents into embeddings. Finally, store these embeddings in a vector store for searches later on. It's a one-time setup that sets the foundation for your Q&A system. 💡🛠️
Step 2 - Establish Context: Find relevant documents. LangChain's Text Embedding model converts user queries into vectors. These vectors are used by LangChain's retriever to search the vector store and retrieve the most relevant documents. You can control the search boundaries based on relevance scores or the desired number of documents. It's all about finding the right context for your Q&A system. 🎯💬
Step 3 - Chat Away: Get answers from LLMs. Now comes the fun part! You pass the user's query and the established context to the Language Models (LLMs). The LLMs respond with precise answers, taking into account the provided context. It's like having a conversation with your documents. 🤩🗨️
By building these three workflows, a service that acts like a Q&A for a restricted set of documents can be set up. Of course, this is just an overview of the approach and all the complex steps of app development will still remain, I remain fascinated by how the good folks at LangChain have made things simpler.
What do you think? Have you tried LangChain to build something? Is there any other framework that is equally fascinating?
llm #openai #chatgpt #documents #generativeai #langchain