Document Q&A API Endpoint with PDF Vector RAG - n8n Workflow

Build a lightning-fast REST API for document Q&A using the PDF Vector n8n node. This production-ready n8n workflow processes documents and returns AI-generated answers with citations and confidence scores.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • AI developers and backend engineers needing a custom RAG (Retrieval-Augmented Generation) microservice.

  • System integrators building high-performance APIs with n8n.

  • Users looking to leverage the PDF Vector n8n node for contextual document querying.

  • Those seeking advanced n8n templates for custom web services.

Overview

This specialized n8n workflow transforms a simple document processing request into a sophisticated, context-aware API service. It addresses the challenge of providing instant, verifiable answers based on a specific document's content, such as PDFs or web articles. By utilizing the powerful PDF Vector n8n node, the workflow efficiently parses, vectors, and queries the provided document, mimicking the logic of a custom knowledge base. The architecture is designed for reliability, starting with a robust validation step and ending with a standardized JSON response, ensuring this n8n template is production-ready. This entire process is orchestrated by n8n, demonstrating its capability far beyond simple task automation, allowing users to rapidly deploy AI-powered web services.

How it Works

The entire process is initiated by an external API call using the Webhook n8n trigger. This n8n workflow operates in a clear, linear fashion:


  1. API Trigger: The process begins when the Webhook n8n trigger receives a POST request at the configured /doc-qa endpoint. The request must contain a document URL and the user's question.

  2. Request Validation: The first Code n8n node, 'Validate Request,' analyzes the incoming JSON body. It ensures the question and a document identifier (documentUrl or documentId) are present, generating a unique sessionId and setting a valid boolean flag.

  3. Conditional Check: The 'Valid Request?' If n8n node branches the execution. If the request is invalid, the flow proceeds to 'Format Error Response.'

  4. AI Processing (Success Path): If valid, the flow hits the 'PDF Vector - Ask Question' n8n node. This critical step uses the document URL and the user's prompt to perform RAG, extracting the most relevant contextual answer.

  5. Format Success Response: A subsequent Code n8n node takes the answer generated by PDF Vector, calculates a simulated confidence score, and structures the final rich JSON output, including processing metadata and the session ID.

  6. Error Handling (Failure Path): If the request validation fails, the 'Format Error Response' Code n8n node compiles the validation errors into a clean, structured error JSON.

  7. Final Output: Both the success and error paths converge into the 'Send Response' n8n node (Respond to Webhook), which immediately sends the appropriate JSON data back to the originating client, completing the API request cycle.

Installation Guide

To deploy this comprehensive n8n workflow template, follow these steps:


  1. Import: Copy the entire JSON code provided and import it directly into your n8n instance using the 'New' menu and selecting 'Import from JSON'.

  2. Credentials Setup: The 'PDF Vector - Ask Question' n8n node requires credentials (usually an API key for the underlying AI service like OpenAI or similar vector services). Ensure these are securely configured.

  3. Webhook Activation: The 'Webhook' n8n trigger is set to respond to POST requests on the path /doc-qa. After saving the n8n workflow, ensure it is activated (toggle the switch in the top right).

  4. Testing: Test the API by sending a POST request to your n8n instance's webhook URL, including the mandatory documentUrl and question parameters in the JSON body.

Node Details

Webhook (n8n trigger): Named 'Webhook'. Serves as the API entry point, configured for a POST method at the /doc-qa path. It listens for external document Q&A requests.
Code (n8n node): Named 'Validate Request'. Performs input sanitation, checking for required parameters (documentUrl and question) and setting a boolean flag for validity. It is crucial for stabilizing the n8n workflow.
If (n8n node): Named 'Valid Request?'. Controls the flow, directing valid requests to the AI processing path and invalid requests to the error formatting path.
PDF Vector (n8n node): Named 'PDF Vector - Ask Question'. The core intelligence component. It processes the document URL provided in the request and uses RAG logic to generate a contextual answer to the user's question.
Code (n8n node): Named 'Format Success Response'. Handles the final data transformation, structuring the AI answer, calculating a confidence score, and packaging it into a clear, client-friendly JSON format.
Code (n8n node): Named 'Format Error Response'. Prepares a standardized error message response when the initial request validation fails, ensuring a consistent API experience.


  • Respond to Webhook (n8n node): Named 'Send Response'. This is the terminal n8n node that immediately sends the structured JSON back to the client that initiated the n8n trigger.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

A fully featured PDF APIs for developers - Parse any PDF or Word document, extract structured data, and access millions of academic papers - all through simple APIs.

Featured*