E-mail Chatbot with Combined Semantic and Structured RAG Using Telegram and Pgvector

This workflow implements an intelligent email Q&A bot that allows users to interact with it via Telegram for quick inquiries about their personal emails. It combines semantic search with structured SQL queries, enabling it to understand natural language questions and accurately locate email content and time information, thereby providing precise answers. This system is particularly suitable for individuals and businesses that require efficient email management, enhancing the intelligence and convenience of email queries.

Tags

Email Q&ASemantic Search

Workflow Name

E-mail Chatbot with Combined Semantic and Structured RAG Using Telegram and Pgvector

Key Features and Highlights

This workflow develops an intelligent email Q&A chatbot that integrates semantic retrieval (based on vector search) with structured database queries (SQL) to enable efficient and intelligent querying of personal email databases. Users can interact directly via the Telegram chat interface or the built-in n8n chat. The chatbot comprehends natural language questions, automatically decomposes them, and invokes both vector search and SQL query engines to accurately locate email content and relevant temporal information, providing precise answers.

Core Problems Addressed

Traditional email search largely relies on keyword matching, which struggles to understand semantics and context, especially for queries involving time ranges and event details. By combining Pgvector’s vectorized semantic search with SQL’s structured querying, this workflow solves the challenges of semantic understanding of email content and precise temporal retrieval, enabling intelligent responses to complex email queries.

Application Scenarios

  • Rapidly querying email history for individuals or enterprises, such as finding meeting schedules, interview times, service registration dates, and other specific information
  • Conversational retrieval of email content anytime, anywhere via Telegram
  • Semantic Q&A on email data to improve email management efficiency and ease of information access
  • Acting as an intelligent assistant to help users manage and review email communication records

Main Workflow Steps

  1. Trigger Entry: Workflow is initiated by receiving a message on Telegram or via the built-in n8n chat
  2. Session Management: Generate and manage session IDs to support contextual memory
  3. Natural Language Understanding: Pass user input text to the AI Agent to parse query intent
  4. Semantic Vector Retrieval: Use the Pgvector vector database to perform semantic search on email texts and retrieve relevant email snippets
  5. Structured SQL Query: Based on email IDs from vector search results, invoke SQL query tools to obtain detailed structured email information (e.g., date, subject)
  6. Answer Generation and Formatting: The AI Agent synthesizes results from both queries to generate accurate answers and formats the response content
  7. Response Output: Segment the answer and send batch replies via Telegram messages to ensure completeness and readability

Involved Systems and Services

  • Telegram: Primary user interaction interface for receiving triggers and sending replies
  • Postgres PGVector: Stores vectorized embeddings of emails to enable semantic retrieval
  • SQL Database (Postgres): Stores structured email data supporting precise SQL queries
  • n8n LangChain Nodes: Integrate and orchestrate AI Agent, vector retrieval, and SQL query tools
  • OpenAI Model (mistral-small3.1) and Ollama Embeddings: Provide language understanding and vector embedding capabilities

Target Users and Value

  • Individual users with high email management needs who want to quickly query email history using natural language
  • Enterprise users and teams requiring efficient querying and summarization of large volumes of email communications
  • Developers and automation engineers aiming to build intelligent email Q&A assistants to enhance office automation
  • AI and data integration scenarios driving intelligent retrieval and insight extraction from email content

This workflow empowers users to intelligently query emails conversationally by leveraging advanced fusion of semantic and structured retrieval technologies, significantly enhancing the intelligence and convenience of email search.

Recommend Templates

RAG Workflow For Stock Earnings Report Analysis

This workflow utilizes RAG technology to automatically process and analyze the quarterly financial reports of publicly listed companies in PDF format, generating structured financial analysis reports. It accurately extracts key information through semantic retrieval and large language models, intelligently generating detailed reports that include content such as revenue, costs, and profits, which are then automatically saved to Google Docs. This process significantly enhances the efficiency and accuracy of financial data insights, helping investment analysts, financial advisors, and others quickly obtain in-depth analysis results.

Financial AnalysisRAG Technology

Voice RAG Chatbot with ElevenLabs and OpenAI

This workflow implements an intelligent chatbot based on voice interaction, integrating advanced speech synthesis, recognition technologies, and powerful language models. Users can ask questions via voice, and the system can retrieve relevant knowledge from the database in real-time and generate accurate, natural voice responses, significantly enhancing the accuracy and professionalism of voice Q&A. It is suitable for scenarios such as enterprise customer service, virtual shopping assistants, and knowledge base assistants, providing users with a convenient information retrieval experience.

Voice QARAG Chatbot

My workflow

This workflow automatically identifies and extracts key parameters from OAuth2 authentication configurations, such as authorization URI, token URI, and audience information, using a powerful AI language model. It incorporates a confidence scoring mechanism to help users assess the reliability of the data. This significantly enhances the efficiency and accuracy of OAuth2 setup, addressing the complexity and error-proneness of manual querying processes. It is suitable for developers, IT operations personnel, and API integration platform managers, optimizing the process of obtaining OAuth2 authentication parameters.

OAuth2 ConfigSmart Recognition

AI Phone Agent with RetellAI

This workflow provides an intelligent phone agent solution that can automatically record and transcribe calls, extract call summaries, and utilize advanced AI technology for knowledge base Q&A. It supports automatic scheduling of customer appointments, streamlining the manual scheduling process and enhancing the efficiency of phone customer service and sales teams. This system can analyze call content in real-time, ensuring that key information is not overlooked, making it suitable for various types of businesses and improving the quality and responsiveness of customer service.

Smart Phone AgentCall Summary

🔍🛠️ Tavily Search & Extract - Template

This workflow integrates Tavily's search and content extraction API with OpenAI's language model to achieve intelligent web information retrieval and content summarization. Users can input a topic in the chat window, and the system automatically filters highly relevant search results and extracts webpage content, ultimately generating a structured summary. This process addresses the issues of information overload and lack of structure found in traditional search methods, making it suitable for various scenarios such as research, business decision-making, and content creation, thereby enhancing the efficiency and quality of information acquisition.

Smart SearchContent Extraction

Integrating AI with Open-Meteo API for Enhanced Weather Forecasting

This workflow integrates artificial intelligence with a weather API to provide an intelligent weather inquiry service. Users only need to enter the city name and the number of days for the query in the chat interface, and the system will automatically retrieve the city's latitude and longitude, as well as future weather information, offering accurate weather forecasts. It supports multi-turn dialogue memory, enhancing the user experience. This service is suitable for scenarios such as travel planning, education and training, and intelligent customer service, allowing users to quickly obtain the weather data they need, thereby assisting with daily travel and decision-making.

Smart WeatherNatural Language Query

Local File Monitoring and Intelligent Q&A for Bank Statements Workflow

This workflow achieves intelligent management and querying of bank statements by monitoring the addition, deletion, and modification events within a local folder. It utilizes a vector database to synchronize file content, generating efficient semantic vector embeddings that support natural language interaction, thereby enhancing query accuracy and response speed. Users can quickly locate and understand a large number of financial documents, significantly improving the utilization efficiency of financial data and the querying experience.

Local File MonitorSmart Q&A

Personalized AI Tech Newsletter Using RSS, OpenAI, and Gmail

This workflow automatically fetches RSS news from multiple well-known technology websites, utilizing AI technology for intelligent analysis and summarization of the content. It generates a personalized weekly technology news briefing and sends it to users via email. Through this automated process, users can efficiently filter key information, avoid information overload, and easily stay updated on industry trends. It is suitable for tech enthusiasts, corporate teams, and professionals, enhancing information retrieval efficiency and reading experience.

PersonalizationSmart Summary