A simple, fully offline Retrieval-Augmented Generation (RAG) pipeline for local use. It parses technical documents (PDF, DOCX, PPTX, etc.), chunks them intelligently, builds a BM25 sparse index and dense FAISS embeddings, and queries them with a hybrid retrieval pipeline.
- Multi-format parsing — supports PDF, DOCX, PPTX, and more via lightweight offline parsers.
- Hybrid chunking — combines structural boundaries with overlapping windows to preserve context.
- BM25 index — builds an inverted index with pre-computed IDF tables, 100% offline.
- Dense embeddings — encodes chunks with
BAAI/bge-small-en-v1.5for semantic search. - Incremental caching — SHA-256 fingerprints skip unchanged documents on re-runs, stored in a sidecar cache.
- Hybrid retrieval — fuses BM25 keyword scores and dense embedding cosine similarity via Reciprocal Rank Fusion (RRF).
- Cross-encoder reranking — re-scores top candidates with
cross-encoder/ms-marco-MiniLM-L-6-v2for better relevance. - Parent-child expansion — pulls in surrounding context for headings and structural elements.
- Pseudo-relevance feedback (PRF) — automatically expands queries with distinctive terms from top initial results.
- MMR diversity — optional Maximal Marginal Relevance to balance similarity and result diversity.
- Semantic deduplication — removes near-duplicate chunks before returning results.
flowchart LR
subgraph Ingest ["Ingestion (ingest.py)"]
docs["Documents<br/>(PDF, DOCX, PPTX)"] --> parse["Parse & Chunk<br/>(structural + recursive)"]
parse --> bm25["BM25 Index<br/>(Okapi k1=1.5, b=0.75)"]
parse --> embed["Dense Embeddings<br/>(BAAI/bge-small-en-v1.5)"]
embed --> faiss["FAISS Index<br/>(IndexFlatIP)"]
end
subgraph Query ["Query (query.py)"]
q["User Query"] --> clean["Clean & Expand<br/>(PRF top-3 terms)"]
clean --> dual["BM25 + Dense Search<br/>(RRF k=60)"]
dual --> rerank["Cross-Encoder Rerank<br/>(ms-marco-MiniLM-L-6-v2)"]
rerank --> expand["Parent-Child Expansion"]
expand --> dedup["Semantic Deduplication<br/>(cosine > 0.92)"]
end
bm25 --> dual
faiss --> dual
rag-basic-local/
├── ingest.py # Offline document ingestion and indexing
├── query.py # Hybrid BM25 + dense search and reranking
├── requirements.txt # Python dependencies
├── SKILL.md # Agent skill definition for VS Code Copilot
└── QUERY_WORKFLOW.md # Detailed query workflow documentation
The pipeline requires a single environment variable pointing to your workspace directory. This directory should contain:
in/— folder with source documents to ingestout/— folder where index and embedding files are written
$env:RAG_PATH = "C:\Users\YourName\Documents\rag-workspace"set RAG_PATH=C:\Users\YourName\Documents\rag-workspaceexport RAG_PATH="/home/username/rag-workspace"# Default: read from ./in, write to ./out/rag_output.json
python ingest.py
# Custom paths and options
python ingest.py /path/to/documents --output /path/to/output.json --chunk-threshold 768 --overlap-ratio 0.15 --force# Basic BM25 query
python query.py "search terms"
# Full hybrid pipeline with all features
python query.py "compressor shock waves" --json --mode hybrid --rerank --parent-child --prf --top-k 10Copy rag-query/SKILL.md into your assistant's skills/prompts folder so it can invoke the query pipeline automatically.
| Assistant | Skills / Prompts Folder |
|---|---|
| VS Code Copilot | .github/skills/rag-query/SKILL.md (workspace only) |
| OpenCode | ~/.config/opencode/skills/ (global) or .opencode/skills/ (repo) |
| Claude Code | ~/.claude/skills/ (global) or .claude/skills/ (repo) |
| Continue.dev | ~/.continue/ (global) or .continue/ (repo) |
| Custom agents | Any skill/prompt folder your agent reads from |
RAG_PATHmust be set so the agent can locateout/rag_output.jsonandout/rag_embeddings.faiss.- The agent should clean user queries (strip filler words) before passing them to
query.py. - The agent should synthesize answers with inline citations like
[source_document, pg. page_range].
Install all requirements (preferably in a virtual environment):
pip install -r requirements.txtKey dependencies:
sentence-transformers— embedding and cross-encoder modelsfaiss-cpu— dense vector similarity searchpymupdf,python-docx,python-pptx— document parsingnumpy— numerical operations
See LICENSE file for details.