CORTEXFLOW · FREE FOREVER

Chatbots

RAG Chatbot over Company Documents

↓ Download workflow JSON

Import in n8n: Workflows → ⋯ → Import from file, then add your credentials. Free download with a free account.

How it works

The workflow has two separate chains: one answers questions, the other loads documents into the knowledge base.

Answer chain:

  1. Chat Trigger starts the conversation — the n8n chat UI sends the user’s question into the workflow.
  2. Embed Question creates a vector — the question is turned into an embedding through the OpenAI embeddings API.
  3. Search Vector DB retrieves chunks — the vector is searched against your vector database, returning the most relevant document chunks.
  4. Build Context formats the evidence — the retrieved chunks and the original question are assembled into clean fields for the agent.
  5. Answer from Docs (AI agent) answers — GPT answers using ONLY the retrieved context. If the answer is not in the context, it says so instead of guessing.

Ingestion chain (unconnected — runs separately):

  1. Ingest Webhook Trigger receives a document — POST document text (with an ID) to this webhook.
  2. Prepare Document normalizes it — trims the text and passes the document ID through (auto-generated if missing).
  3. Embed Document creates a vector — the document text is embedded with the same model used for questions.
  4. Upsert to Vector DB stores it — the vector plus the original text lands in your docs collection, ready for retrieval.

Set up steps

