See llms.txt for all machine-readable content.

Back to Templates

Chat with local documents using Ollama and MariaDB Vector cache

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

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

Setup

  1. Set up a MariaDB 11.7+ database with the documents (VECTOR column) and qa_cache tables, and add an n8n MySQL/MariaDB credential.
  2. 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.
  3. Add an FTP credential and update the FTP path to point to the document(s) you want to ingest.
  4. Adjust the allowed category list for classification and the top_k retrieval value to match your use case.