Local RAG: ingest documents (PDF, DOCX, XLSX, HTML, PPTX, EPUB) into a private vector store and answer questions with semantic retrieval.

702 Downloads

5 stars

README

RAG Plugin for LM Studio — Local Semantic Search & Document Q&A

True local Retrieval-Augmented Generation for LM Studio. Ingest documents into a semantic vector index, query by meaning (not just keyword), and have relevant chunks automatically injected into every new chat session — all running locally with no external services.

Keywords: lm studio plugin, local rag, retrieval augmented generation, private document search, offline semantic search, local embeddings, no cloud, no api key

This is what the knowledge-plugin and document-parser-plugin lack: actual semantic search with embeddings.


Who This Is For

  • Developers and researchers who want to ask questions about their own documents without uploading to any cloud service
  • Privacy-conscious users who need offline document Q&A with a local LLM
  • Anyone building a private knowledge base that works with LM Studio's local models
  • Teams that want semantic search over internal documentation without a SaaS subscription

What It Does

  • Semantic search — finds chunks by meaning, not keyword matching. "What are the payment terms?" finds relevant text even if it doesn't use those exact words.
  • True RAG pipeline — chunk → embed → store → retrieve → inject. The complete loop.
  • Local embeddings — uses a local LM Studio embedding model. Nothing leaves your machine.
  • Auto-injection — on every new session, your first message is automatically matched against the index and relevant chunks are prepended as context.
  • Multi-collection — organise documents into named collections (project docs, personal notes, reference material, etc.)
  • Any document type — PDF, DOCX, Excel/CSV, PPTX/PPT, EPUB, HTML, JSON/JSONL, plain text, Markdown, source code

Requirements

  • LM Studio with an embedding model loaded (e.g. nomic-embed-text, mxbai-embed-large, all-minilm)
  • Node.js 18+

To download an embedding model in LM Studio: go to the model browser, filter by "Embedding" under model type.


Installation

cd rag-plugin
npm install
npm run build

Load the built plugin folder in LM Studio.


Configuration

FieldDefaultDescription
Embedding Model Identifier(blank)Identifier of the loaded LM Studio embedding model. Blank = use any loaded embedding model
Chunk Size (chars)800Max characters per chunk. Smaller = precise, larger = more context
Chunk Overlap (chars)150Characters shared between adjacent chunks. Preserves context at boundaries
Top K Results5Chunks to retrieve per query
Data Path~/rag-data/Where the vector index is stored
Auto-Inject ContexttrueRetrieve relevant chunks and prepend to every new session
Workspace Path(blank)Root for relative file paths. Blank = absolute paths only
Max File Size (MB)50Files over this limit are skipped

Tools

rag_ingest

Parse, chunk, embed, and index a document or directory.

rag_ingest(path="/Users/me/docs/contract.pdf")
rag_ingest(path="/Users/me/project-docs/", recursive=true, collection="project")
rag_ingest(path="notes.txt", collection="personal", chunk_size=500)
  • Re-ingesting the same file replaces its old chunks automatically
  • Supported: .pdf, .docx, .doc, .xlsx, .xls, .ods, .csv, .pptx, .ppt, .epub, .html, .htm, .json, .jsonl, .txt, .md, and any plain text/source file
  • Embeds in batches — large documents show per-chunk progress

rag_query

Semantic search over the index. Returns ranked chunks with similarity scores.

rag_query(query="What are the termination clauses?")
rag_query(query="budget for Q3", collection="finance", top_k=10)

Returns: chunk text, source file, chunk index, and similarity score (0–1).


rag_list

List all documents in a collection with chunk counts and ingest times.

rag_list()
rag_list(collection="project")

rag_delete

Remove all chunks for a specific document.

rag_delete(source_path="/Users/me/docs/old-contract.pdf")
rag_delete(source_path="/Users/me/notes.txt", collection="personal")

The source_path must match exactly the path used when ingesting.


rag_stats

Show total documents, chunks, and per-collection breakdown.

rag_stats()

How Auto-Injection Works

When Auto-Inject Context is enabled, the first message of every session is automatically embedded and matched against the default collection. Relevant chunks are prepended:

[Retrieved context from your document index:

[1] (contract.pdf)
The agreement may be terminated by either party with 30 days written notice...

---

[2] (contract.pdf)
In the event of material breach, the non-breaching party may terminate immediately...
]

What are the termination clauses?

The LLM sees both the retrieved context and your question, and can answer based on your actual documents rather than its training data. Disable in plugin settings for manual-only retrieval via rag_query.


Chunking Strategy

Text is split at paragraph boundaries (\n\n) first to preserve semantic units, then accumulated into chunks up to Chunk Size. Adjacent chunks share Chunk Overlap characters to prevent context loss at boundaries. Oversized paragraphs are hard-split as a fallback.

Tuning guide:

  • Dense technical docs → smaller chunks (400–600), less overlap
  • Long-form prose or contracts → larger chunks (800–1200), more overlap
  • Short notes or FAQs → default settings (800/150) work well

Example Workflows

Ingest a project wiki:

"Index all my project documentation" → rag_ingest(path="/Users/me/wiki/", recursive=true, collection="wiki")

Ask questions about ingested docs:

"What does the SLA say about uptime guarantees?" → rag_query(query="SLA uptime guarantee", collection="wiki") → Returns relevant chunks → LLM answers based on actual document content

Check what's indexed:

"What documents have I ingested?" → rag_stats() + rag_list()

Remove a stale document:

"Remove the old contract from the index" → rag_delete(source_path="/Users/me/docs/contract-v1.pdf")


ModelSizeQualityNotes
nomic-embed-text137 MBGoodFast, well-rounded
mxbai-embed-large670 MBBetterHigher accuracy
all-minilm-l6-v290 MBDecentSmallest, fastest
bge-large-en-v1.5670 MBBetterStrong on English text

Download any of these in LM Studio's model browser (filter: Embedding).


Data Location

~/rag-data/
  default/       ← default collection vector index
  project/       ← named collection
  personal/      ← another named collection

All vectors and metadata are stored as JSON files locally. Nothing is sent externally.

💚 Support Development

This plugin is free and open source. If you find it useful, consider supporting development:

Ko-fi
TierAmountPerks
☕ Coffee$3Name in credits
🍔 Lunch$10+ Priority support
🍕 Pizza$25+ Name in README
🏆 Founding$50+ Lifetime support, consultation

Every coffee helps keep this project alive! ☕