Beyond Basic LLM Applications: Getting Started With Redis and LangChain

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to have a closer look at how you use Lang chain with redis I'm first going to make a case for why you want to consider redis as a backend for your llm application then I'm going to show you how you use slang chain with the cloud hosted version of redis which is hosted on reddit.com I'll create indexes and show how to retrieve the data using the python Library radius pi and quickly dive into How Lane chain stores this data under the hood so why red is well first of all redis is one of the most popular databases in the world it ranks just below mongodb and the big SQL databases in terms of popularity go to any ranking and you'll see red is near the top of the list like this ranking on DB engines.com and as you know companies love to keep the tech stack lean and use the same tools for multiple tasks so this is already reason enough to consider redis for your next project but that's actually an even better reason to consider redis and it has to do with the way redis is being used in companies around the world redis is the most popular database when it comes to feeding machine learning models in production with real-time data and the way it often works is that you have a web client that needs some information generated by a machine learning model for the model to be able to provide an answer it needs to fetch features which is the data that goes into the model and to do that in a reasonable time frame the model needs to be fed data from a so-called online store and where this is the most popular choice for this so what does this have to do with Lang chain while Lang chain integrates with Feast a system widely used to generate the feature data and those same features can be used to inject important contexts into prompt templates so we can actually use redis both for Vector storage and for holding information that is needed to personalize a language model's interaction with a customer in the coming videos I'm going to walk you through how this works and how this can be utilized for online businesses so hit subscribe if you want to follow along as for this video I'm going to share the code and the data used below this video to get you started with link chain and radius as quickly as possible let's go so if you go to redis.com you can sign up for a free account and once you sign up or sign in you can set up a new subscription and here I'm just going to choose the free tier and then I'm going to set up a subscription on AWS and then I'm going to give it a name I'm going to call it Lane chain and then I just create the subscription once we have the subscription we're going to set up a new database and here we're going to choose ready stack that includes all the redis modules that we need and then we choose a database name I'm going to call this one analytics and then we activate the database once the database is set up and you can see that by the icon next analytics turning green we can go in and fetch the endpoint that we need to connect to the database so go to public endpoint and then you click connect and here we can get the URL that we need to connect length chain to this redis database so I'm just going to click copy and then we can use this URL in a notebook so besides slang chain we're also going to be using redis pi that allows us to connect to the redis database using python and installing this is simply pip install radius and of course we're also going to be using link chain and to install the latest version of link chain simply write pip install line chain so let's paste the URL that we copied from radish Cloud into a notebook and you can see that the URL actually consists of three parts a host a password and a port to connect to redis through link chain we're going to use the full URL with all three parts but to connect to redis through redis Pi without bank chain we need the host and the password and the port separately so let me start by connecting through redis pi to do that we import redis and then we pass the host port and password as arguments to the instance and here I called the instance R and then we can ping it to see if we have a connection and you can use r dot keys to see what's stored in the redis database and here it's obviously empty so now I'm going to load some data into the database and I'm going to be using the same data we've been using before which is the Amazon review data set and here I'm going to extract the data for one particular product which is the Pinnacle orthotic shoe insoles and I'm going to fetch the ID I'm going to fetch the overall rating I'm going to fetch these review text and the summary of the review text the headline so if we want to load this into radius using radius as a vector database we're going to need embeddings so I'm going to import hacking face embeddings and use those embeddings to to store the data and to use the Hawking face embeddings you need to hip install the sentence Transformer Library I'm going to check the data from the data frame and transform it into a format that we can load into the database and in particular I need all the review texts in a list and I need all the summaries in the list and I'm going to create a list of metadatas that contains all the ratings for each individual review and I don't need the reviews vectors or summary vectors just yet we'll need it later and to let this into redis from line chain it's the same syntax as always we use the from texts method and load in the texts we need the embeddings and in this case we also need the URL and once we've loaded the vectors we can do r dot keys and we can see that now we have data in the database so if you want to see the indexes that have been created you can use r.execute command and then execute FC dot underscore list and this will give you a list of the indexes in this database language stores the data and radius as hashes so if we want to fetch all the fields of a particular key we can use R.H keys and then the key and here we see we have metadata we have a Content vector and we have content and we can also fetch just a particular field by using Edge get and then adding the field name the constant Vector is stored as bytes so it's going to be unreadable and if you want to read the constant Vector we're going to need to decode it and you can use numpy from buffer to do that choosing D type float32 and here we have the decoded content vector if we dive into the redist.pi component of line chain you can see how the data is being stored as hashes using a redis pipeline we'll get more into that in later videos all right that's it for now if you enjoyed this video like And subscribe thanks for watching
Info
Channel: Rabbitmetrics
Views: 4,400
Rating: undefined out of 5
Keywords: langchain, langchain chatgpt, langchain own data, gpt 4, langchain openai, large language models, pinecone, hugging face models, llm explained, langchain in python, langchain ai, langchain prompt, langchain agent, embeddings, vectore store, langchain tutorial, marketing analytics, lemlist, personalization, redis, feast feature store
Id: MXhfLUoIRno
Channel Id: undefined
Length: 8min 3sec (483 seconds)
Published: Mon Aug 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.