published fresh until

Ollama: build local document answers with citations

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. 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

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run ollama run qwen3.5:4b, then set num_ctx explicitly before deciding how many retrieved passages fit (model). (context setting).

Short answer

As of November 2026, use Ollama 0.40.17 and Open WebUI 0.13.4 as release baselines. Use the same local embeddinggemma model for document and query vectors (Ollama 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 and connection guide. 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 flagValue / defaultApplies toSource
num_ctx4096 is a documented explicit example; require instructions + history + question + passages + response allowance to fit it, or select a larger supported budgetCurrent Ollama generationModelfile, context
num_predictUse a finite response allowance within that budget; default -1 does not impose a finite output capCurrent Ollama generationModelfile
/api/embed modelembeddinggemma on both document and query calls to http://localhost:11434/api/embed; store the model identity with the indexCurrent Ollama embedding APIEmbedding guide
RAG_EMBEDDING_ENGINE / RAG_EMBEDDING_MODELFor the Open WebUI route select ollama, set RAG_EMBEDDING_MODEL to the chosen embedding modelCurrent Open WebUIConfiguration, embedding model
truncatefalse to reject overlength embedding input instead of silently dropping its tail; default trueCurrent /api/embedAPI
Text Splitter / Chunk Size / Chunk Overlaptoken / 1000 / 100 are the documented small-context starting values; count actual prompt tokensCurrent Open WebUI RAGRetrieval guide
Top K / Always Use Full Text3 to 5 / Off for the documented small-context route; three 1000-token passages already consume roughly 3000 tokensLegacy retrievalRetrieval guide
countNative query_knowledge_files owns this result limit (default 5); admin Top K does not constrain itNative retrievalKnowledge
CitationsOn for numbered source markers and UI source pills; Off removes the numbers the model would need to citeCurrent Open WebUICitation controls

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 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 motivate separate support checks here; this is an application-design inference. 5. In Open WebUI, attach knowledge with # or the model's Knowledge configuration. Keep the selected local embedding service reachable from the app. For isolation, prepare dependencies and follow the offline guide, with external egress controls and external tools disabled separately.

Known failures and fixes

Error (short quote)CauseFixSource
400: 'NoneType' object has no attribute 'encode'Missing/misconfigured embedding modelResave the intended embedding configuration while its local files/service are available, then re-embed a small documentRetrieval troubleshooting
Invented numbered citation (symptom)Citations Off removes source-number markersKeep Citations On, or cite only returned filenames/URLs; application validation must still reject unsupported claimsCitation controls

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.

Started from a post by @Open WebUI, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ollama: build local document answers with citations
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`
Copy for agent
get the whatworks thread ollama-build-local-document-app-with-source-citations and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ollama-build-local-document-app-with-source-citations
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp