Library / RAG & Knowledge Bases
RAG & Knowledge Bases
Answer document questions via webhook with Pinecone, OpenAI and Google Drive
Serves a POST endpoint that answers questions over a PDF library with cited passages and Drive links, caching repeat questions and gating low-confidence answers.
What it does
## Document Q&A API with Citations, Cache and Confidence Gate A POST endpoint that answers questions about your own PDF library and returns the answer, the exact passage it came from, the page number, and clickable Google Drive links to every source file. Built to be called by a website chat widget, a Slack bot, or any front end that can send JSON. ### How it works The webhook validates the request first and returns a 400 when the question is missing, so bad calls never reach a paid model. A repeated question is served from an answer cache held in an n8n data table, which keeps a busy endpoint fast and cheap for seven days. New questions go to a retrieval agent that searches a Pinecone index through OpenAI embeddings, reranks the matches with Cohere, and returns structured JSON: the answer, a confidence number, and one citation per supporting passage. A confidence gate sits after the agent, so a weak or unsupported answer comes back as an honest not-found response rather than a guess. Good answers have their source file names deduplicated, looked up once each in Google Drive, and turned into view and download links, with any file missing from Drive named in the reply. Every answer is then cached, written to an audit log with its confidence and response time, and returned. Conversation memory keyed on the caller's session id makes follow-up questions work. ### Setup Add your OpenAI, Gemini, Pinecone, Cohere, Drive and Sheets credentials. Point the Knowledge Base node at your Pinecone index, create a data table with the columns named on the cache node, and set the sheet ID and QA Log tab. ### Customization Change the cache window, the confidence threshold, or the reranker topN to trade accuracy against cost.
The steps
- Question Webhook
- Capture Request
- Valid Question?
- Respond Bad Request
- Look Up Cached Answer
- Fresh Cache Hit?
- Respond From Cache
- Document Q&A Agent
- Answer Model
- Fallback Answer Model
- Conversation Memory
- Document Knowledge Base
- Search Embeddings
- Match Reranker
24 steps in total.
Similar automations
RAG & Knowledge BasesAnswer Questions from Documents with OpenAI and Pinecone RAG24 stepsRAG & Knowledge BasesIndex Google Drive Documents in Pinecone with Contextual Chunking13 stepsRAG & Knowledge BasesRAG Chat Over Google Drive Documents with Pinecone23 stepsRAG & Knowledge BasesIndex Google Drive documents with OpenAI embeddings and Pinecone62 steps