coverage-verified-rag-indexer
Skill1 starsChanged 5 months agoMITView on GitHub
Build a local RAG document indexer that NEVER silently drops chunks — block-structured stages with per-stage error attribution, a coverage check (stored count == chunk count) before a job is marked done, OCR-capable extraction, token-based chunking, and an atomic job claim so two workers can't double-process. Use when building or debugging a document → embeddings → vector DB pipeline, or when retrieval quality is bad because indexing failed silently. Trigger on "build a RAG indexer", "embeddings worker", "chunks missing / duplicated", "Milvus/Qdrant ingest", or "reindex pipeline".
In this repository2 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
After insert + flush, query the vector DB for count(doc, version) and assert it equals the number of chunks.
- Very specific: line 34
Use an OCR-capable parser (e.g.
- Very specific: line 35
If extraction returns near-nothing, fail at extract (flag needs_ocr) instead of embedding a blank doc.
- Distinctive: line 59
Every indexed doc is provably complete (count-verified), failures name their stage, and duplication can't slip through.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Coverage-Verified RAG Indexer
Most RAG indexers fail silently — a crash mid-batch, a dropped insert, a duplicate run — and you only find out when answers are bad. This pattern makes failures loud and impossible to miss.
Pipeline (block-structured stages)
resolve_file → extract (OCR) → chunk → embed (batched+retry) → upsert → verify_coverage → mark_complete
Each stage raises StageError(stage, msg). On failure, record which stage + the message into the job
row (error_stage, error_msg). No more "it just hangs" — you always know where it broke.
The key idea: coverage verification
After insert + flush, query the vector DB for count(doc, version) and assert it equals the number of
chunks. Mismatch → the job FAILS (it never marks complete, so a corrupt index is never served):
stored = count_in_vectordb(doc, version)
if stored != len(chunks):
raise StageError("verify", f"coverage mismatch: stored {stored} of {len(chunks)}")This single check catches dropped chunks, partial inserts, and duplication (e.g. a 2× count from two workers).
Extraction — handle real documents
Use an OCR-capable parser (e.g. Docling) so scanned/image PDFs and .docx tables don't yield empty text.
If extraction returns near-nothing, fail at extract (flag needs_ocr) instead of embedding a blank doc.
Chunking — measure in TOKENS, not characters
Chunk with the embedding model's own tokenizer, target 500–1000 tokens (e.g. 800) with ~20% overlap, or use a structure-aware chunker (Docling HybridChunker) that respects headings. Char-based chunking lies: 1200 chars ≈ 300 tokens, far below target.
Concurrency — claim jobs atomically
A polling worker MUST claim jobs atomically, or two instances grab the same job and double-insert (the classic 2× coverage failure). With Postgres:
UPDATE jobs SET status='processing'
WHERE id = (SELECT id FROM jobs WHERE status='queued' ORDER BY id LIMIT 1 FOR UPDATE SKIP LOCKED)
RETURNING ...;Operational gotchas
- Auto-ingest by watching a folder + content hash (only re-index new/changed files); dedup against a clearable state table, NOT an append-only audit ledger (or you can't reset).
- Run one instance under launchd/systemd (the atomic claim is the real safety net).
- Derive doc identity from the real filename (slug), not a hand-typed map — spacing/casing mismatches bite.
- Vector DB query windows are capped (e.g. Milvus offset+limit ≤ 16384) — count via iteration for big corpora.
Result
Every indexed doc is provably complete (count-verified), failures name their stage, and duplication can't slip through. That's the difference between a demo RAG and one you can trust.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

