Generate Exam Questions

工作流概述

这是一个包含37个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "7Qa2mH7PnDxy7Qat",
  "meta": {
    "instanceId": "a4bfc93e975ca233ac45ed7c9227d84cf5a2329310525917adaf3312e10d5462",
    "templateCredsSetupCompleted": true
  },
  "name": "Generate Exam Questions",
  "tags": [],
  "nodes": [
    {
      "id": "4e037d6e-93a9-4c1b-b84a-dbbcf77beaf5",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -740,
        120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "febc8bb7-5de7-46d6-bc23-54673089cd3d",
      "name": "Qdrant Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        900,
        240
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "qdrantCollection": {
          "__rl": true,
          "mode": "list",
          "value": "ai_article_test",
          "cachedResultName": "ai_article_test"
        }
      },
      "credentials": {
        "qdrantApi": {
          "id": "iyQ6MQiVaF3VMBmt",
          "name": "QdrantApi account (Hetzner)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2d7e2673-6559-49b3-9ed0-29ca2c376f00",
      "name": "Create collection",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -440,
        -20
      ],
      "parameters": {
        "url": "http://QDRANT_URL/collections/COLLECTIONS",
        "method": "PUT",
        "options": {},
        "jsonBody": "{
  \"vectors\": {
    \"size\": 1536,
    \"distance\": \"Cosine\"  
  },
  \"shard_number\": 1,  
  \"replication_factor\": 1,  
  \"write_consistency_factor\": 1 
}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "qhny6r5ql9wwotpn",
          "name": "Qdrant API (Hetzner)"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "615f26b2-930c-4b74-a35c-00b83460a7c9",
      "name": "Refresh collection",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -440,
        240
      ],
      "parameters": {
        "url": "http://QDRANT_URL/collections/COLLECTIONS/points/delete",
        "method": "POST",
        "options": {},
        "jsonBody": "{
  \"filter\": {}
}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "qhny6r5ql9wwotpn",
          "name": "Qdrant API (Hetzner)"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "eb34b8dd-353b-41c4-8a02-6565c3f8a7d3",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        820,
        440
      ],
      "parameters": {
        "options": {
          "stripNewLines": false
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "4zwP0MSr8zkNvvV9",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "fb639802-e099-4857-823b-5e6d89fb3e86",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1080,
        460
      ],
      "parameters": {
        "loader": "textLoader",
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1
    },
    {
      "id": "0af5028d-56a4-4bbc-8af0-f088e54f178b",
      "name": "Token Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterTokenSplitter",
      "position": [
        1040,
        640
      ],
      "parameters": {
        "chunkSize": 450,
        "chunkOverlap": 50
      },
      "typeVersion": 1
    },
    {
      "id": "6a10192e-4b2e-4705-865a-fa90328ba3c1",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -80
      ],
      "parameters": {
        "color": 6,
        "width": 880,
        "height": 220,
        "content": "# STEP 1

## Create Qdrant Collection
Change:
- QDRANTURL
- COLLECTION"
      },
      "typeVersion": 1
    },
    {
      "id": "1ebefe44-e5c9-43fb-b9fa-fee47b08e2c2",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        180
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 400,
        "content": "# STEP 2












## Documents vectorization with Qdrant and Google Drive
Change:
- QDRANTURL
- COLLECTION"
      },
      "typeVersion": 1
    },
    {
      "id": "88f816ae-4331-46e0-b1f9-636ec94e8bb3",
      "name": "Converto di MD",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        240
      ],
      "parameters": {
        "jsCode": "function convertToMarkdown(docContent) {
  let markdown = '';

  const headingMap = {
    'HEADING_1': '#',
    'HEADING_2': '##',
    'HEADING_3': '###',
    'HEADING_4': '####',
    'HEADING_5': '#####',
    'HEADING_6': '######',
  };

  for (const element of docContent.body.content) {
    if (!element.paragraph) continue;

    const para = element.paragraph;
    let line = '';

    // Tipo di paragrafo (normale o heading)
    const style = para.paragraphStyle?.namedStyleType;
    const prefix = headingMap[style] || '';

    for (const el of para.elements) {
      if (!el.textRun) continue;

      let text = el.textRun.content || '';
      const style = el.textRun.textStyle || {};

      if (style.bold) text = `**${text.trim()}**`;
      if (style.italic) text = `*${text.trim()}*`;
      if (!style.bold && !style.italic) text = text.trim();

      line += text;
    }

    if (prefix) {
      markdown += `${prefix} ${line}\n\n`;
    } else {
      markdown += `${line}\n\n`;
    }
  }

  return markdown.trim();
}

