Skip to content

AI-Powered Chat with Document Retrieval

This workflow creates an intelligent chat interface that can answer questions based on stored documents using Google Gemini AI and vector search capabilities. Users can interact with the system through a public chat interface, and the AI will retrieve relevant information from an in-memory knowledge base to provide contextual answers.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. User Interaction: A user sends a message through the public chat interface
  2. Question Processing: The chat trigger receives the message and forwards it to the Q&A chain
  3. Document Retrieval: The system searches through stored documents using vector similarity to find relevant information
  4. AI Response Generation: Google Gemini processes the user's question along with the retrieved context to generate an informed response
  5. Response Delivery: The answer is returned to the user through the chat interface

The workflow uses an in-memory vector store that must be populated with documents before it can effectively answer questions. The vector embeddings are generated using Google Gemini's embedding model to ensure compatibility with the chat model.

Workflow Diagram

graph TD
    A[When chat message received] --> B[Question and Answer Chain]
    C[Google Gemini Chat Model] --> B
    D[Vector Store Retriever] --> B
    E[In-Memory Vector Store] --> D
    F[Embeddings Google Gemini] --> E

Trigger

Chat Trigger: A public webhook that accepts chat messages from users. The trigger is configured as public, making it accessible without authentication.

Nodes Used

Node Type Purpose
Chat Trigger Receives incoming chat messages from users
Question and Answer Chain Orchestrates the retrieval-augmented generation process
Google Gemini Chat Model Generates AI responses based on user questions and retrieved context
Vector Store Retriever Searches the vector database for relevant document chunks
In-Memory Vector Store Stores document embeddings for similarity search
Embeddings Google Gemini Converts text into vector embeddings for storage and retrieval

External Services & Credentials Required

  • Google Gemini (PaLM) API: Required for both chat model and embeddings
    • Credential name: "Google Gemini(PaLM) Api account"
    • Used by: Google Gemini Chat Model, Embeddings Google Gemini

Environment Variables

No environment variables are explicitly configured in this workflow. All configuration is handled through node parameters and credentials.

Data Flow

Input: - Chat messages from users (text)

Processing: - User message → Vector similarity search → Retrieved document chunks + Original question → AI model → Generated response

Output: - AI-generated responses based on retrieved context

Error Handling

No explicit error handling nodes are configured in this workflow. Errors would be handled by n8n's default error handling mechanisms.

Known Limitations

  • The in-memory vector store is ephemeral and will lose all data when the workflow stops
  • No document ingestion mechanism is included in this workflow
  • No conversation history or context retention between chat sessions
  • Public webhook may be subject to abuse without rate limiting

No related workflows specified in the context.

Setup Instructions

  1. Import the Workflow: Import the JSON into your n8n instance

  2. Configure Google Gemini Credentials:

    • Create a Google Gemini (PaLM) API credential
    • Obtain an API key from Google AI Studio
    • Add the credential to both the Google Gemini Chat Model and Embeddings nodes
  3. Populate the Vector Store:

    • Create a separate workflow to load documents into the In-Memory Vector Store
    • Or modify this workflow to include document ingestion capabilities
  4. Test the Chat Interface:

    • Activate the workflow
    • Use the webhook URL to test chat functionality
    • Ensure documents are loaded before testing Q&A capabilities
  5. Security Considerations:

    • Consider adding authentication if the chat interface should not be public
    • Implement rate limiting to prevent abuse
    • Monitor usage and costs associated with Google Gemini API calls

Note: This workflow requires documents to be pre-loaded into the vector store before it can provide meaningful answers. Consider creating a companion workflow for document ingestion and management.