Build a Tax Code Assistant with Qdrant, Mistral.ai and OpenAI n8n Workflow Template

n8n workflow template · 31 nodes · Mistral AI

Build a Tax Code Assistant with Qdrant, Mistral.ai and OpenAI is a free n8n workflow template that runs when another workflow calls it and works with Mistral AI, Qdrant and OpenAI. It has 31 nodes, 11 of them AI nodes (Mistral Cloud Embeddings, Default Data Loader, Recursive Character Text Splitter and Qdrant Vector Store). The notes inside the workflow say: “Join the Discord or ask in the Forum!” To run it, you add your own credentials for Mistral Cloud API, OpenAI API and Qdrant API.

At a glance

Trigger
Execute Workflow Trigger (Execute Workflow Trigger)
Nodes
31
Apps
Mistral AI, Qdrant and OpenAI
AI nodes
11
Credentials
3 types
Category
RAG, documents and vector search

Apps and integrations

  • Mistral AI
  • Qdrant
  • OpenAI

Node types used

  • Manual Trigger
  • Mistral Cloud Embeddings
  • Default Data Loader
  • Recursive Character Text Splitter
  • HTTP Request
  • Compression
  • Split Out
  • Extract from File
  • Edit Fields (Set)
  • Execute Workflow Trigger
  • Loop Over Items
  • Filter
  • Qdrant Vector Store
  • AI Agent
  • Window Buffer Memory
  • Chat Trigger
  • OpenAI Chat Model
  • Wait
  • Call n8n Workflow Tool
  • Switch

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.

Try Me Out!

This workflow builds an AI powered Legal assistant who answers questions about tax codes.

  • Download publically available tax code PDFs from the relevant government website.
  • Strategically exact tax code sections and store these in our Qdrant Vectorstore using Mistral.ai embeddings.
  • Use an AI Agent to answer user's tax questions by attaching tools which query our Qdrant vectorstore.

Need Help?

Join the Discord or ask in the Forum!

Step 1. Download the Tax Code PDF

Read more about handling Zip Files

Let's begin by pulling a zip file containing all the tax codes as separate PDF files. We can unzip on the fly with n8n's compression node.

Step 4. Build a Tax Code Assistant ChatBot

Learn more about using AI Agents in n8n

For our chatbot, we'll use an AI agent node because we want to achieve more than one functionality. The first will be querying to relevant texts to answer a user's question and secondly, a direct search feature to pull full section text when requested.

Step 2. Extract and Partition Into Chapters & Sections

Learn more about reading PDF Files

Rather than ingest the raw text of the PDF, we'll be a little more strategic and extract the tax code sections separately instead. Not only will this provide cleaner results, we'll also be able to fetch sections in isolation if required.

What's the difference?

With raw PDF data, we may blur the boundaries between chapters and sections making later results hard to find, incoherent or misleading. Depending on your use-case, store your data in a way you intend to retrieve it!

Step 5. Use Qdrant API as Tools

Learn more about using AI Agents in n8n

Our Ask Tool will generate embeddings using Mistral.ai and query our Qdrant collection using the Qdrant Search API. Our Search Tool will use filter our Qdrant collection using the Qdrant Scroll API, matching on each doc's section metadata key.

Step 3. Save into Qdrant VectorStore

Read more about using the Qdrant Vectorstore

We'll save our data into a Qdrant collection being mindful to use metadata to take full advantage of Qdrant's filtering capabilities later. Though not always required, since the tax code documents can be quite large we'll implement a loop here to throttle the number of tokens being processed as to not trip the Mistral.ai rate limits for embeddings.

Nodes in this workflow

The 31 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. When clicking ‘Test workflow’ (Manual Trigger)
  2. Embeddings Mistral Cloud (Mistral Cloud Embeddings)
  3. Default Data Loader (Default Data Loader)
  4. Recursive Character Text Splitter (Recursive Character Text Splitter)
  5. Get Tax Code Zip File (HTTP Request)
  6. Extract Zip Files (Compression)
  7. Files as Items (Split Out)
  8. Extract PDF Contents (Extract from File)
  9. Extract From Chapter (Edit Fields (Set))
  10. Map To Sections (Edit Fields (Set))
  11. Execute Workflow Trigger (Execute Workflow Trigger)
  12. Get Mistral Embeddings (HTTP Request)
  13. Content Chunking @ 50k Chars (Edit Fields (Set))
  14. Split Out Chunks (Split Out)
  15. For Each Section... (Loop Over Items)
  16. Sections To List (Split Out)
  17. Only Valid Sections (Filter)
  18. Use Qdrant Search API1 (HTTP Request)
  19. Use Qdrant Scroll API (HTTP Request)
  20. Get Search Response (Edit Fields (Set))
  21. Qdrant Vector Store (Qdrant Vector Store)
  22. AI Agent (AI Agent)
  23. Window Buffer Memory (Window Buffer Memory)
  24. When chat message received (Chat Trigger)
  25. Window Buffer Memory1 (Window Buffer Memory)
  26. OpenAI Chat Model (OpenAI Chat Model)
  27. 1sec (Wait)
  28. Ask Tool (Call n8n Workflow Tool)
  29. Search Tool (Call n8n Workflow Tool)
  30. Switch (Switch)
  31. Get Ask Response (Edit Fields (Set))

Credentials you need

  • Mistral Cloud API – used by Embeddings Mistral Cloud and Get Mistral Embeddings
  • OpenAI API – used by OpenAI Chat Model
  • Qdrant API – used by Qdrant Vector Store, Use Qdrant Scroll API and Use Qdrant Search API1

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. 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.
  3. Open each node that shows a warning and select or create its credential.
  4. 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.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us