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.
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'Read Full Reproducible Guide →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.
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'- • 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
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-dimensionEach 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.
- Lock your embedding model to `bge-m3` (1024-dim) for bilingual ZH/EN corpora.
- 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.
ollama psFix: Raise Chat Model num_ctx to >= 8192 to Stop Silent Prompt Head Truncation
sol-rag-num-ctx-truncationOllama 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.
- Set `num_ctx: 8192` (or `16384`) in your chat model parameters or Modelfile.
- 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.
ollama psFix: Route Scanned PDFs & Complex Tables Through Local Vision LLM (Qwen2.5-VL) or Docling
sol-rag-scanned-pdf-vlmStandard 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.
- Check if `pdftotext file.pdf - | wc -c` returns < 50 characters per page (indicating a scanned image PDF).
- 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.
ollama run qwen2.5vl:7b "Describe this table in Markdown"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.
Linux / macOS / Windows WSL2 · Ollama 0.5.7 · Open WebUI / Dify / Continue (ChromaDB, Qdrant, PGVector)
Ollama 0.5.7 · bge-m3 (1024-dim) · nomic-embed-text (768-dim) · mxbai-embed-large (1024-dim)
100% Local Vector DB & GPU Process Diagnostics — All vector dimension probes and GPU process checks run locally via curl and nvidia-smi.