skip to content
Avatar Bruno Garcia

Research about LangChain and the Titanic SQLite database

The main goal of this project is to research about the LangChain library and the API of OpenAI using the Titanic SQLite database.

How is it working?

  • First, the API of OpenAI allows me to use the GPT-3 model at a very cheap price. The total cost of the research was 💵 $0.36.
  • Then, the LangChain library allows me to connect the OpenAI API and the Titanic Database in a very simple way.
  • Finally, Next.js let me create a simple web application that allows the final user to interact with the database in a natural language.
How is it work?

Database

The table is called titanic and has the following columns.

🥳 Amazing: even the this table was created using natural language:

“Give the column name, data type and description of the table titanic in markdown format”

Column NameData TypeDescription
PassengerIdTEXTUnique identifier for each passenger
SurvivedTEXTWhether the passenger survived or not
PclassTEXTPassenger class
NameTEXTPassenger name
SexTEXTPassenger gender
AgeTEXTPassenger age
SibSpTEXTNumber of siblings/spouses aboard
ParchTEXTNumber of parents/children aboard
TicketTEXTTicket number
FareTEXTTicket fare
CabinTEXTCabin number
EmbarkedTEXTPort of embarkation

Answering the questions with natural language

The app and the notebook are able to answer the following questions in natural language:

  1. How many passengers survived?
  2. How many passengers were in each class?
  3. How many passengers survived/died within each class?
  4. What was the average age of survivors vs non-survivors?
  5. What was the average age of each passenger class?
  6. What was the average fare by passenger class? By survival?
  7. How many siblings/spouses aboard on average, by passenger class? By survival?
  8. How many parents/children aboard on average, by passenger class? By survival?

Example #1: How many passengers survived?

342 passengers survived.

Example #2: How many passengers were in each class?

There were 216 passengers in first class, 184 passengers in second class, and 491 passengers in
third class.

Github

Check out the source code on Github.