TinkerLab
DIAGNOSTIC TREE // RAG-EMPTY-HALLUCINATION-CITATION (3 ROOT CAUSES)

Local RAG Returns Empty Results, Dimension Error (1024 vs 768) or Misses Retrieved Facts

Diagnose vector dimension mismatches after switching embedding models, silent num_ctx=2048 prompt head truncation, and scanned PDF zero-text layers.

[KEY VERIFIED TAKEAWAY / TL;DR]This diagnostic decision tree for "Local RAG Returns Empty Results, Dimension Error (1024 vs 768) or Misses Retrieved Facts" provides 4 interactive nodes and 3 hardware-verified root-cause fixes (Fix: Rebuild Vector Collection After Switching Embedding Models (Never Mix Dimensions); Fix: Raise Chat Model num_ctx to >= 8192 to Stop Silent Prompt Head Truncation; Fix: Route Scanned PDFs & Complex Tables Through Local Vision LLM (Qwen2.5-VL) or Docling), paired with our reproducible guide "embedding-dimension-mismatch-and-zombie-vram".
Local RAG Returns Empty Results, Dimension Error (1024 vs 768) or Misses Retrieved Facts
Step 1: What Symptom Do You Observe When Querying Your Local Knowledge Base?

Check your RAG UI (Open WebUI / Dify / AnythingLLM) citations panel and container logs:

Diagnostic Probe Command
curl -s http://127.0.0.1:11434/api/embed -d '{"model":"bge-m3","input":"test"}' | jq '.embeddings[0] | length'

Select what your environment outputs:
DIAGNOSTIC PROBE SEQUENCE // 完整分步探测命令与症状分支

All 1 Terminal Diagnostic Probes in "Local RAG Returns Empty Results, Dimension Error (1024 vs 768) or Misses Retrieved Facts"

Complete static reference of every read-only probe command, baseline hint, and branch transition in this decision tree.

Step 1: What Symptom Do You Observe When Querying Your Local Knowledge Base?step-rag-symptom

Check your RAG UI (Open WebUI / Dify / AnythingLLM) citations panel and container logs:

curl -s http://127.0.0.1:11434/api/embed -d '{"model":"bge-m3","input":"test"}' | jq '.embeddings[0] | length'
Symptom Branches:
  • • Throws "InvalidDimensionException: Embedding dimension 1024 does not match collection 768/384"→ sol-rag-reindex-dimension
  • • UI Citations panel shows the exact right chunk, yet the LLM replies "Not mentioned in document"→ sol-rag-num-ctx-truncation
  • • Uploading a PDF succeeds, but retrieval returns 0 chunks or garbled table numbers→ sol-rag-scanned-pdf-vlm
ALL VERIFIED FIXES IN THIS TREE // 本树涵盖的全部根因与修复方案一览

3 Verified Root Causes, Fix Configs & Commands in "Local RAG Returns Empty Results, Dimension Error (1024 vs 768) or Misses Retrieved Facts"

Fix: Rebuild Vector Collection After Switching Embedding Models (Never Mix Dimensions)

sol-rag-reindex-dimension

Each embedding model outputs a fixed vector dimension (`all-MiniLM-L6-v2` = 384, `nomic-embed-text` = 768, `bge-m3` = 1024). Existing ChromaDB/pgvector collections remain locked to the dimension of the model used when the first document was uploaded.

  1. Lock your embedding model to `bge-m3` (1024-dim) for bilingual ZH/EN corpora.
  2. Delete and recreate the knowledge collection (or click "Reset Vector DB & Re-index" in Admin Settings) so all chunks are re-embedded at 1024 dimensions.
# Verify exact output dimension of your active Ollama embedding model:
curl -s http://127.0.0.1:11434/api/embed \
  -d '{"model":"bge-m3","input":"dimension check"}' | python3 -c '
import sys, json
vecs = json.load(sys.stdin).get("embeddings", [[]])
print("Embedding Dimension:", len(vecs[0]))
'

[BOUNDARY]Even if two different models both output 768 dimensions, their vector spaces are incompatible—switching models ALWAYS requires full re-indexing.

Verify: ollama ps

Fix: Raise Chat Model num_ctx to >= 8192 to Stop Silent Prompt Head Truncation

sol-rag-num-ctx-truncation

Ollama defaults every model to `num_ctx = 2048` unless overridden. When your RAG app prepends 5–8 retrieved chunks (~3,500 tokens) + system instructions, Ollama silently drops the earliest tokens (your top-ranked chunks!) so the LLM never sees them.

  1. Set `num_ctx: 8192` (or `16384`) in your chat model parameters or Modelfile.
  2. Enable `OLLAMA_FLASH_ATTENTION=1` and `OLLAMA_KV_CACHE_TYPE=q8_0` so the larger context + co-loaded `bge-m3` model stay 100% on GPU.
# Create a RAG-ready 16K context Modelfile
cat << 'EOF' > Modelfile.rag
FROM qwen2.5:14b-instruct-q4_K_M
PARAMETER num_ctx 16384
PARAMETER temperature 0
EOF
ollama create qwen2.5-14b-rag -f Modelfile.rag

[BOUNDARY]Check the CONTEXT column in `ollama ps` during a RAG query to confirm the server actually allocated 8192/16384 tokens.

Verify: ollama ps

Fix: Route Scanned PDFs & Complex Tables Through Local Vision LLM (Qwen2.5-VL) or Docling

sol-rag-scanned-pdf-vlm

Standard PDF parsers (`pypdf` / `pdfminer`) only read embedded character streams. Scanned PDFs yield 0 characters, while two-column PDFs merge left and right columns across the same horizontal Y-coordinate.

  1. Check if `pdftotext file.pdf - | wc -c` returns < 50 characters per page (indicating a scanned image PDF).
  2. Rasterize pages at 150 DPI (`pdftoppm -png -r 150`) and extract clean Markdown tables via local `qwen2.5vl:7b` before indexing into your RAG store.
# Check if PDF has an embedded text layer (if close to 0, it's a scanned image PDF):
pdftotext sample.pdf - | wc -c

# Rasterize at 150 DPI for local Vision LLM OCR:
pdftoppm -png -r 150 sample.pdf ./page

[BOUNDARY]Rasterizing at 150 DPI (~1240×1754 px) is the accuracy/VRAM sweet spot; 300+ DPI quadruples visual tokens without improving OCR accuracy.

Verify: ollama run qwen2.5vl:7b "Describe this table in Markdown"
PAIRED REPRODUCIBLE GUIDE // 配套实测指南与硬件环境基线

Troubleshooting RAG Embedding Dimension Mismatch (1024 vs 768) & Zombie VRAM Allocation

Fix the two most common post-setup local AI failures: Chroma/PGVector dimension mismatch errors after changing embedding models, and GPU VRAM staying 95% full when ollama ps shows zero models.

TESTED HARDWARE & OS

Linux / macOS / Windows WSL2 · Ollama 0.5.7 · Open WebUI / Dify / Continue (ChromaDB, Qdrant, PGVector)

PINNED STACK VERSIONS

Ollama 0.5.7 · bge-m3 (1024-dim) · nomic-embed-text (768-dim) · mxbai-embed-large (1024-dim)

VERIFIED (2026-10-26)

100% Local Vector DB & GPU Process Diagnostics — All vector dimension probes and GPU process checks run locally via curl and nvidia-smi.