Dynamic AI Assistant with Site-Specific RAG and Router - n8n Workflow

Build a dynamic, site-aware AI assistant using this advanced n8n workflow. Integrates DeepSeek via OpenRouter, Pinecone for RAG, and Postgres for history, enabling multi-site support.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical teams needing high-performance, context-aware AI chat support.

  • Businesses running multiple websites or products requiring distinct RAG knowledge bases.

  • Developers looking for advanced examples of n8n templates integrating LangChain features like agents, memory, and vector stores.

  • Users wanting to leverage DeepSeek or other models via OpenRouter in an n8n workflow.

Overview

This specialized n8n workflow solves the common challenge of running a single, scalable AI assistant infrastructure that must serve multiple, distinct websites or products. Instead of deploying separate n8n workflows for each site, this centralized automation uses a powerful Switch n8n node to inspect the incoming request's site parameter. This allows the system to efficiently route the user's query to the appropriate, pre-configured AI Agent. Each agent maintains its own Postgres chat memory for conversational context and connects to its unique set of Pinecone knowledge bases (vector stores), ensuring answers are always site-specific and accurate. This robust n8n automation architecture is ideal for scaling support operations while maintaining strict contextual boundaries, making it one of the most useful n8n templates available for complex AI applications.

How it Works

The execution of this robust n8n workflow begins with the Webhook n8n trigger. This n8n trigger awaits an external request (likely from a web chat interface), which must include parameters such as query (the user's question), userId (for memory tracking), and crucially, site (to identify the originating website).


  1. Trigger and Routing: Once the Webhook n8n trigger receives the data, it passes the input to the Switch n8n node. This essential n8n node analyzes the $json.query.site value.

  2. Dynamic Agent Selection: Based on the value (e.g., testsite, testsite2, test_site3), the Switch routes the flow to the correct AI Agent branch. This dynamic routing is the core logic that makes this an effective multi-site n8n workflow template.

  3. AI Agent Processing: In the selected branch (e.g., the complex AI Agent for groton), the AI Agent n8n node orchestrates the RAG process. It uses the OpenRouter Chat Model (running DeepSeek) as its LLM, retrieves chat history from the Postgres Chat Memory n8n node (keyed by userId), and utilizes the connected Pinecone Vector Store n8n nodes as external tools for factual retrieval. The Cohere Embeddings n8n node facilitates the vector search.

  4. Context-Aware Response: The AI agent follows a detailed, custom system prompt (which incorporates the specific site and page context) to generate a response strictly based on the verified information in its corresponding Pinecone index.

  5. Final Response: The resulting AI output is then captured by the dedicated Respond to Webhook n8n node in that branch, which formats the data and sends the structured JSON answer back to the requesting client, completing the n8n automation cycle. This entire sequence demonstrates a powerful application of the n8n node ecosystem.

Installation Guide

To set up this powerful n8n workflow template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and paste it into your n8n instance using the "New" -> "Import from JSON" function.

  2. Configure Credentials: Several n8n node types require credentials:

OpenRouter API: Create and connect credentials for OpenRouter (used to access the DeepSeek chat model).
Pinecone API: Set up Pinecone credentials. Ensure these credentials have access to the specific namespaces referenced in the various Pinecone Vector Store n8n node configurations (e.g., ServicePackagesOverview, ghostwr, ebookwr).
Postgres Database: Configure Postgres credentials. This database is essential for the Postgres Chat Memory n8n node to maintain session continuity for each user (userId).
Cohere API: Configure Cohere credentials, as the embeddings n8n nodes require this service to facilitate similarity searches within Pinecone.

  1. Activate the n8n Trigger: Once all credentials are set, activate the Webhook n8n trigger node. Copy the Webhook URL and configure your frontend chat application to send queries to this URL, ensuring you pass the query, userId, and site parameters correctly in the request.

Node Details

This n8n workflow utilizes several advanced nodes, primarily from the LangChain community package:

Webhook n8n trigger: Serves as the initiation point for the entire n8n workflow.
Function: Triggers the n8n workflow upon receiving an HTTP request containing user query, site ID, and user ID.
Key Configuration: Configured with a unique path and set to wait for a response node.
Switch n8n node: The core logic gate.
Function: Directs the n8n workflow path based on the value of {{ $json.query.site }} (e.g., routing to agents for testsite, testsite2, or test_site3).
AI Agent (LangChain) n8n node: Multiple instances exist, forming the brain of this n8n automation.
Function: Orchestrates the retrieval augmented generation (RAG) process, combining LLM capabilities with factual data from Pinecone.
Key Configuration: Uses extensive, site-specific systemMessage prompts to enforce strict context boundaries and tool usage.
OpenRouter Chat Model (LangChain) n8n node:
Function: Provides the large language model capabilities, utilizing the DeepSeek model for high-quality responses in this n8n workflow.
Key Configuration: Model set to deepseek/deepseek-chat-v3-0324:free.
Pinecone Vector Store (LangChain) n8n node: Multiple instances are used, often linking different namespaces for specialized knowledge.
Function: Acts as a retrieval tool, querying indexed knowledge bases based on the userโ€™s question using the RAG approach.
Key Configuration: Configured in retrieve-as-tool mode, targeting specific Pinecone namespaces.
Postgres Chat Memory (LangChain) n8n node:
Function: Stores and retrieves the history of the conversation in a Postgres table, ensuring the AI agent maintains conversational flow across multiple turns within the n8n workflow.
Key Configuration: Uses dynamic expression {{ $('Webhook').item.json.query.userId }} as the session key.
Respond to Webhook n8n node: Multiple instances serve as the end point.
Function*: Formats the final AI response into a JSON object and sends it back to the client, concluding the n8n automation execution.

Related n8n Workflows

Free

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

Featured*