Modifying A RAG workflow to have clickable inline refrences

Hi I am new to n8n and i am modifying a RAG n8n workflow that works with google drive, i want to know how to get clickable inline refrence tags. If the n8n AI Assistant was active it would have helped with this.

Please share your workflow

{
“nodes”: [
{
“parameters”: {},
“id”: “764a865c-7efe-4eec-a34c-cc87c5f085b1”,
“name”: “Chat Trigger”,
“type”: “@n8n/n8n-nodes-langchain.chatTrigger”,
“position”: [
680,
1060
],
“webhookId”: “1727c687-aed0-49cf-96af-e7796819fbb3”,
“typeVersion”: 1
},
{
“parameters”: {
“jsCode”: “let out = ""\nfor (const i in $input.all()) {\n let itemText = "— CHUNK " + i + " —\n"\n itemText += $input.all()[i].json.document.pageContent + "\n"\n itemText += "\n"\n out += itemText\n}\n\nreturn {\n ‘context’: out\n};”
},
“id”: “36cd9a8d-7d89-49b3-8a81-baa278201a21”,
“name”: “Prepare chunks”,
“type”: “n8n-nodes-base.code”,
“position”: [
1500,
1060
],
“typeVersion”: 2
},
{
“parameters”: {
“options”: {}
},
“id”: “6356bce2-9aae-43ed-97ce-a27cbfb80df9”,
“name”: “Embeddings OpenAI2”,
“type”: “@n8n/n8n-nodes-langchain.embeddingsOpenAi”,
“position”: [
1120,
1280
],
“typeVersion”: 1,
“credentials”: {
“openAiApi”: {
“id”: “EEfoQTeXEMY3E8hu”,
“name”: “OpenAi account”
}
}
},
{
“parameters”: {
“options”: {}
},
“id”: “8fb697ea-f2e5-4105-b6c8-ab869c2e5ab2”,
“name”: “OpenAI Chat Model”,
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“position”: [
1740,
1280
],
“typeVersion”: 1,
“credentials”: {
“openAiApi”: {
“id”: “EEfoQTeXEMY3E8hu”,
“name”: “OpenAi account”
}
}
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “236047ff-75a2-47fd-b338-1e9763c4015e”,
“name”: “chunks”,
“type”: “number”,
“value”: 4
}
]
},
“includeOtherFields”: true,
“options”: {}
},
“id”: “9a2b0152-d008-42cb-bc10-495135d5ef45”,
“name”: “Set max chunks to send to model”,
“type”: “n8n-nodes-base.set”,
“position”: [
900,
1060
],
“typeVersion”: 3.3
},
{
“parameters”: {
“jsonSchema”: “{\n "type": "object",\n "properties": {\n "answer": {\n "type": "string"\n },\n "citations": {\n "type": "array",\n "items": {\n "type": "number"\n }\n }\n }\n}”
},
“id”: “f2ab813f-0f0c-4d3a-a1de-7896ad736698”,
“name”: “Structured Output Parser”,
“type”: “@n8n/n8n-nodes-langchain.outputParserStructured”,
“position”: [
1920,
1280
],
“typeVersion”: 1
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “67ecefcf-a30c-4cc4-89ca-b9b23edd6585”,
“name”: “citations”,
“type”: “array”,
“value”: “={{ $json.citations.map(i => ‘[’ + $(‘Get top chunks matching query’).all()[$json.citations].json.document.metadata.file_name + ', lines ’ + $(‘Get top chunks matching query’).all()[$json.citations].json.document.metadata[‘loc.lines.from’] + ‘-’ + $(‘Get top chunks matching query’).all()[$json.citations].json.document.metadata[‘loc.lines.to’] + ‘]’) }}”
}
]
},
“includeOtherFields”: true,
“options”: {}
},
“id”: “ada2a38b-0f6e-4115-97c0-000e97a5e62e”,
“name”: “Compose citations”,
“type”: “n8n-nodes-base.set”,
“position”: [
2100,
1060
],
“typeVersion”: 3.3
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “d77956c4-0ff4-4c64-80c2-9da9d4c8ad34”,
“name”: “text”,
“type”: “string”,
“value”: “={{ $json.answer }} {{ $if(!$json.citations.isEmpty(), "\n" + $json.citations.join(""), ‘’) }}”
},
{
“id”: “afa3a3d5-013a-45d1-8d74-6a6f1815f0b0”,
“name”: “refrences”,
“value”: “={{ chunkdata= $(‘Get top chunks matching query’).item.json.document.metadata.document_id }}”,
“type”: “string”
}
]
},
“options”: {}
},
“id”: “8e115308-532e-4afd-b766-78e54c861f33”,
“name”: “Generate response”,
“type”: “n8n-nodes-base.set”,
“position”: [
2320,
1060
],
“typeVersion”: 3.3
},
{
“parameters”: {
“content”: “## 2. Chat with file, getting citations in reponse”,
“height”: 548.5086735412393,
“width”: 1693.989843925635,
“color”: 7
},
“id”: “40c5f9d8-38da-41ac-ab99-98f6010ba8bf”,
“name”: “Sticky Note1”,
“type”: “n8n-nodes-base.stickyNote”,
“position”: [
860,
940
],
“typeVersion”: 1
},
{
“parameters”: {
“promptType”: “define”,
“text”: “=Use the following pieces of context to answer the question at the end. If you don’t know the answer, just say that you don’t know, don’t try to make up an answer. Important: In your response, also include the the indexes of the chunks you used to generate the answer.\n\n{{ $json.context }}\n\nQuestion: {{ $("Chat Trigger").first().json.chatInput }}\nHelpful Answer:”,
“hasOutputParser”: true
},
“id”: “ef357a2b-bc8d-43f7-982f-73c3a85a60be”,
“name”: “Answer the query based on chunks”,
“type”: “@n8n/n8n-nodes-langchain.chainLlm”,
“position”: [
1720,
1060
],
“typeVersion”: 1.4
},
{
“parameters”: {
“mode”: “load”,
“pineconeIndex”: {
“__rl”: true,
“value”: “campus-genie”,
“mode”: “list”,
“cachedResultName”: “campus-genie”
},
“prompt”: “={{ $json.chatInput }}”,
“topK”: “={{ $json.chunks }}”,
“options”: {}
},
“id”: “1a5511b9-5a24-40d5-a5b1-830376226e4e”,
“name”: “Get top chunks matching query”,
“type”: “@n8n/n8n-nodes-langchain.vectorStorePinecone”,
“position”: [
1120,
1060
],
“typeVersion”: 1,
“credentials”: {
“pineconeApi”: {
“id”: “mGpRzKnaRIBWi3Bl”,
“name”: “PineconeApi account”
}
}
}
],
“connections”: {
“Chat Trigger”: {
“main”: [
[
{
“node”: “Set max chunks to send to model”,
“type”: “main”,
“index”: 0
}
]
]
},
“Prepare chunks”: {
“main”: [
[
{
“node”: “Answer the query based on chunks”,
“type”: “main”,
“index”: 0
}
]
]
},
“Embeddings OpenAI2”: {
“ai_embedding”: [
[
{
“node”: “Get top chunks matching query”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
},
“OpenAI Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “Answer the query based on chunks”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Set max chunks to send to model”: {
“main”: [
[
{
“node”: “Get top chunks matching query”,
“type”: “main”,
“index”: 0
}
]
]
},
“Structured Output Parser”: {
“ai_outputParser”: [
[
{
“node”: “Answer the query based on chunks”,
“type”: “ai_outputParser”,
“index”: 0
}
]
]
},
“Compose citations”: {
“main”: [
[
{
“node”: “Generate response”,
“type”: “main”,
“index”: 0
}
]
]
},
“Answer the query based on chunks”: {
“main”: [
[
{
“node”: “Compose citations”,
“type”: “main”,
“index”: 0
}
]
]
},
“Get top chunks matching query”: {
“main”: [
[
{
“node”: “Prepare chunks”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateId”: “2165”,
“templateCredsSetupCompleted”: true,
“instanceId”: “fb7475f294ee0d10df37e260ff5aed51ad3de9deeae4fbdbc9220e75ee4a4dec”
}
}

You can use Markdown for hyperlinks.
Just ask the AI to wrap all URLs into Markdown hyperlinks.

Markdown hyperlinks work like this:

[This is a hyperlink](https://n8n.io)

This is a hyperlink
.

See some screenshots:

1 Like

Thanks a bunch, you rock :slightly_smiling_face:

1 Like

Happy to help :muscle:

Please remember to mark my reply as the solution.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.