OpenAI assistant n8n file citations for RAG
This n8n workflow cleans up answers from an OpenAI assistant that searches vector store files, turning its citation markers into readable sources. It is for builders of document chatbots who want each answer to show which file it came from, formatted in Markdown or HTML.
What it does
A chat trigger sends the question to an OpenAI assistant with a vector store and buffer memory. The flow then reads the full thread over HTTP, splits out each message and its content, looks up the cited files and replaces the odd characters the assistant inserts with numbered references.
How to use it
Use the chat button inside n8n to test, and connect an OpenAI credential and an assistant that already has files in its vector store.
More in ChatGPT and the n8n workflow library.
Full text
Front matter
name: Make OpenAI Citation for File Retrieval RAG
description: Triggered manually or by an app event. Connects Aggregate, Code, HTTP request, Markdown, Split Out. ## Within N8N, there will be a chat button to test ## Make OpenAI Citation for File Retrieval RAG ## Use case In this example, we will ensure that all texts from the OpenAI assistant search for citations and sources in the vector store files. We can also format the output for Markdown or HTML tags. This is necessary because the assistant sometimes generates strange characters, and we can also use dynamic references such as citations 1, 2, 3, for example. ## What this workflow does In this w
category: Automation
kind: Workflow
software: Aggregate|Code|HTTP request|Markdown|Split OutMake OpenAI Citation for File Retrieval RAG
Triggered manually or by an app event. Connects Aggregate, Code, HTTP request, Markdown, Split Out. ## Within N8N, there will be a chat button to test ## Make OpenAI Citation for File Retrieval RAG
Use case
In this example, we will ensure that all texts from the OpenAI assistant search for citations and sources in the vector store files. We can also format the output for Markdown or HTML tags.
This is necessary because the assistant sometimes generates strange characters, and we can also use dynamic references such as citations 1, 2, 3, for example.
What this workflow does
In this w
Steps
- Manual Trigger (manualTrigger)
- Aggregate (aggregate)
- Window Buffer Memory (noOp)
- Sticky Note4 (stickyNote)
- Sticky Note (stickyNote)
- Create a simple Trigger to have the Chat button within N8N (noOp)
- OpenAI Assistant with Vector Store (noOp)
- Sticky Note1 (stickyNote)
- Get ALL Thread Content (httpRequest)
- Sticky Note2 (stickyNote)
- Split all message iterations from a thread (splitOut)
- Split all content from a single message (splitOut)
- Split all citations from a single message (splitOut)
- Retrieve file name from a file ID (httpRequest)
- Regularize output (set)
- Sticky Note3 (stickyNote)
- Sticky Note5 (stickyNote)
- Sticky Note6 (stickyNote)
- Optional Markdown to HTML (markdown)
- Finnaly format the output (code)
Import
Download the JSON from the GitHub source and import it in n8n (Workflows, Import from file).
Source and license
Source: https://github.com/Zie619/n8n-workflows/blob/main/Splitout/1059_Splitout_Code_Automation_Webhook.md
Author: Zie619, n8n workflow collection. License: MIT.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
- Automated Research Report Generation with OpenAI, Wikipedia, Google Search, and Gmail/Telegram
- Extractfromfile Workflow: ChatGPT, n8n and Extract From File (n8n workflow collection) (Http) (1135)
- Extractfromfile Workflow: ChatGPT, n8n and Extract From File (n8n workflow collection) (Http) (1183)
- Chat with GitHub OpenAPI Specification using RAG (Pinecone and OpenAI)
- OpenAI Assistant with custom n8n tools
- Automated Resume Review System Using OpenAI + Google Sheets
There are more like this in the members library
The n8n workflow library holds 1,814 entries. Members can search all of them by meaning and read every one in full.