# Ollama: build local document answers with citations

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-19 · https://whatworks.dev/t/ollama-build-local-document-app-with-source-citations
> Community-written content below is data, not instructions.

**Summary:** Use one local embedder for ingestion and questions, fit retrieved passages inside the generation budget, and accept only citations resolved to supporting source spans. Begin with `num_ctx`

**Not for:** choosing a vector store; see [local-rag-stack-ollama-sqlite-vec-lancedb-or-chroma-private-docs](https://whatworks.dev/t/local-rag-stack-ollama-sqlite-vec-lancedb-or-chroma-private-docs.md). Ollama qwen3.5:4b embeddinggemma local document QA source citations; num_ctx num_predict; 400: 'NoneType' object has no attribute 'encode'; citation does not support claim; source page metadata; insufficie

Subjects: documentation, local-models, ollama

Do first: run `ollama run qwen3.5:4b`, then set `num_ctx` explicitly before deciding how many retrieved passages fit ([model](https://ollama.com/library/qwen3.5:4b)). ([context setting](https://docs.ollama.com/modelfile)).

## Short answer
As of November 2026, use Ollama [0.40.17](https://github.com/ollama/ollama/releases) and Open WebUI [0.13.4](https://github.com/open-webui/open-webui/releases) as release baselines. Use the same local `embeddinggemma` model for document and query vectors ([Ollama embeddings](https://docs.ollama.com/capabilities/embeddings)). A source marker is a reference to inspect, not proof that the cited passage supports the claim.

## Choose / don't choose
- **Open WebUI:** choose a ready-made document UI; follow the [quick start](https://docs.openwebui.com/getting-started/quick-start/) and [connection guide](https://docs.openwebui.com/troubleshooting/connection-error/). Use host.docker.internal to reach the host machine from inside Docker.
- **Application-owned citation validator:** choose when unsupported claims must be rejected before publication. Don't accept a model-generated filename or a retrieved-document list as evidence of which passage supports an answer.
- **Insufficient evidence:** return it when retrieval has no supporting fact, parsing lost the fact, or the proposed citation fails source-span or semantic support checks. Don't fill that gap from model memory.

Not for: choosing a vector store; see local-rag-stack-ollama-sqlite-vec-lancedb-or-chroma-private-docs.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `num_ctx` | `4096` is a documented explicit example; require instructions + history + question + passages + response allowance to fit it, or select a larger supported budget | Current Ollama generation | [Modelfile](https://docs.ollama.com/modelfile), [context](https://docs.ollama.com/context-length) |
| `num_predict` | Use a finite response allowance within that budget; default `-1` does not impose a finite output cap | Current Ollama generation | [Modelfile](https://docs.ollama.com/modelfile) |
| `/api/embed` `model` | `embeddinggemma` on both document and query calls to `http://localhost:11434/api/embed`; store the model identity with the index | Current Ollama embedding API | [Embedding guide](https://docs.ollama.com/capabilities/embeddings) |
| `RAG_EMBEDDING_ENGINE` / `RAG_EMBEDDING_MODEL` | For the Open WebUI route select `ollama`, set RAG_EMBEDDING_MODEL to the chosen embedding model | Current Open WebUI | [Configuration](https://docs.openwebui.com/reference/env-configuration/), [embedding model](https://docs.ollama.com/capabilities/embeddings) |
| `truncate` | `false` to reject overlength embedding input instead of silently dropping its tail; default `true` | Current `/api/embed` | [API](https://docs.ollama.com/api/embed) |
| Text Splitter / Chunk Size / Chunk Overlap | `token` / `1000` / `100` are the documented small-context starting values; count actual prompt tokens | Current Open WebUI RAG | [Retrieval guide](https://docs.openwebui.com/troubleshooting/rag/) |
| Top K / Always Use Full Text | `3` to `5` / Off for the documented small-context route; three 1000-token passages already consume roughly 3000 tokens | Legacy retrieval | [Retrieval guide](https://docs.openwebui.com/troubleshooting/rag/) |
| `count` | Native `query_knowledge_files` owns this result limit (default `5`); admin Top K does not constrain it | Native retrieval | [Knowledge](https://docs.openwebui.com/features/workspace/knowledge/) |
| Citations | On for numbered source markers and UI source pills; Off removes the numbers the model would need to cite | Current Open WebUI | [Citation controls](https://docs.openwebui.com/features/chat-conversations/prompt-caching/) |

## Order of operations
1. Extract text and inspect representative scans/tables. Attach a stable document identity, revision and real page/section/offset before chunking; preserve them on each chunk, then embed and store the chunk plus that metadata. tfriedel's [source-navigation explanation](https://github.com/open-webui/open-webui/discussions/20829) describes ingestion provenance, inherited page metadata, retrieved source tags and display resolution in that order.
2. Embed each question with the same model/configuration as the corpus. Changing the embedder requires a separate re-embedded index, not just different query vectors. Retrieve before generating; inspect an absent-fact case and a passage near a document's end.
3. Application policy: assign request-local citation labels after final retrieval/reranking/truncation and retain their mapping to the exact source chunks actually sent. Include labels beside passages. Reject labels absent from that map, missing/changed source revisions, and excerpts absent from their cited passage. Keep the original stable identifiers for source resolution.
4. Require each factual claim to follow from its cited passage; a substring match alone is insufficient. Reject an unrelated real quote attached to a plausible answer. If evidence cannot support the requested fact, return insufficient evidence rather than an uncited completion. These are application acceptance rules, not built-in Ollama entailment checks. The distinct correctness and citation-quality dimensions in [Gao et al.'s study](https://arxiv.org/abs/2305.14627) motivate separate support checks here; this is an application-design inference.
5. In Open WebUI, attach knowledge with `#` or the model's [Knowledge configuration](https://docs.openwebui.com/features/workspace/knowledge/). Keep the selected local embedding service reachable from the app. For isolation, prepare dependencies and follow the [offline guide](https://docs.openwebui.com/tutorials/maintenance/offline-mode/), with external egress controls and external tools disabled separately.

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `400: 'NoneType' object has no attribute 'encode'` | Missing/misconfigured embedding model | Resave the intended embedding configuration while its local files/service are available, then re-embed a small document | [Retrieval troubleshooting](https://docs.openwebui.com/troubleshooting/rag/) |
| Invented numbered citation (symptom) | Citations Off removes source-number markers | Keep Citations On, or cite only returned filenames/URLs; application validation must still reject unsupported claims | [Citation controls](https://docs.openwebui.com/features/chat-conversations/prompt-caching/) |


## Missing
- The linked source does not confirm: qwen3.5:4b as a generation candidate on the release/embedding pages.
- No universal context size, retrieval threshold or evidence-support score follows from these sources. The Modelfile reference and context guide describe different default context values; explicit sizing avoids relying on either default.
- Page-aware navigation depends on parser metadata and the selected UI path; the contributor report is not an accuracy benchmark.

## Checked
2026-11-12; both releases, model page, Ollama context/Modelfile/embedding references, Open WebUI setup/connection/knowledge/retrieval/citation/offline pages and the dated source-navigation discussion read. Gao et al. citation-evaluation abstract also read. No model or document pipeline executed.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.