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:
- Chat Interface: Users interact with the AI through a chat interface
- Document Processing: PDFs from Google Drive are automatically extracted and converted into searchable vectors
- Smart Search: When users ask questions, the system searches through vectorized documents using semantic search
- Reranking: Cohere's reranker ensures the most relevant information is prioritized
- AI Response: OpenAI generates contextual answers based on the retrieved information
- 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
- In the "Download file" node, replace
URL DO ARQUIVOwith your Google Drive file URL - Adjust the table name in both Supabase Vector Store nodes if needed
- Customize the agent's tool description in the "searchCafeina" node
4. Load your documents
- Execute the bottom workflow (starting with "When clicking 'Execute workflow'")
- This will download your PDF, extract text, and store it in Supabase
- 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
Document-Based AI Chatbot with RAG, OpenAI, and Cohere Reranker
This n8n workflow creates a powerful AI chatbot that can answer questions based on documents stored in Google Drive. It leverages Retrieval Augmented Generation (RAG) with OpenAI for language understanding and generation, Supabase as a vector store for document embeddings, and Cohere for reranking search results to improve relevance.
What it does
This workflow automates the following steps to provide a document-aware AI chatbot:
- Triggers on Chat Message: Initiates the workflow whenever a new chat message is received.
- Loads Documents from Google Drive: Retrieves specified documents from Google Drive.
- Extracts Content from Files: Processes the binary files from Google Drive to extract their textual content.
- Embeds Document Data: Converts the extracted document content into numerical vector embeddings using OpenAI's embedding models.
- Stores Embeddings in Supabase: Persists the document embeddings in a Supabase vector store for efficient similarity search.
- Retrieves Relevant Documents: When a user asks a question, it searches the Supabase vector store for document chunks most similar to the user's query.
- Reranks Documents with Cohere: Uses Cohere's reranker to refine the retrieved documents, ensuring the most relevant information is prioritized.
- Generates AI Response: Feeds the reranked relevant document snippets and the user's query to an OpenAI Chat Model to generate a comprehensive and contextually accurate answer.
- Maintains Chat History: Utilizes a simple memory buffer to keep track of the conversation context, allowing for more natural and coherent interactions.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- Google Drive Account: For storing your documents.
- OpenAI API Key: For generating embeddings and AI responses.
- Supabase Account: To set up a vector store for document embeddings.
- Cohere API Key: For reranking search results.
- Langchain Nodes: Ensure the
@n8n/n8n-nodes-langchainpackage is installed in your n8n instance.
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 access your documents.
- OpenAI: Configure an OpenAI credential with your API key.
- Supabase: Set up a Supabase credential with your API URL and API key. You will also need to configure your Supabase database with a
documentstable and amatch_documentsfunction for vector search. - Cohere: Configure a Cohere credential with your API key.
- Specify Google Drive Documents: In the "Google Drive" node, configure the specific files or folders you want to use as the knowledge base for your chatbot.
- Configure AI Agent: In the "AI Agent" node, ensure the correct models and tools are selected.
- Run the Workflow: Once configured, you can trigger the workflow manually using the "Manual Trigger" node to test document loading and embedding, or let it run automatically when a chat message is received via the "Chat Trigger" node.
- Interact with the Chatbot: Send chat messages to the configured "Chat Trigger" to start interacting with your document-aware AI chatbot.
Related Templates
Auto-create TikTok videos with VEED.io AI avatars, ElevenLabs & GPT-4
💥 Viral TikTok Video Machine: Auto-Create Videos with Your AI Avatar --- 🎯 Who is this for? This workflow is for content creators, marketers, and agencies who want to use Veed.io’s AI avatar technology to produce short, engaging TikTok videos automatically. It’s ideal for creators who want to appear on camera without recording themselves, and for teams managing multiple brands who need to generate videos at scale. --- ⚙️ What problem this workflow solves Manually creating videos for TikTok can take hours — finding trends, writing scripts, recording, and editing. By combining Veed.io, ElevenLabs, and GPT-4, this workflow transforms a simple Telegram input into a ready-to-post TikTok video featuring your AI avatar powered by Veed.io — speaking naturally with your cloned voice. --- 🚀 What this workflow does This automation links Veed.io’s video-generation API with multiple AI tools: Analyzes TikTok trends via Perplexity AI Writes a 10-second viral script using GPT-4 Generates your voiceover via ElevenLabs Uses Veed.io (Fabric 1.0 via FAL.ai) to animate your avatar and sync the lips to the voice Creates an engaging caption + hashtags for TikTok virality Publishes the video automatically via Blotato TikTok API Logs all results to Google Sheets for tracking --- 🧩 Setup Telegram Bot Create your bot via @BotFather Configure it as the trigger for sending your photo and theme Connect Veed.io Create an account on Veed.io Get your FAL.ai API key (Veed Fabric 1.0 model) Use HTTPS image/audio URLs compatible with Veed Fabric Other APIs Add Perplexity, ElevenLabs, and Blotato TikTok keys Connect your Google Sheet for logging results --- 🛠️ How to customize this workflow Change your Avatar: Upload a new image through Telegram, and Veed.io will generate a new talking version automatically. Modify the Script Style: Adjust the GPT prompt for tone (educational, funny, storytelling). Adjust Voice Tone: Tweak ElevenLabs stability and similarity settings. Expand Platforms: Add Instagram, YouTube Shorts, or X (Twitter) posting nodes. Track Performance: Customize your Google Sheet to measure your most successful Veed.io-based videos. --- 🧠 Expected Outcome In just a few seconds after sending your photo and theme, this workflow — powered by Veed.io — creates a fully automated TikTok video featuring your AI avatar with natural lip-sync and voice. The result is a continuous stream of viral short videos, made without cameras, editing, or effort. --- ✅ Import the JSON file in n8n, add your API keys (including Veed.io via FAL.ai), and start generating viral TikTok videos starring your AI avatar today! 🎥 Watch This Tutorial --- 📄 Documentation: Notion Guide Need help customizing? Contact me for consulting and support : Linkedin / Youtube
Track competitor SEO keywords with Decodo + GPT-4.1-mini + Google Sheets
This workflow automates competitor keyword research using OpenAI LLM and Decodo for intelligent web scraping. Who this is for SEO specialists, content strategists, and growth marketers who want to automate keyword research and competitive intelligence. Marketing analysts managing multiple clients or websites who need consistent SEO tracking without manual data pulls. Agencies or automation engineers using Google Sheets as an SEO data dashboard for keyword monitoring and reporting. What problem this workflow solves Tracking competitor keywords manually is slow and inconsistent. Most SEO tools provide limited API access or lack contextual keyword analysis. This workflow solves that by: Automatically scraping any competitor’s webpage with Decodo. Using OpenAI GPT-4.1-mini to interpret keyword intent, density, and semantic focus. Storing structured keyword insights directly in Google Sheets for ongoing tracking and trend analysis. What this workflow does Trigger — Manually start the workflow or schedule it to run periodically. Input Setup — Define the website URL and target country (e.g., https://dev.to, france). Data Scraping (Decodo) — Fetch competitor web content and metadata. Keyword Analysis (OpenAI GPT-4.1-mini) Extract primary and secondary keywords. Identify focus topics and semantic entities. Generate a keyword density summary and SEO strength score. Recommend optimization and internal linking opportunities. Data Structuring — Clean and convert GPT output into JSON format. Data Storage (Google Sheets) — Append structured keyword data to a Google Sheet for long-term tracking. Setup Prerequisites If you are new to Decode, please signup on this link visit.decodo.com n8n account with workflow editor access Decodo API credentials OpenAI API key Google Sheets account connected via OAuth2 Make sure to install the Decodo Community node. Create a Google Sheet Add columns for: primarykeywords, seostrengthscore, keyworddensity_summary, etc. Share with your n8n Google account. Connect Credentials Add credentials for: Decodo API credentials - You need to register, login and obtain the Basic Authentication Token via Decodo Dashboard OpenAI API (for GPT-4o-mini) Google Sheets OAuth2 Configure Input Fields Edit the “Set Input Fields” node to set your target site and region. Run the Workflow Click Execute Workflow in n8n. View structured results in your connected Google Sheet. How to customize this workflow Track Multiple Competitors → Use a Google Sheet or CSV list of URLs; loop through them using the Split In Batches node. Add Language Detection → Add a Gemini or GPT node before keyword analysis to detect content language and adjust prompts. Enhance the SEO Report → Expand the GPT prompt to include backlink insights, metadata optimization, or readability checks. Integrate Visualization → Connect your Google Sheet to Looker Studio for SEO performance dashboards. Schedule Auto-Runs → Use the Cron Node to run weekly or monthly for competitor keyword refreshes. Summary This workflow automates competitor keyword research using: Decodo for intelligent web scraping OpenAI GPT-4.1-mini for keyword and SEO analysis Google Sheets for live tracking and reporting It’s a complete AI-powered SEO intelligence pipeline ideal for teams that want actionable insights on keyword gaps, optimization opportunities, and content focus trends, without relying on expensive SEO SaaS tools.
Generate song lyrics and music from text prompts using OpenAI and Fal.ai Minimax
Spark your creativity instantly in any chat—turn a simple prompt like "heartbreak ballad" into original, full-length lyrics and a professional AI-generated music track, all without leaving your conversation. 📋 What This Template Does This chat-triggered workflow harnesses AI to generate detailed, genre-matched song lyrics (at least 600 characters) from user messages, then queues them for music synthesis via Fal.ai's minimax-music model. It polls asynchronously until the track is ready, delivering lyrics and audio URL back in chat. Crafts original, structured lyrics with verses, choruses, and bridges using OpenAI Submits to Fal.ai for melody, instrumentation, and vocals aligned to the style Handles long-running generations with smart looping and status checks Returns complete song package (lyrics + audio link) for seamless sharing 🔧 Prerequisites n8n account (self-hosted or cloud with chat integration enabled) OpenAI account with API access for GPT models Fal.ai account for AI music generation 🔑 Required Credentials OpenAI API Setup Go to platform.openai.com → API keys (sidebar) Click "Create new secret key" → Name it (e.g., "n8n Songwriter") Copy the key and add to n8n as "OpenAI API" credential type Test by sending a simple chat completion request Fal.ai HTTP Header Auth Setup Sign up at fal.ai → Dashboard → API Keys Generate a new API key → Copy it In n8n, create "HTTP Header Auth" credential: Name="Fal.ai", Header Name="Authorization", Header Value="Key [Your API Key]" Test with a simple GET to their queue endpoint (e.g., /status) ⚙️ Configuration Steps Import the workflow JSON into your n8n instance Assign OpenAI API credentials to the "OpenAI Chat Model" node Assign Fal.ai HTTP Header Auth to the "Generate Music Track", "Check Generation Status", and "Fetch Final Result" nodes Activate the workflow—chat trigger will appear in your n8n chat interface Test by messaging: "Create an upbeat pop song about road trips" 🎯 Use Cases Content Creators: YouTubers generating custom jingles for videos on the fly, streamlining production from idea to audio export Educators: Music teachers using chat prompts to create era-specific folk tunes for classroom discussions, fostering interactive learning Gift Personalization: Friends crafting anniversary R&B tracks from shared memories via quick chats, delivering emotional audio surprises Artist Brainstorming: Songwriters prototyping hip-hop beats in real-time during sessions, accelerating collaboration and iteration ⚠️ Troubleshooting Invalid JSON from AI Agent: Ensure the system prompt stresses valid JSON; test the agent standalone with a sample query Music Generation Fails (401/403): Verify Fal.ai API key has minimax-music access; check usage quotas in dashboard Status Polling Loops Indefinitely: Bump wait time to 45-60s for complex tracks; inspect fal.ai queue logs for bottlenecks Lyrics Under 600 Characters: Tweak agent prompt to enforce fuller structures like [V1][C][V2][B][C]; verify output length in executions