Skip to main content

Document-based AI chatbot with RAG, OpenAI and Cohere reranker

Workflow preview

Workflow preview
100%
Document-based AI chatbot with RAG, OpenAI and Cohere reranker preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Build intelligent AI chatbot with RAG and Cohere Reranker Who is it for? This template is perfec...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.embeddingsopenai, @n8n/n8n-nodes-langchain.memorybufferwindow, n8n-nodes-base.manualtrigger, n8n-nodes-base.googledrive, @n8n/n8n-nodes-langchain.documentdefaultdataloader

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Anderson Adelino.

Original n8n.io source

1.1 Workflow description

Title
Document-based AI chatbot with RAG, OpenAI and Cohere reranker
Workflow name
Document-based AI chatbot with RAG, OpenAI and Cohere reranker

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Build intelligent AI chatbot with RAG and Cohere Reranker

Who is it for?

This template is perfect for developers, businesses, and automation enthusiasts who want to create intelligent chatbots that can answer questions based on their own documents. Whether you're building customer support systems, internal knowledge bases, or educational assistants, this workflow provides a solid foundation for document-based AI conversations.

How it works

This workflow creates an intelligent AI assistant that combines RAG (Retrieval-Augmented Generation) with Cohere's reranking technology for more accurate responses:

  1. Chat Interface: Users interact with the AI through a chat interface
  2. Document Processing: PDFs from Google Drive are automatically extracted and converted into searchable vectors
  3. Smart Search: When users ask questions, the system searches through vectorized documents using semantic search
  4. Reranking: Cohere's reranker ensures the most relevant information is prioritized
  5. AI Response: OpenAI generates contextual answers based on the retrieved information
  6. Memory: Conversation history is maintained for context-aware interactions

Setup steps

Prerequisites

  • n8n instance (self-hosted or cloud)
  • OpenAI API key
  • Supabase account with vector extension enabled
  • Google Drive access
  • Cohere API key

1. Configure Supabase Vector Store

First, create a table in Supabase with vector support:

CREATE TABLE cafeina (
  id SERIAL PRIMARY KEY,
  content TEXT,
  metadata JSONB,
  embedding VECTOR(1536)
);

-- Create a function for similarity search
CREATE OR REPLACE FUNCTION match_cafeina(
  query_embedding VECTOR(1536),
  match_count INT DEFAULT 10
)
RETURNS TABLE(
  id INT,
  content TEXT,
  metadata JSONB,
  similarity FLOAT
)
LANGUAGE plpgsql
AS $$
BEGIN
  RETURN QUERY
  SELECT
    cafeina.id,
    cafeina.content,
    cafeina.metadata,
    1 - (cafeina.embedding <=> query_embedding) AS similarity
  FROM cafeina
  ORDER BY cafeina.embedding <=> query_embedding
  LIMIT match_count;
END;
$$;

2. Set up credentials

Add the following credentials in n8n:

  • OpenAI: Add your OpenAI API key
  • Supabase: Add your Supabase URL and service role key
  • Google Drive: Connect your Google account
  • Cohere: Add your Cohere API key

3. Configure the workflow

  1. In the "Download file" node, replace URL DO ARQUIVO with your Google Drive file URL
  2. Adjust the table name in both Supabase Vector Store nodes if needed
  3. Customize the agent's tool description in the "searchCafeina" node

4. Load your documents

  1. Execute the bottom workflow (starting with "When clicking 'Execute workflow'")
  2. This will download your PDF, extract text, and store it in Supabase
  3. You can repeat this process for multiple documents

5. Start chatting

Once documents are loaded, activate the main workflow and start chatting with your AI assistant through the chat interface.

How to customize

  • Different document types: Replace the Google Drive node with other sources (Dropbox, S3, local files)
  • Multiple knowledge bases: Create separate vector stores for different topics
  • Custom prompts: Modify the agent's system message for specific use cases
  • Language models: Switch between different OpenAI models or use other LLM providers
  • Reranking settings: Adjust the top-k parameter for more or fewer search results
  • Memory window: Configure the conversation memory buffer size

Tips for best results

  • Use high-quality, well-structured documents for better search accuracy
  • Keep document chunks reasonably sized for optimal retrieval
  • Regularly update your vector store with new information
  • Monitor token usage to optimize costs
  • Test different reranking thresholds for your use case

Common use cases

  • Customer Support: Create bots that answer questions from product documentation
  • HR Assistant: Build assistants that help employees find information in company policies
  • Educational Tutor: Develop tutors that answer questions from course materials
  • Research Assistant: Create tools that help researchers find relevant information in papers
  • Legal Helper: Build assistants that search through legal documents and contracts

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Chat Interface

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 2 - RAG Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2

Block 3 - AI Model (OpenAI)

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 4 - Search Embeddings

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 5 - Conversation Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 6 - Load Documents Trigger

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 7 - Download PDF from Drive

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 8 - Document Embeddings

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 9 - Process Document Text

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1.1

Block 10 - Knowledge Base Search

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreSupabase - vectorStoreSupabase
Config choices
Version 1.3

Block 11 - Store in Vector Database

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreSupabase - vectorStoreSupabase
Config choices
Version 1.3

Block 12 - Extract PDF Content

Type / Role
n8n-nodes-base.extractFromFile - extractFromFile
Config choices
Version 1

Block 13 - Cohere Reranker

Type / Role
@n8n/n8n-nodes-langchain.rerankerCohere - rerankerCohere
Config choices
Version 1

Block 14 - Note: Chat Trigger

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Note: RAG Agent

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Note: Knowledge Search

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Note: Reranker

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 18 - Note: Configuration

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Document-based AI chatbot with RAG, OpenAI and Cohere reranker
Complexity advanced
Nodes 18
Categories Internal Wiki, AI RAG
Author Anderson Adelino
Published 25 Jul 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/6401/6401.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Document-based AI chatbot with RAG, OpenAI and Cohere reranker do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Build intelligent AI chatbot with RAG and Cohere Reranker Who is it for? This template is perfec...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.