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.

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 Name | Data Type | Description |
---|---|---|
PassengerId | TEXT | Unique identifier for each passenger |
Survived | TEXT | Whether the passenger survived or not |
Pclass | TEXT | Passenger class |
Name | TEXT | Passenger name |
Sex | TEXT | Passenger gender |
Age | TEXT | Passenger age |
SibSp | TEXT | Number of siblings/spouses aboard |
Parch | TEXT | Number of parents/children aboard |
Ticket | TEXT | Ticket number |
Fare | TEXT | Ticket fare |
Cabin | TEXT | Cabin number |
Embarked | TEXT | Port of embarkation |
Answering the questions with natural language
The app and the notebook are able to answer the following questions in natural language:
- How many passengers survived?
- How many passengers were in each class?
- How many passengers survived/died within each class?
- What was the average age of survivors vs non-survivors?
- What was the average age of each passenger class?
- What was the average fare by passenger class? By survival?
- How many siblings/spouses aboard on average, by passenger class? By survival?
- 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.