[!NOTE]
This project is a Community Project.The project is maintained and supported by the community. Upstash may contribute but does not officially support or assume responsibility for it.
DegreeGuru is a project designed to teach you making your own AI RAG chatbot on any custom data. Some of our favorite features:
This chatbot is trained on data from Stanford University as an example, but is totally domain agnostic. We've created this project so you can turn it into a chatbot with your very own data by simply modifying the crawler.yaml
file.
For local development, we recommend forking this project and cloning the forked repository to your local machine by running the following command:
git clone git@github.com:[YOUR_GITHUB_ACCOUNT]/DegreeGuru.git
This project contains two primary components: the crawler and the chatbot. First, we'll take a look at how the crawler extracts information from any website you point it to. This data is automatically stored in an Upstash Vector database. If you already have a vector database available, the crawling stage can be skipped.
The crawler is developed using Python, by initializing a Scrapy project and implementing a custom spider. The spider is equipped with the parse_page
function, invoked each time the spider visits a webpage. This callback function splits the text on the webpage into chunks, generates vector embeddings for each chunk, and upserts those vectors into your Upstash Vector Database. Each vector stored in our database includes the original text and website URL as metadata.
To run the crawler, follow these steps:
[!TIP] If you have docker installed, you can skip the "Configure Environment Variables" and "Install Required Python Libraries" sections. Instead you can simply update the environment variables in docker-compose.yml and run
docker-compose up
. This will create a container running our crawler. Don't forget to configure the crawler as explained in the following sections!
After setting these environment variables, we are almost ready to run the crawler. The subsequent step involves configuring the crawler itself, primarily accomplished through the crawler.yaml
file located in the degreegurucrawler/utils
directory. Additionally, it is imperative to address a crucial setting within the settings.py
file.
That's it! š We've configured our crawler and are ready to run it using the following command:
scrapy crawl configurable --logfile degreegurucrawl.log
Note that running this might take time. You can monitor the progress by looking at the log file degreegurucrawl.log
or the metrics of your Upstash Vector Database dashboard as shown below.
[!TIP] If you want to do a dry run (without creating embeddings or a vector database), simply comment out the line where we pass the
callback
parameter to theRule
object inConfigurableSpider
In this section, we'll explore how to chat with the data we've just crawled and stored in our vector database. Here's an overview of what this will look like architecturally:
Before we can run the chatbot locally, we need to set the environment variables as shown in the .env.local.example
file. Rename this file and remove the .example
ending, leaving us with .env.local
.
Your .env.local
file should look like this:
# Redis tokens retrieved here: https://console.upstash.com/
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
# Vector database tokens retrieved here: https://console.upstash.com/vector
UPSTASH_VECTOR_REST_URL=
UPSTASH_VECTOR_REST_TOKEN=
# OpenAI key retrieved here: https://platform.openai.com/api-keys
OPENAI_API_KEY=
The first four variables are provided by Upstash, you can visit the commented links for the place to retrieve these tokens. You can find the vector database tokens here:
The UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
are needed for rate-limiting based on IP address. In order to get these secrets, go to Upstash dashboard and create a Redis database.
Finally, set the OPENAI_API_KEY
environment variable you can get here which allows us to vectorize user queries and generate responses.
That's the setup done! š We've configured our crawler, set up all neccessary environment variables are after running npm install
to install all local packages needed to run the app, we can start our chatbot using the command:
npm run dev
Visit http://localhost:3000
to see your chatbot live in action!
You can use this chatbot in two different modes:
To customize the chatbot further, you can update the AGENT_SYSTEM_TEMPLATE in your route.tsx file to better match your specific use case.
Congratulations on setting up your own AI chatbot! We hope you learned a lot by following along and seeing how the different parts of this app, namely the crawler, vector database, and LLM, play together. A major focus in developing this project was on its user-friendly design and adaptable settings to make this project perfect for your use case.
The above implementation works great for a variety of use cases. There are a few limitations I'd like to mention:
UpstashVectorStore
used with LangChain currently only implements the similaritySearchVectorWithScore
method needed for our agent. Once we're done developing our native LangChain integration, we'll update this project accordingly.