You’ll need:

  • n8n (self-hosted or cloud) with webhook access
  • An OpenAI account — get an API key at platform.openai.com → API keys
  • A vector database (Qdrant, Pinecone, or similar) — create a collection named docs and get an API key plus your API URL
  1. Download the workflow JSON using the download button on this page.
  2. In n8n, go to Workflows → ⋯ → Import from file and select the JSON.
  3. Create your OpenAI credentials — in n8n go to Credentials → New → OpenAI, paste your API key, save, and select it in OpenAI Chat Model. Then go to Credentials → New → Header Auth, add a header named Authorization with the value Bearer YOUR_OPENAI_API_KEY, save, and select it in Embed Question and Embed Document.
  4. Connect your vector database — in n8n go to Credentials → New → Header Auth, add your vector DB’s auth header, save, and select it in Search Vector DB and Upsert to Vector DB. Replace both placeholder URLs (https://your-vector-db.com/...) with your real endpoints.
  5. Ingest your docs — POST each document to the Ingest Webhook Trigger URL as {"doc_id": "handbook-1", "doc_text": "..."}. For one-off pastes, you can replace the trigger with a Manual Trigger.
  6. Activate the workflow (toggle, top-right), open the chat from the Chat Trigger node, and ask a question about your docs.

Note: Search Vector DB and Build Context expect Qdrant-style results (results[].payload.text). If your provider returns a different shape, adjust the expression in Build Context.

Customize it

  • Swap the embedding model — change text-embedding-3-small in Embed Question and Embed Document (keep both identical).
  • Tune retrieval — raise limit in Search Vector DB for more context per answer, or lower it for faster responses.
  • Ground harder — edit the system prompt in Answer from Docs to require citations from specific chunks.
  • Scheduled ingestion — replace Ingest Webhook Trigger with a Schedule Trigger that pulls documents from Google Drive, Notion, or your CMS on a cadence.
  • Chunk long documents — add a Code node after Prepare Document to split long texts into overlapping chunks before embedding.

Workflow nodes

This workflow is built from 10 nodes. Here's what each one does:

#NodeTypeWhat it does
1 Chat Trigger Chat Trigger Starts the workflow from the n8n chat interface.
2 Embed Question HTTP Request Calls an external API or webhook endpoint.
3 Search Vector DB HTTP Request Calls an external API or webhook endpoint.
4 Build Context Set Holds editable configuration values — fill in your own settings here before activating.
5 Answer from Docs AI Agent The AI brain — reasons over the task and calls tools to get it done.
6 OpenAI Chat Model OpenAI Chat Model The language model powering the AI agent.
7 Ingest Webhook Trigger Webhook Entry point — receives incoming HTTP requests that trigger the workflow.
8 Prepare Document Set Holds editable configuration values — fill in your own settings here before activating.
9 Embed Document HTTP Request Calls an external API or webhook endpoint.
10 Upsert to Vector DB HTTP Request Calls an external API or webhook endpoint.

Setup instructions

1. Add your credentials

In n8n go to Credentials → New, create each credential below, then open the named node and select it:

NodeCredential to add
Embed Question HTTP Header Auth
Search Vector DB HTTP Header Auth
OpenAI Chat Model OpenAI API
Embed Document HTTP Header Auth
Upsert to Vector DB HTTP Header Auth

How this workflow starts

  • Chat Trigger: Fires automatically on its event — activate the workflow and connect the service.
  • Webhook: Listens on path /ingest-doc — copy the production URL from the node after activating the workflow.

Use cases

Every growing company ends up answering the same questions over and over: the leave policy, the expense process, how the refund flow works. This template gives you a chatbot that answers from your own documents instead of guessing. It has two chains. The answer chain takes a question from the Chat Trigger, turns it into an embedding, searches your vector database for the most relevant chunks, and has the Answer from Docs agent reply using only that retrieved context — if the answer is not in the documents, it says so instead of hallucinating. The ingestion chain is separate: POST document text to the Ingest Webhook Trigger and it gets embedded and upserted into your docs collection, ready for retrieval.

The HR lead onboarding at a 40-person agency

New hires ask the same ten questions for their first month: notice period, work-from-home rules, the leave approval chain. The HR lead ingests the employee handbook through the Ingest Webhook Trigger — Prepare Document normalizes the text and passes the document ID through — and embeds it with the same model used for questions, text-embedding-3-small. From then on, new joiners ask the chat and get answers grounded in the actual handbook. Practical tip: when the handbook is updated, re-POST the revised text with the same doc_id so the vector store always reflects the current policy, and the honest fallback means the bot says it does not know rather than inventing a policy.

The SaaS support team with a sprawling help center

A support team of five fields tickets about a product with hundreds of help articles. They ingest the articles once, and agents use the chat internally to pull exact answers instead of searching the help center mid-ticket. Because Search Vector DB returns the most relevant chunks and Build Context assembles them with the original question, the agent answers with the evidence in front of it. Practical tip: raise the limit in Search Vector DB when answers need broader context, or lower it for faster responses on simple lookups — and edit the system prompt in Answer from Docs to require citations from specific chunks when support needs to quote chapter and verse.

The franchise network with a 300-page operations manual

Franchisees call headquarters about procedures that are all written down — in a manual nobody opens. The franchisor ingests the operations manual section by section through the webhook, and franchise owners ask the chat about everything from opening checklists to supplier escalation. The doc-ID passthrough in Prepare Document keeps each section addressable, so updates to one chapter do not require re-ingesting the whole manual. Practical tip: add a Code node after Prepare Document to split long chapters into overlapping chunks before embedding, which keeps retrieval precise on very long documents.

The compliance officer who needs sourced answers

A compliance officer answering "what does our policy say about data retention" needs the actual policy language, not a paraphrase. The Build Context node formats retrieved chunks into clean fields, and the agent answers only from that evidence. Practical tip: harden the grounding further by editing the agent's system prompt to quote the source chunk verbatim for policy questions, and schedule ingestion from Google Drive or Notion by swapping the Ingest Webhook Trigger for a Schedule Trigger so policy updates flow in on a cadence.

The consultancy productizing internal knowledge

A 25-person consultancy keeps its playbooks in scattered docs that only seniors know. Ingesting them into the docs collection turns tribal knowledge into something every junior can query on day one. The vector database can be Qdrant, Pinecone, or similar — Search Vector DB and Build Context expect Qdrant-style results, so if your provider returns a different shape, adjust the expression in Build Context. Practical tip: keep the embedding model identical in Embed Question and Embed Document — mismatched models silently break retrieval, which is the single most common setup mistake with this template.

← All templates