ClickCease
Decorative

Add a Vector Database to your GPT Custom Content Bot that uses LlamaIndex and LangChain

Italo Orihuela
Engineer
Android
iOS
Web
Aug 28, 2023

In the previous tutorial regarding GPT, step-by-step guide to using LlamaIndex, GitHub Repository Loader and LangChain to create Custom Based Content Bot that can connect to a Chat SDK, we developed the basic structure for getting the content from a Github Repository Loader and then using LangChain to build the prompt that was going to be used for the query.

Now we will add a vector database to it, specifically through the use of Pinecone. This will help make a more efficient and accurate query considering the custom dataset. Then continuing with the flow of the previous tutorial, you can connect it to a chat SDK.

Pre-requisites

  • Python 3.11
  • OpenAI API Key
  • Pinecone API Key

If you followed the previous tutorial, then this time you will need to create a Pinecone free account in order to obtain the API Key.

LlamaIndex using LangChain and Pinecone VD for Index Construction and Storage

Continuing from the previous blog, we can place ourselves on the part of build and store index. Once you have you Pinecone API Key, you can place it on your <span id="greylight" class="greylight">env.</span> file and then add the following code. Please do not forget to specify the server region where is mentioned.

As you can see, there is a part of the code that will generate the new index name that you have defined, so you can query it next time. Once you already have the index created in Pinecone, the function after the “else” will take place and get the index.

Query the Index

After adding Pinecone, you can run the query file as you did before in the previous tutorial:

Now you only need to add your question and run it!

Integrating with a Chat SDK

Now, as mentioned before, having a bot makes more sense if you use it through a channel that will allow your users to have quick and easy access to it. Hence, we recommend you use a provider that has the option of Webhook events. In this case, by using Amity Chat SDK, you can get real-time events through Webhooks, so that you can develop a script to detect that particular event that will call the channel of your bot’s name so that it will trigger your bot’s logic. In our next GPT tutorial, we will discuss more about this part and will show you how it works. In the meantime, if you want to know more about Amity and test it: contact sales.