Ask questions about a PDF using AI
The workflow first populates a Pinecone index with vectors from a Bitcoin whitepaper. Then, it waits for a manual chat message. When received, the chat message is turned into a vector and compared to the vectors in Pinecone. The most similar vectors are retrieved and passed to OpenAI for generating a chat response.
Note that to use this template, you need to be on n8n version 1.19.4 or later.
Ask Questions About a PDF Using AI
This n8n workflow enables you to interact with PDF documents stored in Google Drive using AI. It allows you to upload a PDF, embed its content into a Pinecone vector store, and then ask questions about the PDF, receiving AI-generated answers based on the document's content.
What it does
This workflow automates the following steps:
- Triggers on chat message: Initiates the workflow when a chat message is received, allowing for user interaction to either upload a PDF or ask a question.
- Loads PDF from Google Drive: Retrieves a specified PDF file from Google Drive.
- Processes PDF content: Converts the binary PDF data into a readable document format.
- Splits document into chunks: Divides the document into smaller, manageable text chunks for efficient processing by the AI.
- Generates embeddings: Creates numerical representations (embeddings) of the text chunks using OpenAI's embedding model.
- Inserts into Pinecone Vector Store: Stores the generated embeddings and their corresponding text chunks into a Pinecone vector database.
- Loads Pinecone Vector Store: Retrieves relevant document chunks from Pinecone based on the user's query.
- Retrieves relevant information: Uses a Vector Store Retriever to find the most relevant document sections for the given question.
- Answers questions using OpenAI: Leverages an OpenAI Chat Model to generate an answer to the user's question based on the retrieved document content.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- Google Drive Account: To store your PDF documents.
- OpenAI API Key: For generating text embeddings and AI-powered answers.
- Pinecone Account: To create and manage your vector store for document embeddings.
Setup/Usage
- Import the workflow: Download the provided JSON and import it into your n8n instance.
- Configure Credentials:
- Google Drive: Set up a Google Drive credential to allow n8n to access your files.
- OpenAI: Configure an OpenAI credential with your API key.
- Pinecone: Set up a Pinecone credential with your API key and environment details.
- Adjust Node Parameters:
- Google Drive (Node 58): Specify the ID of the PDF file you want to process.
- Pinecone: Insert (Node 1211): Configure your Pinecone index name and namespace if applicable.
- Pinecone: Load (Node 1213): Configure your Pinecone index name and namespace, matching the insert node.
- Manual Chat Trigger (Node 1207): This node acts as the entry point for your chat interactions. You will need to interact with it manually or integrate it with a chat platform (e.g., Slack, Telegram) using another trigger node.
- Activate the workflow: Once configured, activate the workflow.
- Interact with the workflow:
- To upload and embed a new PDF, you would typically trigger the workflow with a specific command or input that leads to the Google Drive and Pinecone Insert path.
- To ask a question, trigger the
Manual Chat Triggernode with your question. The workflow will then retrieve relevant information from Pinecone and provide an AI-generated answer.
Related Templates
OpenAI assistant with custom tools
This workflow shows how you can get your OpenAI assistant to call an n8n workflow as a tool. Since you can put almost any functionality in an n8n workflow, this means you can give your assistant access to almost any data source. Note that to use this template, you need to be on n8n version 1.19.4 or later.
Send a message with an inline embedded image with Gmail
The built-in Gmail node doesn't yet support embedding images within the body of the email, but you can pull this off using the HTTP node, and this template shows you how. Requirements A Gmail account How it works The workflow downloads an image, converts it into the format that the Gmail API expects (base64), packages it into a multipart MIME email and uses the HTTP node to send it.
Access execution data from an error workflow
Sometimes you want to take a different action in your error workflow based on the data that was flowing through it. This template illustrates how you can do that (more specifically, how you can retrieve the data of a webhook node). How it works Use the 'n8n' node to fetch the data of the failed execution Parse that data to find webhook nodes and extract the data of the one that was executed