Chat with local documents using Ollama and MariaDB Vector cache

Go to Workflow
0 views
Built by Quirino Scaramastra Quirino Scaramastra
Created on October 24, 2026

Description

Quick Overview
This workflow ingests documents from an FTP server into MariaDB Vector using Ollama embeddings, then provides a local chat interface that answers questions with retrieved context and caches repeated questions in a MariaDB Q&A table.

How it works
Starts a manual ingestion run that lists and downloads a file from an FTP server and extracts its text.
Sends the extracted text to an Ollama chat model to generate a short summary and assign a category from an allowed list.
Splits the document text into chunks, creates embeddings with Ollama, and inserts each chunk plus its vector and metadata into a MariaDB documents table.
Receives a question via an n8n Chat trigger and normalizes it to look up a matching answer in the MariaDB qa_cache table.
If there is no cached answer, embeds the question with Ollama and retrieves the top similar chunks from MariaDB using vector distance.
Builds a context-cited prompt from the retrieved chunks and uses an Ollama chat model to answer strictly from that context.
Stores the new answer back into qa_cache and returns either the cached or newly generated answer to the chat.

Setup
Set up a MariaDB 11.7+ database with the documents (VECTOR column) and qa_cache tables, and add an n8n MySQL/MariaDB credential.
Run Ollama and ensure the chat and embedding models are available, then set the Ollama base URL and model names in the workflow settings nodes.
Add an FTP credential and update the FTP path to point to the document(s) you want to ingest.
Adjust the allowed category list for classification and the top_k retrieval value to match your use case.

This workflow was created by Quirino Scaramastra and shared publicly on the n8n community template library. n8nFind indexes it for discovery — the workflow remains the property of its original creator.

Nodes Used (13)

AI Agent
@n8n/n8n-nodes-langchain.agent
Basic LLM Chain
@n8n/n8n-nodes-langchain.chainLlm
Code
n8n-nodes-base.code
Default Data Loader
@n8n/n8n-nodes-langchain.documentDefaultDataLoader
Embeddings Ollama
@n8n/n8n-nodes-langchain.embeddingsOllama
FTP
n8n-nodes-base.ftp
HTTP Request
n8n-nodes-base.httpRequest
MySQL
n8n-nodes-base.mySql
Ollama Chat Model
@n8n/n8n-nodes-langchain.lmChatOllama
Recursive Character Text Splitter
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter
Simple Memory
@n8n/n8n-nodes-langchain.memoryBufferWindow
Simple Vector Store
@n8n/n8n-nodes-langchain.vectorStoreInMemory
Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured