At a glance
- Trigger
- Chat Trigger (Create a simple Trigger to have the Chat button within N8N)
- Nodes
- 12
- Apps
- OpenAI
- AI nodes
- 3
- Credentials
- 1 type
- Category
- AI agents and LLM tools
Apps and integrations
Node types used
How it works
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Within N8N, there will be a chat button to test
A file retrieval request contains a lot of information, and we want only the text that will be substituted and the file name.
With the last three splits, we may have many citations and texts to substitute. By doing an aggregation, it will be possible to handle everything as a single request.
This simple code will take all the previous files and citations and alter the original text, formatting the output. In this way, we can use Markdown tags to create links, or if you prefer, we can add an HTML transformation node.
Retrieving all thread content is necessary because the OpenAI tool does not retrieve all citations upon request.
Setup notes
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
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 workflow, we will use an OpenAI assistant created within their interface, equipped with a vector store containing some files for file retrieval.
The assistant will perform the file search within the OpenAI infrastructure and will return the content with citations.
- We will make an HTTP request to retrieve all the details we need to format the text output.
Setup
Insert an OpenAI Key
How to adjust it to your needs
At the end of the workflow, we have a block of code that will format the output, and there we can add Markdown tags to create links. Optionally, we can transform the Markdown formatting into HTML.
by Davi Saranszky Mesquita
Setup
In this step, we will use an assistant created within the OpenAI platform that contains a vector store a.k.a file retrieval
Nodes in this workflow
The 12 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:
- Aggregate (Aggregate)
- Window Buffer Memory (Window Buffer Memory)
- Create a simple Trigger to have the Chat button within N8N (Chat Trigger)
- OpenAI Assistant with Vector Store (OpenAI)
- Get ALL Thread Content (HTTP Request)
- Split all message iterations from a thread (Split Out)
- Split all content from a single message (Split Out)
- Split all citations from a single message (Split Out)
- Retrieve file name from a file ID (HTTP Request)
- Regularize output (Edit Fields (Set))
- Optional Markdown to HTML (Markdown)
- Finnaly format the output (Code)
Credentials you need
- OpenAI API – used by Get ALL Thread Content, OpenAI Assistant with Vector Store and Retrieve file name from a file ID
Configure your own credentials after importing. Create each credential in n8n, then select it in the node.
How to import into n8n
- Download the JSON file with the button above.
- In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
- Open each node that shows a warning and select or create its credential.
- Read the notes on the canvas, test the workflow with sample data, then activate it.
Do you need somewhere to run it? Read our guide to self-hosted n8n.