// Assumiamo che il JSON completo sia in items[0].json
const docJson = items[0].json;
const markdown = convertToMarkdown(docJson);

return [
  {
    json: {
      markdown,
    },
  },
];"
      },
      "typeVersion": 2
    },
    {
      "id": "5c733b2d-3d0a-4260-af88-7907907e209f",
      "name": "Get Doc",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        -60,
        240
      ],
      "parameters": {
        "simple": false,
        "operation": "get",
        "documentURL": "XXXXXXXXXXXXXXXX"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "LpmDV1ry0BPLvW8b",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "5de82976-2376-4201-a5a4-dbdd6bfcb596",
      "name": "Vector Store Retriever",
      "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
      "position": [
        1540,
        1040
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "25bcb865-7b15-4272-81da-4ff41a4ccc60",
      "name": "Qdrant Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        1440,
        1180
      ],
      "parameters": {
        "options": {},
        "qdrantCollection": {
          "__rl": true,
          "mode": "list",
          "value": "ai_article_test",
          "cachedResultName": "ai_article_test"
        }
      },
      "credentials": {
        "qdrantApi": {
          "id": "iyQ6MQiVaF3VMBmt",
          "name": "QdrantApi account (Hetzner)"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7dacd3ac-2d25-4960-ba53-e44ae9722dca",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        560,
        240
      ],
      "parameters": {
        "options": {},
        "operation": "toText",
        "sourceProperty": "markdown"
      },
      "typeVersion": 1.1
    },
    {
      "id": "9d7561f0-5b01-4327-ab62-68a105364155",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        540,
        980
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash-exp"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0p34rXqIqy8WuoPg",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4f63e896-45b1-484f-9fa1-0b488691023a",
      "name": "Item List Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserItemList",
      "position": [
        740,
        1000
      ],
      "parameters": {
        "options": {
          "numberOfItems": 10
        }
      },
      "typeVersion": 1
    },
    {
      "id": "911e8654-dfef-4d4f-b1c8-247fe0091381",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1100,
        780
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "987e13f8-f8c9-4bc1-9e4f-d11a5f8af4d7",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1360,
        1020
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-pro-exp"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0p34rXqIqy8WuoPg",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c2f70831-4d5d-403b-b92d-af82205cbbdc",
      "name": "Google Gemini Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        520,
        1720
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash-exp"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0p34rXqIqy8WuoPg",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2f4ca583-8005-4e26-88df-ffebdc2be2f6",
      "name": "Item List Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserItemList",
      "position": [
        760,
        1720
      ],
      "parameters": {
        "options": {
          "numberOfItems": 10
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cacecdab-2f1c-4730-a7c5-d46dca32969c",
      "name": "Loop Over Items1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1080,
        1540
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "2de66223-475c-4fef-aa85-13e954a5c1cc",
      "name": "Google Gemini Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1320,
        1840
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash-exp"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0p34rXqIqy8WuoPg",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "43058954-369c-477d-beee-ece1916aebb7",
      "name": "Qdrant Vector Store2",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        1380,
        2020
      ],
      "parameters": {
        "options": {},
        "qdrantCollection": {
          "__rl": true,
          "mode": "list",
          "value": "ai_article_test",
          "cachedResultName": "ai_article_test"
        }
      },
      "credentials": {
        "qdrantApi": {
          "id": "iyQ6MQiVaF3VMBmt",
          "name": "QdrantApi account (Hetzner)"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "27dddcae-e20a-41a9-879e-ce8ae8a0347f",
      "name": "Embeddings OpenAI2",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1360,
        2200
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "4zwP0MSr8zkNvvV9",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "37d164a7-94aa-4273-b91a-8b22684a45fd",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1820,
        1820
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{
	\"type\": \"object\",
	\"properties\": {
		\"correct\": {
			\"type\": \"string\"
		},
		\"answers\": {
			\"type\": \"array\",
			\"items\": {
				\"type\": \"string\"
			}
		}
	}
}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "42d627b5-c033-4b2e-8ea4-fe704601b3d6",
      "name": "RAG",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "position": [
        1500,
        1820
      ],
      "parameters": {
        "description": "In base alla domanda consulta il database vettoriale ed estrapola la risposta corretta. Elabora anche altre 3 risposte non corrette."
      },
      "typeVersion": 1.1
    },
    {
      "id": "ce763ef2-eb54-484b-8046-7bc008012ec5",
      "name": "Google Gemini Chat Model4",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1700,
        1980
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-pro-exp"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0p34rXqIqy8WuoPg",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "076994e8-0326-424e-a5c3-3d07958af0af",
      "name": "Open questions",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        560,
        780
      ],
      "parameters": {
        "text": "=Article:
'''
{{ $json.markdown }}
'''",
        "messages": {
          "messageValues": [
            {
              "message": "=## Purpose
You are a specialized AI designed to analyze articles and create challenging questions that test comprehension and knowledge retention. Your task is to generate questions that encourage critical thinking about the article's content.

## Input
The input will be a text article on any subject. This could be academic, news, technical, or general interest content.

## Output Requirements
- Create exactly 10 questions based on the article content
- DO NOT number the questions
- Questions should cover key facts, concepts, and implications from the article
- Include a mix of question types:
  - Factual recall questions
  - Inference questions that require reading between the lines
  - Application questions that ask how concepts might be applied
  - Analysis questions that probe deeper understanding
  - Questions about relationships between different parts of the article
- Questions should vary in difficulty level
- Avoid creating questions with simple yes/no answers
- Ensure questions are clearly worded and unambiguous
- Questions should test genuine understanding rather than trivial details

## Output Format
- Present each question as a separate paragraph
- Do not include answers
- Do not include numbering or bullet points
- Do not include any introductory text
- Do not include any explanatory notes

## Behavior Guidelines
- Focus on the most significant and meaningful content in the article
- Ensure questions thoroughly cover the entire article, not just the beginning
- If the article contains technical terms, create questions that test understanding of these terms
- If the article presents contrasting viewpoints, create questions about both perspectives
- Maintain neutrality - do not frame questions that suggest a particular stance
- If the article is highly specialized, adjust question complexity accordingly
- Do not create questions about information not contained in the article
- If the article is in a language other than English, generate questions in the same language

## Examples of Good Questions
- How does the author's description of X relate to the concept of Y discussed later in the article?
- What evidence does the article provide to support the claim that X leads to Y?
- How might the framework described in the article be applied to solve similar problems in different contexts?
- What underlying assumptions inform the author's perspective on this issue?
- In what ways does the article suggest the relationship between X and Y has evolved over time?"
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.6
    },
    {
      "id": "5df02a14-175f-4923-9a2f-ad4514f98c71",
      "name": "Closed questions",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        560,
        1540
      ],
      "parameters": {
        "text": "=Article:
'''
{{ $json.markdown }}
'''",
        "messages": {
          "messageValues": [
            {
              "message": "=## Purpose
You are a specialized AI designed to analyze articles and create high-quality multiple-choice questions that effectively test knowledge comprehension and retention. Your task is to generate questions with appropriate answer options that accurately assess understanding of the article's content.

## Input
The input will be a text article on any subject. This could be academic, news, technical, or general interest content.

## Output Requirements
- Create exactly 10 multiple-choice questions based on the article content
- DO NOT number the questions
- Each question must include:
  - A clear question stem
  - Four answer options (labeled A, B, C, D)
  - One correct answer and three plausible distractors
- Questions should cover key facts, concepts, and implications from the article
- Include a mix of question types:
  - Factual recall questions
  - Inference questions requiring deeper understanding
  - Application questions testing practical knowledge
  - Analysis questions examining relationships between concepts
- Questions should vary in difficulty level
- Ensure questions are clearly worded and unambiguous
- Distractors should be plausible but clearly incorrect upon careful reading of the article

## Output Format
- Present each question as a separate paragraph
- Format each question as:
  [Question]
  A. [Option A]
  B. [Option B]
  C. [Option C]
  D. [Option D]
- Do not indicate which answer is correct in the output
- Do not include any introductory text
- Do not include any explanatory notes
- Do not include numbering for questions

## Behavior Guidelines
- Focus on the most significant and meaningful content in the article
- Ensure questions thoroughly cover the entire article, not just the beginning
- Make all answer options approximately the same length
- Avoid using absolute terms like \"always\" or \"never\" in the options
- Avoid grammatical clues that hint at the correct answer
- Make distractors plausible by:
  - Using common misconceptions
  - Including partially correct information
  - Using correct information from the wrong context
- If the article contains technical terms, create questions that test understanding of these terms
- If the article presents contrasting viewpoints, create questions about both perspectives
- Maintain neutrality - do not frame questions that suggest a particular stance
- If the article is in a language other than English, generate questions in the same language

## Examples of Good Multiple-Choice Questions
- What is the primary factor contributing to the phenomenon described in the article?
  A. [Plausible but incorrect factor]
  B. [Correct factor from article]
  C. [Plausible but incorrect factor]
  D. [Plausible but incorrect factor]

- According to the article, how does [concept X] impact [concept Y]?
  A. [Correct relationship described in article]
  B. [Plausible but incorrect relationship]
  C. [Plausible but incorrect relationship]
  D. [Plausible but incorrect relationship]

- Which application of the described technology would align with the principles outlined in the article?
  A. [Plausible but incorrect application]
  B. [Plausible but incorrect application]
  C. [Correct application based on article]
  D. [Plausible but incorrect application]"
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.6
    },
    {
      "id": "53c89d9a-4a69-47f7-bbf1-f523e2763741",
      "name": "Answer questions",
      "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
      "position": [
        1400,
        800
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemPromptTemplate": "You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question.

If you don't know the answer, just say that you don't know, don't try to make up an answer.
Use text plain (not markdown).
----------------
Context: {context}"
        },
        "promptType": "define"
      },
      "typeVersion": 1.5
    },
    {
      "id": "93d55b4f-2a93-474e-b431-6fd8ef868c45",
      "name": "Answer and create options",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1420,
        1560
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=System Prompt for RAG-Based Multiple-Choice Exam Creation

PURPOSE:
You are an AI assistant specialized in creating multiple-choice exams. Your task is to generate questions with one correct answer and three plausible but incorrect options using only the Retrieval Augmented Generation (RAG) tool to source accurate information.

INPUT:
You will receive a topic, subject area, or specific question to create exam items for.

OUTPUT REQUIREMENTS:
- Create multiple-choice questions with exactly four options per question
- Each question must have one correct answer and three false answers
- The correct answer must be derived directly from the RAG tool's retrieved information
- All false answers must be plausible but clearly incorrect when compared to the retrieved information
- Use plain text only (no markdown formatting)
- Present all content in a clean, simple format without any special formatting

PROCESS:
1. For each question:
   - Use the RAG tool to retrieve accurate information on the topic
   - Formulate a clear, unambiguous question based on the retrieved information
   - Extract the correct answer directly from the retrieved information
   - Create three false answers that are plausible but contradicted by the retrieved information
   - Mix the order of correct and incorrect answers

2. For creating false answers:
   - Use common misconceptions related to the topic
   - Create answers that contain partial truths but are ultimately incorrect
   - Modify correct information slightly to make it incorrect
   - Avoid obviously wrong answers that would be too easy to eliminate

OUTPUT FORMAT:
Question: [Question text]
A. [Option A]
B. [Option B]
C. [Option C]
D. [Option D]

GUIDELINES:
- Questions should be clear and direct
- Use simple, straightforward language
- Avoid negatively phrased questions (e.g., \"Which of the following is NOT...\")
- Ensure all answer options are approximately the same length
- Do not include any explanations, notes, or additional information
- Do not include any formatting beyond plain text
- Do not indicate which answer is correct in the output
- Ensure all questions and answers are factually accurate based on the RAG tool's information
- Make sure distractors (false answers) are genuinely plausible to someone not familiar with the topic

CONSTRAINTS:
- You must use the RAG tool for every question
- You must not rely on your general knowledge without verification through RAG
- You must not use markdown formatting
- You must not include any meta-information about the questions
- You must ensure all answer options are mutually exclusive (no overlap in meaning)
- You must use plain text only for all output"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "c7e55f54-d851-4786-839d-fe839659caea",
      "name": "Write open",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1880,
        800
      ],
      "parameters": {
        "columns": {
          "value": {
            "ANSWER": "={{ $json.response }}",
            "QUESTION": "={{ $('Loop Over Items').item.json.text }}"
          },
          "schema": [
            {
              "id": "QUESTION",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "QUESTION",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ANSWER",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ANSWER",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q/edit#gid=0",
          "cachedResultName": "Open questions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q/edit?usp=drivesdk",
          "cachedResultName": "Question for Exam"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "JYR6a64Qecd6t8Hb",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "1c72d8f0-b5b7-4e10-ad03-6c8491136cdf",
      "name": "Write closed",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1860,
        1560
      ],
      "parameters": {
        "columns": {
          "value": {
            "CORRECT": "={{ $json.output.correct }}",
            "ANSWER A": "={{ $json.output.answers[0] }}",
            "ANSWER B": "={{ $json.output.answers[1] }}",
            "ANSWER C": "={{ $json.output.answers[2] }}",
            "ANSWER D": "={{ $json.output.answers[3] }}",
            "QUESTION": "={{ $('Closed questions').item.json.text }}"
          },
          "schema": [
            {
              "id": "QUESTION",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "QUESTION",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ANSWER A",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ANSWER A",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ANSWER B",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ANSWER B",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ANSWER C",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ANSWER C",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ANSWER D",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ANSWER D",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CORRECT",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "CORRECT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 124452194,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q/edit#gid=124452194",
          "cachedResultName": "Closed questions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16zkksQMG1U9U850DFC5nDy-90VYZCgxLlyVwDB9I28Q/edit?usp=drivesdk",
          "cachedResultName": "Question for Exam"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "JYR6a64Qecd6t8Hb",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "9e5e41b1-32b2-413e-b63f-13e946857569",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1420,
        1340
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "4zwP0MSr8zkNvvV9",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a87ab6ba-39b0-4c7c-be19-9003e38c9495",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        780
      ],
      "parameters": {
        "width": 620,
        "height": 180,
        "content": "# STEP 3

The chain analyzes the document and creates 10 \"open\" questions and another chain analyzes each single question and through the consultation of the vector database the optimal answer is obtained."
      },
      "typeVersion": 1
    },
    {
      "id": "ea81bccc-d204-44d7-89b2-85f7b3267e34",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        1540
      ],
      "parameters": {
        "width": 620,
        "height": 180,
        "content": "# STEP 4

The chain analyzes the document and creates 10 questions with \"closed\" answers and another chain analyzes each single question and through the consultation of the vector database the correct answer and 3 other wrong answers are obtained to be used as a quiz."
      },
      "typeVersion": 1
    },
    {
      "id": "b510a77d-7436-4b84-b7a3-d42d75b15b59",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        -360
      ],
      "parameters": {
        "color": 3,
        "width": 1120,
        "height": 200,
        "content": "## Auto-Generate Exam Questions from Google Docs with AI

This workflow automates the creation of exam questions (both open-ended and multiple-choice) from educational content stored in Google Docs, using AI-powered analysis and vector database retrieval

This workflow **saves educators hours of manual work** while ensuring high-quality, curriculum-aligned assessments. Let me know if you'd like help adapting it for specific subjects!
"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "626a1ef7-45ae-4724-af3b-8a04b37fffc8",
  "connections": {
    "RAG": {
      "ai_tool": [
        [
          {
            "node": "Answer and create options",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Doc": {
      "main": [
        [
          {
            "node": "Converto di MD",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write open": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write closed": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Converto di MD": {
      "main": [
        [
          {
            "node": "Closed questions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Open questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Open questions": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Token Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Qdrant Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Answer questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer questions": {
      "main": [
        [
          {
            "node": "Write open",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Closed questions": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [],
        [
          {
            "node": "Answer and create options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Qdrant Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Qdrant Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Qdrant Vector Store2",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Refresh collection": {
      "main": [
        [
          {
            "node": "Get Doc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Qdrant Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Qdrant Vector Store1": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Retriever",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Qdrant Vector Store2": {
      "ai_vectorStore": [
        [
          {
            "node": "RAG",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Retriever": {
      "ai_retriever": [
        [
          {
            "node": "Answer questions",
            "type": "ai_retriever",
            "index": 0
          }
        ]
      ]
    },
    "Item List Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Open questions",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Open questions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Item List Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Closed questions",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Answer and create options",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Answer and create options": {
      "main": [
        [
          {
            "node": "Write closed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Answer questions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Closed questions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Answer and create options",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "RAG",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Refresh collection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Manualtrigger
  • @N8N/N8N Nodes Langchain.Vectorstoreqdrant
  • Httprequest
  • @N8N/N8N Nodes Langchain.Embeddingsopenai
  • @N8N/N8N Nodes Langchain.Documentdefaultdataloader

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作