{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ee0f84f3-c30c-4bdc-983a-fc2569b7d726",
      "name": "Kimi-K2 via Featherless.ai",
      "type": "n8n-nodes-featherless.featherless",
      "position": [
        624,
        0
      ],
      "parameters": {
        "model": "moonshotai/Kimi-K2-Instruct",
        "message": "=<document> \n{{\n$('Extract from File').first().json.text\n  .slice(\n    $itemIndex - 10  < 0 ? 0 : $itemIndex - 10,\n    $itemIndex + 5 > $('Extract from File').first().json.text.length - 1\n      ? $('Extract from File').first().json.text.length - 1\n      : $itemIndex + 5\n  )\n  .join('\\n')\n}} \n</document>\nHere is the chunk we want to situate within the whole document \n<chunk> \n{{ $json.text }}\n</chunk> \nPlease give a short succinct context, title and keywords to situate this chunk within the overall document for the purposes of improving search retrieval of the chunk. Answer only with the succinct context, title, keywords and nothing else.\nBe exhaustive with the keywords.",
        "temperature": 0.6,
        "system_prompt": "You are a helpful assistant.\nOutput using the following format\n```\nContext: ...\nTitle: ...\nKeywords: ...\n```",
        "additionalFields": {
          "max_tokens": "={{ 16384 - $parameter.system_prompt.length - $parameter.message.length }}"
        }
      },
      "credentials": {
        "featherlessApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a3827c3e-1d58-466e-b017-e37c93bc5906",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -480,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7bc49947-f4f4-44a5-9959-dedafe061a42",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        16,
        0
      ],
      "parameters": {
        "options": {
          "joinPages": false
        },
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "923063f7-d260-4940-a377-d48aaa97b36d",
      "name": "Get Response",
      "type": "n8n-nodes-base.set",
      "position": [
        848,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "19d13eb1-482a-4836-a529-f083422e6d64",
              "name": "summary",
              "type": "string",
              "value": "={{ $json.response\n    .match(/Context\\:[\\s]?([^\\n]+)/ig)?.[0]\n    .replace(/Context\\:[\\s]?/i, \"\")\n    .trim()\n}}\n{{ $json.response\n    .match(/Keywords\\:[\\s]?([^\\n]+)/ig)?.[0]\n    .replace(/Keywords\\:[\\s]?/i, \"\")\n    .trim()\n}}"
            },
            {
              "id": "541355a0-21f1-4cda-aa06-d3e0ec342e17",
              "name": "title",
              "type": "string",
              "value": "={{ $json.response\n    .match(/Title\\:[\\s]?([^\\n]+)/ig)?.[0]\n    .replace(/Title\\:[\\s]?/i, \"\")\n    .trim()\n}}"
            },
            {
              "id": "a7dfdd2e-75e0-4e16-be4a-08bdd183c313",
              "name": "chunk",
              "type": "string",
              "value": "={{ $('Split Pages').item.json.text }}"
            },
            {
              "id": "3b858044-8845-486b-a8ec-2b0f387124cd",
              "name": "pageNumber",
              "type": "string",
              "value": "={{ $itemIndex + 1 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c764ac52-9398-4590-8faf-04d2e46d4af1",
      "name": "Download Large Document",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -176,
        0
      ],
      "parameters": {
        "url": "https://www.highwaycodeuk.co.uk/uploads/3/2/9/2/3292309/the_official_highway_code_-_10-04-2025_2.pdf",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "09111780-2d13-4a12-81a0-91a4d716fc91",
      "name": "Split Pages",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        208,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "95ecabfb-c682-4862-b864-84825163a09b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 512,
        "content": "## 1. Works Best on Large Documents\n**Credit:** [Highway Code Ebook via highwaycodeuk.co.uk](https://www.highwaycodeuk.co.uk/uploads/3/2/9/2/3292309/the_official_highway_code_-_10-04-2025_2.pdf)\n\nFor large and information dense documents, simple chunking of text for your vector store may not perform well due to lack of context - things like titles, headings, chapters as well as preceding and following paragraphs are lost which are crucial to ensure results are relevant to a user's query. One approach to solve this problem and which we will explore in this template,  is called \"Contextual Summaries\".\n\nFor this demonstration, we'll build a RAG knowledgebase on the UK Highway Code. [View the PDF document here](https://www.highwaycodeuk.co.uk/uploads/3/2/9/2/3292309/the_official_highway_code_-_10-04-2025_2.pdf)."
      },
      "typeVersion": 1
    },
    {
      "id": "f3c8536e-a0f6-413e-8ca7-9bd909aea9be",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 512,
        "content": "## 2. Using Kimi-K2 via [Featherless.ai](https://featherless.ai/register?referrer=HJUUTA6M) for Unlimited Tokens!\n[Learn more about Featherless.ai pricing model](https://featherless.ai/#pricing?referrer=HJUUTA6M)\n\nGenerating Contextual summaries is an embedding technique to improve the retrieval relevance of similarity search results. It requires an LLM to summarise the current chunk against the full or larger portion of the original text which of course, can use a lot of tokens meaning higher costs and without proper care, can quickly exhaust credits and disrupt services.\n\nWith [Featherless.ai](https://featherless.ai/register?referrer=HJUUTA6M) however, their subscription plans include unlimited tokens at no extra cost! This makes them ideal for token intensive workloads whilst keeping costs manageable and predictable."
      },
      "typeVersion": 1
    },
    {
      "id": "268e1a4f-80d6-4abd-9633-096b62db0599",
      "name": "Retrieval Vectors with Gemini Embeddings 001",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1664,
        0
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent",
        "method": "POST",
        "options": {
          "batching": {
            "batch": {}
          }
        },
        "jsonBody": "={{\n{\n  \"model\": \"models/gemini-embedding-001\",\n  \"content\": {\n    \"parts\": [{ text: $json.summary }]\n  },\n  \"task_type\": \"RETRIEVAL_DOCUMENT\",\n  \"title\": $json.title,\n  \"output_dimensionality\": 768\n}\n}}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googlePalmApi"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 4.2
    },
    {
      "id": "58c81a7c-3f50-413a-b8a3-e38cb6415773",
      "name": "Add Docs To Qdrant Vector Store",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        1856,
        96
      ],
      "parameters": {
        "points": "={{\n[{\n  \"id\": $('Get Response').item.json.pageNumber.toNumber(),\n  \"payload\": {\n    \"content\": $('Get Response').item.json.chunk,\n     \"metadata\": {\n      \"summary\": $('Get Response').item.json.summary,\n      \"pageNumber\": $('Get Response').item.json.pageNumber.toNumber(),\n      \"url\": $('Download Large Document').params.url\n    }\n  },\n  \"vector\": {\n    \"default\": $json.embedding.values\n  }\n}].toJsonString()\n}}",
        "resource": "point",
        "operation": "upsertPoints",
        "collectionName": {
          "__rl": true,
          "mode": "list",
          "value": "highwaycode",
          "cachedResultName": "highwaycode"
        },
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f26f69c8-2449-4449-9aa7-2f598a2b8753",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1296,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "080df5be-ad23-4dd4-b93e-2474a2cb2452",
      "name": "Chunk Ref",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1472,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bdae9c94-5cd0-48d7-b065-0065f11ef33a",
      "name": "Create Collection",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        1296,
        576
      ],
      "parameters": {
        "vectors": "{\n  \"default\": {\n    \"distance\": \"Cosine\",\n    \"size\": 768\n  }\n}",
        "operation": "createCollection",
        "shardNumber": {},
        "sparseVectors": "{\n  \"minicoil\": {\n    \"modifier\": \"idf\"\n  }\n}",
        "collectionName": "highwaycode",
        "requestOptions": {},
        "replicationFactor": {},
        "writeConsistencyFactor": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6e917de3-776f-44b7-ad8c-7df1fe5a4cc0",
      "name": "Create Summary Index",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        1520,
        576
      ],
      "parameters": {
        "resource": "payload",
        "fieldName": "metadata.summary",
        "operation": "createPayloadIndex",
        "fieldSchema": "{\n  \"type\": \"text\",\n  \"tokenizer\": \"word\",\n  \"min_token_len\": 2,\n  \"max_token_len\": 10,\n  \"lowercase\": true\n}",
        "collectionName": {
          "__rl": true,
          "mode": "list",
          "value": "highwaycode",
          "cachedResultName": "highwaycode"
        },
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f4d9893d-c781-466b-bd6e-bee783ec81e9",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        3072,
        -624
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "940320a6-ddef-4629-ae9d-874ab71647c8",
      "name": "Subworkflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        2288,
        -64
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "query"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8882bbef-c8bb-496c-a60e-3e310f5ffb65",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        3264,
        -512
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c8e4954c-e375-4c7c-85d4-1e670e889ecf",
      "name": "Highway Code Manual1",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        3504,
        -512
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "Call this tool to query the Highway Code manual. The Highway Code is a comprehensive guide containing the rules, regulations, and advice for all road users in the UK, including pedestrians, cyclists, and drivers\n",
        "workflowInputs": {
          "value": {
            "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "query"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b111f132-2da9-496b-a68e-177750bd4a26",
      "name": "Highway Code Manual",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        3344,
        480
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "Call this tool to query the Highway Code manual. The Highway Code is a comprehensive guide containing the rules, regulations, and advice for all road users in the UK, including pedestrians, cyclists, and drivers\n",
        "workflowInputs": {
          "value": {
            "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "query"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d2a96906-d11c-415c-9025-2c313f4aee2c",
      "name": "Highway Code MCP Server",
      "type": "@n8n/n8n-nodes-langchain.mcpTrigger",
      "position": [
        3072,
        304
      ],
      "parameters": {
        "path": "639dd058-cfa6-4c67-84d2-aee52caf0e6b"
      },
      "typeVersion": 2
    },
    {
      "id": "e0338eec-5bfe-44ad-877a-9a46b5230c37",
      "name": "Highway Code Expert",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3280,
        -672
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an expert advisor of the UK Highway Code.\nWhen answering a user's query, ensure you provide citation of the page, rule or relevant legislation of your answer.\nIf the answer cannot be found in the UK highway code, then inform the user as such."
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f1deda9b-3e28-42f8-98a0-66369d82a7d0",
      "name": "Retrieval Vectors with Gemini-Embeddings-001",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2496,
        -64
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent",
        "method": "POST",
        "options": {
          "batching": {
            "batch": {}
          }
        },
        "jsonBody": "={{\n{\n  \"model\": \"models/gemini-embedding-001\",\n  \"content\": {\n    \"parts\": [{ text: $('Subworkflow Trigger').item.json.query }]\n  },\n  \"task_type\": \"RETRIEVAL_DOCUMENT\",\n  \"output_dimensionality\": 768\n}\n}}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googlePalmApi"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 4.2
    },
    {
      "id": "734f6d78-f6c4-4160-8997-d884a7660f30",
      "name": "Test Questions",
      "type": "n8n-nodes-base.set",
      "position": [
        3072,
        -128
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{\n{\n  \"question\": [\n    `You've just passed your first practical driving or riding test. What will you have to do if you get six penalty points on your licence in the next two years?\n1) Retake only your theory test\n2) Retake your theory and practical tests\n3) Retake only your practical test\n4) Reapply for your full licence immediately`,\n`What part of the car does the law require you to keep in good condition?\n1) The gearbox\n2) The transmission\n3) The door locks\n4) The seat belts`,\n`What's the main benefit of driving a four-wheel-drive vehicle?\n1) Improved grip on the road\n2) Lower fuel consumption\n3) Shorter stopping distances\n4) Improved passenger comfort`,\n`What colour are the reflective studs between a motorway and a slip road?\n1) Amber\n2) White\n3) Green\n4) Red`,\n`What should you do when you're passing loose sheep on the road?\n1) Briefly sound your horn\n2) Go very slowly\n3) Pass quickly but quietly\n4) Herd them to the side of the road`,\n`You're in a built-up area at night and the road is well lit. Why should you use dipped headlights?\n1) So that you can see further along the road\n2) So that you can go at a much faster speed\n3) So that you can switch to main beam quickly\n4) So that you can be easily seen by others`,\n`What should you do if the vehicle starts reversing off the driveway?\n1) Move to the opposite side of the road\n2) Drive through as you have priority\n3) Sound your horn and be prepared to stop\n4) Speed up and drive through quickly`,\n`How should you use anti-lock brakes when you need to stop in an emergency?\n1) Keep pumping the footbrake to prevent skidding\n2) Brake normally but grip the steering wheel tightly\n3) Brake promptly and firmly until you've stopped\n4) Apply the parking brake to reduce the stopping distance`,\n`Why should you allow extra room while overtaking a motorcyclist on a windy day?\n1) The rider may turn off suddenly to get out of the wind\n2) The rider may be blown in front of you\n3) The rider may stop suddenly\n4) The rider may be travelling faster than normal`\n  ]\n}\n}}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "400cf31e-1657-4833-bd4f-823998afd761",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        3248,
        -128
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "question"
      },
      "typeVersion": 1
    },
    {
      "id": "a9325e7f-da8c-4577-be50-939fd4ca4d08",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 912,
        "height": 624,
        "content": "## 3. Gemini-Embeddings-001 for Document Retrieval Embeddings\n[Learn more about Gemini Embeddings](https://ai.google.dev/gemini-api/docs/embeddings)\n\nGemini-Embeddings-001 is (at time of writing) the latest embeddings model from Google and comes with quite a few notable changes which warrants using the HTTP API rather of the n8n embeddings node.\n**1.** The default is now 3072 which may be overkill for a lot of document types. To bring this down to the more reasonable sizes of 768 or 1024, you must specify the `output_dimensionality` parameter.\n**2.** You can now improve embedding performance by specifying a \"task type\" which aligns with your use-case. For this template, we'll use the task type of `RETRIEVAL_DOCUMENT`.\n\nWe'll generate vectors for our contextual summaries and store them in our Qdrant vector store for later retrieval."
      },
      "typeVersion": 1
    },
    {
      "id": "dedb0860-4f3f-4a2b-b1a5-c9eeaad4999b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 384,
        "content": "## 3.1 Install Qdrant Community Node\n[Learn more about the Qdrant node](http://api.qdrant.tech/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-qdrant.qdrant)\n\nIf you want to follow along, you'll need to install the Qdrant community node which can be done via the nodes panel. Once installed, you'll need to create a **Collection** - the following two steps can do this for you! The Summary index is optional but enables full-text search on the `metadata.summary` values in our collection."
      },
      "typeVersion": 1
    },
    {
      "id": "5eb12796-3353-48c8-9ea6-6bd5616e463d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2192,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 432,
        "content": "## 4. Create a Document Retrieval Subworkflow Tool\n[Read more about Subworkflow triggers](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger)\n\nTo use our contextual retrieval embeddings, we'll need to use a subworkflow tool approach. This is because embedding API requiring the extra params not available via the n8n built-in embeddings node. Subworkflow tools are also a good idea in general - we can shared them within MCP servers and expose them to external agents."
      },
      "typeVersion": 1
    },
    {
      "id": "1c7b7364-2866-4da1-9bb2-baefbe0a215b",
      "name": "Query Docs from Qdrant Vector Store",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        2704,
        -64
      ],
      "parameters": {
        "limit": 20,
        "query": "={{ $json.embedding.values.toJsonString() }}",
        "using": "default",
        "resource": "search",
        "operation": "queryPoints",
        "collectionName": {
          "__rl": true,
          "mode": "list",
          "value": "highwaycode",
          "cachedResultName": "highwaycode"
        },
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c50a153d-ccbd-403e-ac97-a44ed1d080c1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2976,
        -832
      ],
      "parameters": {
        "color": 7,
        "width": 752,
        "height": 512,
        "content": "## Example Usage: The Highway Code Q&A Agent\n[Read more about AI Agents](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent)"
      },
      "typeVersion": 1
    },
    {
      "id": "a1d62ebf-4882-430d-987b-29f1e7cffba4",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2976,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 896,
        "height": 432,
        "content": "## Example Usage: The Automated UK Driving Theory Test Taker\n[Read more about Featherless AI node](https://www.npmjs.com/package/n8n-nodes-featherless)"
      },
      "typeVersion": 1
    },
    {
      "id": "68eaf415-0ceb-4a4e-9ab7-8540f7ca1822",
      "name": "Call Highway Code Manual Tool",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        3440,
        -80
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        },
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "workflowInputs": {
          "value": {
            "query": "={{ $json.question.split('\\n').first() }}"
          },
          "schema": [
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "query"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "70e62b09-219d-436d-83a9-4fbb08a4ac33",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2976,
        176
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 464,
        "content": "## Example Usage: Highway Code MCP Server\n[Read more about MCP Server Node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.mcptrigger/)"
      },
      "typeVersion": 1
    },
    {
      "id": "860bdf7d-dcf5-45e9-b6ac-9df36a3c4b77",
      "name": "Kimi-K2 via Featherless ai",
      "type": "n8n-nodes-featherless.featherless",
      "position": [
        3632,
        -80
      ],
      "parameters": {
        "model": "moonshotai/Kimi-K2-Instruct",
        "message": "=## Question\n{{ $('Split Out').item.json.question }}\n\n## References\n{{\n$json.result.points\n  .filter(point => point.score > 0.75)\n  .map(point => point.payload.toJsonString()).join('\\n')\n}}",
        "temperature": 0.6,
        "system_prompt": "=You are taking a UK driving theory test which contains multiple choice questions. Select the correct or most appropriate answer and output your answer as a number indicating the choice from the available choices. Refer to the highway code manual as required.\nDo not explain your reasoning and return only the number indicating the selected choice.",
        "additionalFields": {
          "max_tokens": "={{ 16384 - $parameter.system_prompt.length - $parameter.message.length }}"
        }
      },
      "credentials": {
        "featherlessApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0878af92-e970-42f2-a6bc-a77bf68269aa",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        -688
      ],
      "parameters": {
        "width": 528,
        "height": 1296,
        "content": "## Contextual Retrieval RAG for Less Using [Featherless.AI](https://featherless.ai/?referrer=HJUUTA6M) and Gemini-Embeddings-001\n\n### Generating contextual summaries is an token-intensive approach for RAG embeddings which can quickly rack up costs if your inference provider charges by token usage.\n\n[Featherless.ai](https://featherless.ai/?referrer=HJUUTA6M) is an inference provider with a different pricing model - they charge a flat subscription fee (starting from $10) and allows for unlimited token usage instead. If you're typically spending over $10 - $25 a month, you may find Featherless to be a cheaper and more manageable option for your projects or team.\n\nFor this template, Featherless's unlimited token usage is well suited for generating contextual summaries at high volumes for a majority of RAG workloads.\n\n### How it works\n1. A large document is imported into the workflow using the HTTP node and its text extracted via the Extract from file node. For this demonstration, the UK highway code is used an an example.\n2. Each page is processed individually and a contextual summary is generated for it. The contextual summary generation involves taking the current page, preceding and following pages together and summarising the contents of the current page.\n3. This summary is then converted to embeddings using Gemini-embedding-001 model. Note, we're using a http request to use the Gemini embedding API as at time of writing, n8n does not support the new API's schema.\n4. These embeddings are then stored in a Qdrant collection which can then be retrieved via an agent/MCP server or another workflow.\n\n### How to use\n* Replace the large document import with your own source of documents such as google drive or an internal repo.\n* Replace the manual trigger if you want the workflow to run as soon as documents become available. If you're using Google Drive, check out my [Push notifications for Google Drive template](https://n8n.io/workflows/6106-monitor-file-changes-with-google-drive-push-notifications/).\n* Expand and/or tune embedding strategies to suit your data. You may want to additionally embed the content itself and perform multi-stage queries using both.\n\n### Requirements\n* [Featherless.ai](https://featherless.ai/?referrer=HJUUTA6M) Account and API Key\n* Gemini Account and API Key for Embeddings\n* Qdrant Vector store\n\n### Customising this workflow\n* Sparse Vectors were not included in this template due to scope but should be the next step to getting the most our of contextual retrieval.\n* Be sure to explore other models on the Featherless.ai platform or host your own custom/finetuned models.\n\n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/XPKeKXeB7d) or ask in the [Forum](https://community.n8n.io/)!\n\nHappy Hacking!"
      },
      "typeVersion": 1
    },
    {
      "id": "8659639e-2a8f-49a2-8c67-23aa3552912b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        624
      ],
      "parameters": {
        "width": 528,
        "height": 304,
        "content": "![](https://cdn.subworkflow.ai/n8n-templates/banner_595x311.png#full-width)"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Chunk Ref": {
      "main": [
        [
          {
            "node": "Retrieval Vectors with Gemini Embeddings 001",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Call Highway Code Manual Tool",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Pages": {
      "main": [
        [
          {
            "node": "Kimi-K2 via Featherless.ai",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Response": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Test Questions": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Chunk Ref",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Collection": {
      "main": [
        [
          {
            "node": "Create Summary Index",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Split Pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Highway Code Manual": {
      "ai_tool": [
        [
          {
            "node": "Highway Code MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Subworkflow Trigger": {
      "main": [
        [
          {
            "node": "Retrieval Vectors with Gemini-Embeddings-001",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Highway Code Manual1": {
      "ai_tool": [
        [
          {
            "node": "Highway Code Expert",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Download Large Document": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Highway Code Expert",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Kimi-K2 via Featherless.ai": {
      "main": [
        [
          {
            "node": "Get Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Highway Code Expert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Highway Code Manual Tool": {
      "main": [
        [
          {
            "node": "Kimi-K2 via Featherless ai",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Docs To Qdrant Vector Store": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Download Large Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieval Vectors with Gemini Embeddings 001": {
      "main": [
        [
          {
            "node": "Add Docs To Qdrant Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieval Vectors with Gemini-Embeddings-001": {
      "main": [
        [
          {
            "node": "Query Docs from Qdrant Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}