{
  "id": "ARzussFtHtyTQyNE",
  "name": "07.Cost Engineering RAG",
  "tags": [],
  "nodes": [
    {
      "id": "95f41fb0-e5d4-432a-a21d-898298ba8da5",
      "name": "Document Ingestion Scheduler",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1024,
        80
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 2
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "35aba6b3-6695-4a47-87b9-6122053f46f2",
      "name": "Drive Folder Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        1216,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "30c4b9ef-4963-43ad-99f8-0dee5fd24c17",
              "name": "ragIncomingFolder",
              "type": "string",
              "value": "RAG_INCOMING_FOLDER_ID"
            },
            {
              "id": "769460f3-2746-4967-b7a8-8a1718777a05",
              "name": "ragIngestedFolder",
              "type": "string",
              "value": "RAG_INGESTED_FOLDER_ID"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c9463961-6c60-41e7-811d-1ac9205122da",
      "name": "Source Document Discovery",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1408,
        80
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $json.ragIncomingFolder }}"
          }
        },
        "options": {},
        "resource": "fileFolder",
        "returnAll": true
      },
      "typeVersion": 3
    },
    {
      "id": "73b3b962-97cc-4c78-ab9d-e5db25c18976",
      "name": "Document Downloader",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1600,
        80
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "f5e6606d-fba8-4142-81a4-ed03ec4cdd01",
      "name": "PDF Content Extractor",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1792,
        80
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1.1
    },
    {
      "id": "d8517342-2c5f-463f-89cf-255ba86315fd",
      "name": "Document Chunker",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1984,
        528
      ],
      "parameters": {
        "options": {},
        "chunkSize": 2000,
        "chunkOverlap": 200
      },
      "typeVersion": 1
    },
    {
      "id": "4eace0d3-0e90-4ef0-81ec-31eb1093d7a5",
      "name": "Chunk Metadata Builder",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1984,
        352
      ],
      "parameters": {
        "options": {},
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "811ade8f-d00d-4e3a-9b82-86a446e7d193",
      "name": "Embedding Generator",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1744,
        832
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "dc9a0150-b6d6-4b5f-beb4-c0d1ffa7d6a3",
      "name": "Vector Index Writer",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1984,
        80
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "rag",
          "cachedResultName": "rag"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "88a2cb6f-2dee-4f37-9227-eb48228721dc",
      "name": "Archive Processed Document",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2304,
        80
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Document Downloader').item.json.id }}"
        },
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Drive Folder Configuration').item.json.ragIngestedFolder }}"
        },
        "operation": "move"
      },
      "typeVersion": 3
    },
    {
      "id": "d9141e78-38ae-4488-83e6-5025c0820a48",
      "name": "User Query Input",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1024,
        400
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.4
    },
    {
      "id": "6825d610-7a75-4c8b-8a87-0fc01429dc37",
      "name": "RAG Answering Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1216,
        400
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a construction cost estimating specialist.\n\nYou MUST use the document retrieval tool before answering any question.\n\nAnswer exclusively using information retrieved from the Technical Composition Manuals.\n\nDo not use prior knowledge.\n\nDo not make assumptions.\n\nDo not infer information that is not explicitly stated in the retrieved documents.\n\nIf the retrieved documents do not contain sufficient evidence to answer the question, respond exactly with:\n\n\"I cannot find the answer in the available resources.\"\n\nNever generate, complete, or guess missing information.\n\nWhen available, always cite:\n\n* Composition\n* Code\n* Unit\n* Productivity\n\nInclude the source information exactly as found in the retrieved documents.\n"
        }
      },
      "typeVersion": 3.1
    },
    {
      "id": "621608b8-ea3f-4a4d-a4fd-9d1278205fb4",
      "name": "LLM Response Generator",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1184,
        592
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "95e9e329-a46a-4101-aa7c-ec9e00a47c6a",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1312,
        592
      ],
      "parameters": {},
      "typeVersion": 1.4
    },
    {
      "id": "1bbffc5d-22a6-4016-910d-bb99a6e85fa2",
      "name": "Document Retriever Tool",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1424,
        592
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 20,
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "rag",
          "cachedResultName": "rag"
        },
        "toolDescription": "document_retriever_tool"
      },
      "typeVersion": 1.3
    },
    {
      "id": "62b2750e-8189-43f9-9fbe-023ba28a4f6b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 1824,
        "height": 288,
        "content": "## Cost Engineering RAG Ingestion Pipeline"
      },
      "typeVersion": 1
    },
    {
      "id": "b8f11851-b3b2-48f9-ac94-03516390aee8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 992,
        "height": 416,
        "content": "## Cost Engineering RAG Retrieval Pipeline"
      },
      "typeVersion": 1
    },
    {
      "id": "e878730d-5ed6-4f01-a0f4-453bfeb5ec6a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1888,
        288
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 448,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "d4079552-aca2-4ddd-9e50-f734b1ab2bee",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2496,
        80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "00e8b346-1528-4274-87a9-36170e8ab3fe",
      "name": "No Operation, do nothing1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1536,
        400
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8d3b69f7-2174-4806-a2fb-2f03da93d319",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        768
      ],
      "parameters": {
        "color": 7,
        "width": 1824,
        "height": 224,
        "content": "## Embedding"
      },
      "typeVersion": 1
    },
    {
      "id": "87557fd3-d2e0-4da3-a34f-7508cc74908a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 2,
        "width": 832,
        "height": 1120,
        "content": "# Cost Engineering RAG Ingestion & Retrieval\n\n## How It Works\n\n1. A scheduled trigger scans a Google Drive **Incoming** folder for new documents.\n2. New PDF files are downloaded, their text is extracted, and the content is split into chunks with metadata attached.\n3. The chunks are converted into embeddings using OpenAI and stored in the **Pinecone `rag` index**. Processed files are then moved to the **Ingested Archive** folder.\n4. A chat webhook receives user questions. The RAG agent retrieves relevant passages from Pinecone and generates answers based exclusively on the indexed documents.\n5. When available, responses include:\n\n   * Composition\n   * Code\n   * Unit\n   * Productivity\n6. If sufficient evidence is not found, the agent responds with:\n\n   > \"I cannot find the answer in the available resources.\"\n\n---\n\n## Setup Checklist\n\n### Google Drive\n\n* [ ] Connect a Google Drive account.\n* [ ] Configure the **Incoming Folder ID**.\n* [ ] Configure the **Ingested Folder ID**.\n\n### Documents\n\n* [ ] Upload Technical Composition Manuals to the Incoming folder.\n\n### OpenAI\n\n* [ ] Add an OpenAI API key for:\n\n  * Embedding generation\n  * LLM responses\n\n### Pinecone\n\n* [ ] Connect a Pinecone account.\n* [ ] Ensure an index named **`rag`** exists and is accessible.\n\n### Workflow Configuration\n\n* [ ] Review the schedule trigger frequency (default: every 2 minutes).\n* [ ] Configure the chat webhook URL.\n* [ ] Review the agent system prompt.\n* [ ] Validate the Pinecone retrieval tool settings.\n\n---\n\n## Expected Behavior\n\nThe assistant must:\n\n* Always consult the document retrieval tool before answering.\n* Answer exclusively using information retrieved from the Technical Composition Manuals.\n* Never use prior knowledge or make assumptions.\n* Never generate or infer missing information.\n* Return the predefined fallback message when sufficient evidence is unavailable.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "e33e228f-b527-4481-903a-7a7ad5a3b552",
  "connections": {
    "Document Chunker": {
      "ai_textSplitter": [
        [
          {
            "node": "Chunk Metadata Builder",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "User Query Input": {
      "main": [
        [
          {
            "node": "RAG Answering Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Downloader": {
      "main": [
        [
          {
            "node": "PDF Content Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embedding Generator": {
      "ai_embedding": [
        [
          {
            "node": "Vector Index Writer",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Document Retriever Tool",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "RAG Answering Agent": {
      "main": [
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vector Index Writer": {
      "main": [
        [
          {
            "node": "Archive Processed Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDF Content Extractor": {
      "main": [
        [
          {
            "node": "Vector Index Writer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chunk Metadata Builder": {
      "ai_document": [
        [
          {
            "node": "Vector Index Writer",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "LLM Response Generator": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Answering Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Document Retriever Tool": {
      "ai_tool": [
        [
          {
            "node": "RAG Answering Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Source Document Discovery": {
      "main": [
        [
          {
            "node": "Document Downloader",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Archive Processed Document": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive Folder Configuration": {
      "main": [
        [
          {
            "node": "Source Document Discovery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Ingestion Scheduler": {
      "main": [
        [
          {
            "node": "Drive Folder Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}