Query Your Data with GPT-4 | Embeddings, Vector Databases | Langchain JS Knowledgebase

StarMorph AI · Beginner ·🔍 RAG & Vector Search ·3y ago

Key Takeaways

The video demonstrates how to use Langchain JS to create embeddings and perform similarity searches over textual data, utilizing vector storage and databases such as Pinecone and Chroma, and integrating with GPT-4 for query-based data retrieval.

Full Transcript

hey everyone welcome to Star morph where we talk about artificial intelligence and web development today we are going to go into building your own knowledge base to bring your own data into Lane chain and use it with gpt4 so how do you bring in some of your specific data to interact with gpt4 as a lot of you probably saw in my last video we showed what this can do you know giving more specific answers to your content and in this presentation I'm going to go over some of the different pieces that are at play when you're building a knowledge base like this so there's an outline of the presentation we're going to go over embeddings Vector storage link chain documents so just an overview of the whole building a knowledge base so let's get started all right so first off what data do you want to bring into this app what data can you bring into this app these are some of the file loaders that are supported by lanechain and there's also web loaders so there's an ability to bring in Amazon S3 files you can bring in a GitHub repository you can do web scraping with things like Puppeteer or achiria and then you can also do these file loaders and so just a little bit about these I typically do a PDF file loader or I do text files or markdown documents and I've had those working really well I've had some issues with docx files and I believe the CSV file loader takes some configuration you have to identify what headers and rows and columns you want to use so the llm does well with with raw text especially structure tests if possible so that's what I've been doing so far but the way that I do it also is I may a directory there's also a directory loader and then I can um I can load in any PDF or text files in that directory that I put in into the embedding and into the next steps we're about to go to so once you identify what your file type is and what your data is going to look like then we can load our data into Lang chain into our lane chain application using um a document loader and creating a link chain document so you can see here we're importing and this is the JavaScript this whole presentation will be on JavaScript link chain we're importing the text loader from lanechain and then we are loading this text file here using the text loader so this is important because this concept of loading in a document is how we start to get access to work with our our data in the langchain application and another thing to consider here is we have some tools to help us parse the the text so we can do things like splitting and chunking the text when we're loading it into the documents and loading it into the embeddings and that's another tool that linkchain provides okay so once we have the document a next piece of the puzzle is creating and embedding so let's start out with what is an embedding and embedding is used as it says here to create a numerical representation of textual data so it's a vector of numbers lots of vectors of numbers and each number the closer a number is to another one the CL the more similar they are the distance between the numbers signifies how similar different uh parts of the embedding are so let's just zoom out here a little bit and this is actually a visualization of what we're going to be doing with these embeddings so we're going to create the embedding these vectors with numbers representing our document and then what we're going to do is we're going to perform a similarity search over the embedding and we're also going to talk more about Vector storage and creating a database for these embeddings that we'll also use in this process of doing similarity search so this is a cool visualization of what we're actually trying to do here we're loading in our source document whether it's a text file or a PDF file then we're creating this Vector structure to organize the information with numbers and then we're able to perform this kind of similarity search now that it's in this embedding format and and this is also a format that we're able to send over to open Ai and interact with gpg4 with the embedding okay so that's a little bit about what embeddings are it's just the list of numbers that tells you about your Source document context and there's a great website um there's a lot of great websites that talk about this one of the pages I usually go to is just the open AI Pages page about embeddings and so this is a great resource to learn more about what they are measuring the related of text strings and then we can do search as well as some other features here okay so let's talk about creating and embedding inline chain how do you use them so we can import the openai embedding section of the library and this also is available in the open AI API directly which this page will go into and there's two kinds of embeddings that we can do with langchain the first is embedding the query so you can think when you're using a chat bot the actual prompt that the user is typing into the bot we can embed that search and then we can also embed on the other side the actual document like we were just talking about bringing in the document loader and embedding the document and then you can I believe use the query embedding in reference to the document embedding and um yeah so there's two forms of embeddings that we can do here both the query and the document and that's from the lane chain documentation okay so now we have an embedding of our document we are able to create an embedding of our query let's talk about managing these embeddings and that's where we get into Vector storage and this is a very exciting area right now um these companies are there's some amazing technology coming out chroma just raised around weevia just raised their series B link chain just raced around Super Bass just built a vector database plug-in which I'll talk more about so lots of really exciting stuff happening here congratulations to these companies and I'm really excited for all of the tools that I imagine are going to come out of this and I think that it's a great time to jump into this stuff and start learning while these tools are early on and before they get more advanced might as well learn the fundamentals now so we can understand uh how to continue using them as they develop so all right this is a lot here Vector storage it sounds kind of crazy if you want to just get started into it where's a good place to start so my thoughts on this are there two main things to consider the first is what environment are you going to be coding in because some of these uh are going to work better with Docker some will work in a node.js app some can work in the browser serverless so consider what environment you're going to be coding in and then the second thing is what scale are you building a vector storage at so if you want a production level SAS where you want a hosted service at scale then you know something like pine cone could be a great option if you want to have a small file in your GitHub repo I think a great way to get started is using this hnsw lib tool that comes with link chain and it will create your embeddings and then store them into a file that will be local in your GitHub repo you don't need to sign up for a cloud service and you know manage having a remote and a local Vector storage it's just a super simple file so I think this is a great way to get started there's a page on the lane chain documentation about the differences between each of these so if we go to Vector stores here link chain recommends what to pick and similar to what I was just saying they talk about the different environments so for a node application they recommend hnsw browser like some maybe serverless on verscell you can use the link chain memory Vector store which I I want to play with I haven't used that one yet there's also a lot of python options uh in the python documentation if you are running it locally with Docker your backend developer or then you can use chroma and then Super Bass just launched a they just launched a package manager for database packages so like npm but for database packages and there's one now that is a vector store I believe integrated with Lane chain so I'm definitely looking forward to trying that out stupid bass just had an awesome launch week coming out with a ton of new cool stuff and I really love using supervis um so that's a brief overview of you know some of the differences between these um it's great trying out different ones and seeing the different functionalities for getting started again I would recommend starting with this has been a good experience for me and then Pinecone at a larger scale but I definitely want to play with all these tools more so I hope that's helpful on a little overview of some of the options here and moving into how do we kind of start to use all this together and uh so this code snippet here I apologize it's a little blurry is coming from the Lang chain documentation and so we're doing a few of the steps here first we load in our text document we create a lane chain document from it then from this document or then we are loading it into the vector store both the document and creating a new embedding with openai and loading that into the vector store as well and then we can do a vector store.similarity search so this is where all the pieces are starting to come together we're loading our data in creating the document creating the embedding storing that in the vector storage and so that brings us to the second to last slide which is kind of looking at this from a macro view so there's act there are definitely other pieces of this as well where you know the llm comes in but just about what we've talked about so far this is a basic overview you can bring your data in whether it's from a file or from the web you can create a lane chain document with their loader then you can use openai's API to create an embedding and then when the user searches they'll create an embedding of the search and then we can store these embeddings as well as the document in the vector database so that's kind of uh architecture this is my current best understanding of what's Happening behind the scenes uh this is all changing very quickly so definitely check the link chain documentation is going to be more up to date and I will continue to uh you know learn and get better at this and share better information as I learn what's happening here but this is my current best understanding of how some of these knowledge bases are working so I hope this is a helpful overview and in terms of learning learning more about this stuff these are some of the YouTube channels and communities that I've been learning from and I'm sure you guys have seen a lot of these channels already they're giving great content on Lane chain on building knowledge bases working with large language models um of just reading the docs is honestly just sitting down and reading the docs is super valuable and these guys you know are updating it every single day and every single week on Twitter it's just new stuff so very exciting space and I know a lot of businesses are interested in doing this because it's pretty amazing to be able to bring in you know these tools to your custom data there's a lot of different applications for it whether it's a question and answer bot or producing assets for your business um or reading large documents that you don't have time to read a 400 page document but you want to ask it a few questions so I hope this is a helpful overview of some of how this stuff is working with langchain and I know I imagine you guys want to see some coding on this too we have some Snippets here from the docs but I would love to make a future video I'm still working on this where we're going to kind of build out this um build up this code and add the pieces together in an app um because I know you guys want to do that as well so this is stepping towards that and I hope this video was helpful thank you very much for watching please be sure to like And subscribe if you found this video helpful and I'll see you guys in the next video

