NLP / Python · June 30, 2024

Unlock PostgreSQL Data with LlamaIndex

Imagine querying your PostgreSQL database with plain English sentences. No more complex SQL syntax! LlamaIndex bridges the gap between human language and your relational database, empowering you to interact with data in a more intuitive way. This blog post dives into connecting LlamaIndex with PostgreSQL and querying it using plain English.

Prerequisites

  • Python
  • PostgreSQL Database

Setup

  • Download the data from below URL and store it under employees_database and employee schema. Here its not mandatory to store the database with given name and schema. You can use any other name and ignore schema as well. In this case make sure to change database name and schema name in the provided code.
  • https://github.com/h8/employees-database

Complete Code

  • In the provided code, definitely prompt engineering will be required to get correct answers. Here the idea is to make you aware about how to use LlamaIndex with PostgreSQL and not about how to do hyper parameters tuning or prompt engineering to get the correct answers.
  • Also, in the given code the only correct answer I have got is for the Question: Provide separate count of male and female employees. under the section of When we know which table to query?
    • For all other questions the respective answers are incorrect.
  • Below is the complete jupyter notebook code showing complete implementation.
LlamaIndex_LLM_With_Postgres