# Local document question answering with Ollama AI: n8n workflow

> Started by someone opening a chat with it, and works across Postgres. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply...

Source: https://millionrounds.com/workflow/local-document-question-answering-with-ollama-ai (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Documents and files](https://millionrounds.com/workflows?category=Documents+and+files#library)

# Local document question answering with Ollama AI

Started by someone opening a chat with it, and works across Postgres. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 35 steps, 1 branch, 1 loop or waits: large, and worth reading before you trust it with anything live.

Large Calls a model: OpenAI Retrieval

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Flocal-document-question-answering-with-ollama-ai)

**35 steps** Large: read it before trusting it with anything live

**1** Branch: places the flow splits

**1** Loop or waits

**1** Service it connects to

## The flow

Starts it 4 Model 9 Logic 6 Service 16

The steps in the order they run, from what starts it.

- 1 **Postgres Chat Memory** Memory Postgres Chat *Model*
- 2 **When chat message received** Chat trigger *Starts it*
- 3 **Webhook** Webhook *Starts it*
- 4 **Create Document Metadata Table** Postgres *Service*
- 5 **Create Document Rows Table (for Tabular Data)** Postgres *Service*
- 6 **List Documents** Postgres Tool *Service*
- 7 **Get File Contents** Postgres Tool *Service*
- 8 **Query Document Rows** Postgres Tool *Service*
- 9 **Local File Trigger** Local File trigger *Starts it*
- 10 **Embeddings Ollama** Embeddings Ollama *Model*
- 11 **Embeddings Ollama1** Embeddings Ollama *Model*
- 12 **Recursive Character Text Splitter** Text Splitter Recursive Character Text Splitter *Model*
- 13 **Ollama (Change Base URL)** Lm Chat Open Ai *Model*
- 14 **RAG AI Agent** Agent *Model*
- 15 **Edit Fields** Set *Logic*
- 16 **Loop Over Items** Split In Batches *Logic*
- 17 **Postgres PGVector Store** Vector Store PGVector *Model*
- 18 **Postgres PGVector Store1** Vector Store PGVector *Model*
- 19 **Default Data Loader** Document Default Data Loader *Model*
- 20 **Respond to Webhook** Respond To Webhook *Starts it*
- 21 **Set File ID** Set *Logic*
- 22 **Delete Old Doc Records** Postgres *Service*
- 23 **Delete Old Data Records** Postgres *Service*
- 24 **Insert Document Metadata** Postgres *Service*
- 25 **Read/Write Files from Disk** Read Write File *Service*
- 26 **Switch** Switch *Logic*
- 27 **Extract PDF Text** Extract From File *Service*
- 28 **Extract from Excel** Extract From File *Service*
- 29 **Extract from CSV** Extract From File *Service*
- 30 **Extract Document Text** Extract From File *Service*
- 31 **Aggregate** Aggregate *Logic*
- 32 **Insert Table Rows** Postgres *Service*
- 33 **Summarize** Summarize *Service*
- 34 **Set Schema** Set *Logic*
- 35 **Update Schema for Document Metadata** Postgres *Service*

## How it's built

- **Starts on:** Someone opening a chat with it
- **Steps:** 35, with 1 branch, 1 loop or waits
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Postgres
- **Model:** OpenAI
- **Retrieval:** Answers are drawn from documents you supply, not from the model alone

## Questions

What does it need to run?

An n8n account, plus your own Postgres account, and a key for OpenAI. You connect your own accounts after importing it; none are included.

What starts it?

It starts on someone opening a chat with it.

Does it use AI?

Yes. It calls OpenAI. Its answers draw on documents you give it, not on the model alone. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 35 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 35 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Flocal-document-question-answering-with-ollama-ai)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Postgres](https://millionrounds.com/workflows?service=Postgres#library)

## Workflows like it

Also documents and files, with the same services where possible, closest in size first.

- [**Index Google Drive files into a Supabase vector store** 26 steps · calls a model · Google Drive, Postgres](https://millionrounds.com/workflow/index-google-drive-files-into-a-supabase-vector-store)
- [**Telegram AI chatbot with OpenAI and PGVector RAG** 24 steps · calls a model · Google Drive, Postgres](https://millionrounds.com/workflow/telegram-ai-chatbot-with-openai-and-pgvector-rag)
- [**Build an OpenAI RAG system with Postgres** 20 steps · calls a model · Postgres](https://millionrounds.com/workflow/build-an-openai-rag-system-with-postgres)
- [**Intelligent legal document review and compliance automation** 17 steps · calls a model · Postgres](https://millionrounds.com/workflow/intelligent-legal-document-review-and-compliance-automation)
- [**Automated document sync between SharePoint and Google Drive** 15 steps · Google Drive, Postgres](https://millionrounds.com/workflow/automated-document-sync-between-sharepoint-and-google-drive)
- [**Generate PDF documents from HTML with PDF Generator API** 10 steps · Gmail, Postgres](https://millionrounds.com/workflow/generate-pdf-documents-from-html-with-pdf-generator-api)