Original Description

Introduction to Langchain Javascript Embeddings, Vectorstorage, Similarity Search. How to Create GPT-3 GPT-4 Chatbots that can contextually reference your data (txt, JSON, webpages, PDF) with embeddings. Discussion into embeddings, vectorstorage options such as Pinecone, Chroma, Langchain, Supabase, Weaviate. Intro Call https://cal.com/starmorphai/intro-call 1 hr consulting https://cal.com/starmorphai/consultingcall 🌐 Our Official Website: https://starmorph.com Langchain Resources Langchain JS Docs: https://js.langchain.com/docs/ OpenAI Embeddings Docs: https://platform.openai.com/docs/guides/embeddings/use-cases
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

This video teaches how to use Langchain JS to create embeddings and perform similarity searches over textual data, and how to integrate with GPT-4 for query-based data retrieval. The lesson covers the basics of retrieval augmented generation, vector storage, and knowledge bases, and provides practical examples of how to utilize these technologies.

Key Takeaways
  1. Load data into Langchain application using document loader and creating a link chain document
  2. Create an embedding as a numerical representation of textual data
  3. Perform similarity search over the embedding
  4. Use Vector storage and a database for the embeddings
  5. Choose a suitable vector store for your environment
  6. Integrate rag search with GPT-4 for query-based data retrieval
💡 The use of embeddings and vector databases enables efficient and effective query-based data retrieval, and can be integrated with large language models like GPT-4 for powerful applications.

Related Reads

📰
Optimizing RAG at Scale: Chunking, Retrieval, and the Bayesian Search That Cut Latency 40%
Optimize RAG at scale using chunking, retrieval, and Bayesian search to reduce latency by 40% and achieve 95% recall@10
Dev.to AI
📰
Optimizing RAG at Scale: Chunking, Retrieval, and the Bayesian Search That Cut Latency 40%
Learn how to optimize RAG at scale using chunking, retrieval, and Bayesian search to reduce latency by 40%
Dev.to · Imus
📰
Optimizing RAG at Scale: Chunking, Retrieval, and the Bayesian Search That Cut Latency 40%
Learn how to optimize RAG at scale by implementing chunking, retrieval, and Bayesian search to reduce latency by 40% and achieve 95% recall@10
Dev.to AI
📰
Optimizing RAG at Scale: Chunking, Retrieval, and the Bayesian Search That Cut Latency 40%
Learn how to optimize RAG at scale by implementing chunking, retrieval, and Bayesian search to reduce latency by 40%
Dev.to AI
Up next
Build a Chatbot with RAG in 10 minutes | Python, LangChain, OpenAI
Thomas Janssen
Watch →