DEV Community

Cover image for Building a PDF Chatbot with RAG using SQL
Mrunmay Shelar for LangDB

Posted on • Edited on

7

Building a PDF Chatbot with RAG using SQL

In the realm of AI chatbot development, there are many ways to create a PDF chatbot using Retrieval Augmented Generation. There are tools like LangChain and LlamaIndex, which are the popular choice. However, in this post, we’ll be exploring how you can achieve this using SQL.

Let’s go over the general steps of building a RAG chatbot:

  1. Loading and Extracting PDF
  2. Generating and Storing Vector Embeddings
  3. Retrieving relevant information using Vector Search
  4. Generating and Returning Answer

Why SQL?

  • SQL queries are straightforward and efficient, making data manipulation and retrieval easier on large datasets.
  • Combining structured and unstructured data is accessible on the go.
  • Streamlines the development process by enabling the creation of workflows with minimal code.

Here are a few examples of how easily you can create embeddings, create a prompt for the LLM and finally create a model.

-- Embeddings Model 
CREATE EMBEDDING MODEL IF NOT EXISTS generate_embed(
input COMMENT 'This is the input of the content whose embeddings are created'
) USING open_ai_provider(embedding_model='text-embedding-ada-002', encoding_format='float', dimensions=100)

-- Completions Model
CREATE MODEL IF NOT EXISTS search(
  input
) USING open_ai_provider()
PROMPT (system "You are a helpful assistant. You have been provided with similar tool to search over the SEC fillings. 
                 Your task is also to help users with any queries they might have about the SEC filings. 
                 Go through all the content and then respond.",
  human "{{input}}")
TOOLS (similar)
SETTINGS retries = 1;
Enter fullscreen mode Exit fullscreen mode

Using SQL in this manner provides a robust framework for building a PDF chatbot, leveraging the power of SQL for workflow management.
So, the final execution of the model will look like this:

Gif showing how to query a model in LangDB

You can follow the full tutorial here: https://app.langdb.ai/samples/preview?file_name=QA%20on%20PDF%20%26%20RAG%20using%20LangDB

Join our Slack community for more discussions and support: https://join.slack.com/t/langdbcommunity/shared_invite/zt-2haf5kj6a-d7NX6TFJUPX45w~Ag4dzlg

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay