README
rag-v2 is a document-grounded RAG project for LM Studio with two supported integration modes:
The repository uses a workspace layout:
packages/core: transport-agnostic retrieval, ranking, evidence, and policy logicpackages/adapter-lmstudio: LM Studio plugin adapter and prompt-preprocessor flowpackages/mcp-server: MCP server adapter and stdio entrypointThe goal is to keep one shared RAG implementation while supporting both LM Studio plugin workflows and MCP-hosted tool workflows.
When users provide documents, rag-v2 can:
This makes easy cases faster, large-document cases more selective, and weak-evidence cases more grounded.
The system chooses between:
Before retrieval, prompts can be classified as:
no-retrieval-neededambiguouslikely-unanswerableretrieval-usefulThis reduces unnecessary retrieval and helps avoid confident answers that are not actually grounded in the provided documents.
For retrieval-heavy prompts, the system can generate multiple query variants such as:
These variants are fused into a shared candidate pool to improve recall.
Hybrid mode combines:
This is especially useful for exact phrases, rare terms, section titles, and quoted spans.
After retrieval, candidates can be:
The reranker favors answer-useful evidence, not just semantic similarity.
Instead of injecting raw retrieved text, the system:
Retrieved content is treated as untrusted input. The system can:
Grounding modes currently include:
offwarn-on-weak-evidencerequire-evidencepackages/ core/ adapter-lmstudio/ mcp-server/ src/ index.ts scripts/ eval/ manual-tests/ examples/
Important note:
src/index.ts is an intentional LM Studio plugin-root entry shimpackages/adapter-lmstudio/src/index.tsAll other legacy compatibility shims have been removed.
At a high level:
Most LM Studio-facing orchestration lives in packages/adapter-lmstudio/src/promptPreprocessor.ts. Shared retrieval and policy logic lives in packages/core/src/.
Use this when you want document-aware prompt preprocessing directly inside LM Studio.
Run the plugin in dev mode:
npm run dev:plugin
Publish or update the plugin:
npm run push:plugin
Use this when you want to expose RAG functionality as MCP tools to LM Studio MCP or another local MCP-compatible host.
Run the stdio MCP server:
npm run mcp:stdio
This exposes four tools:
rag_answerrag_searchcorpus_inspectrerank_onlyImportant for MCP mode:
documents, filesystem paths, and pre-supplied chunksA ready-to-copy example is included at:
examples/lmstudio.mcp.json
{ "mcpServers": { "rag-v2-local": { "command": "npm", "args": ["run", "mcp:stdio"], "cwd": "C:\\Users\\user\\projects\\rag-v2" } } }
{ "mcpServers": { "rag-v2-local": { "command": "wsl.exe", "args": [ "-d", "Ubuntu-24.04-D", "bash", "-lc", "cd /home/user/projects/temp/ai-apps/rag-v2 && npm run mcp:stdio" ] } } }
Replace the path values with the ones for your machine.
npm run dev:plugin npm run push:plugin npm run mcp:stdio npm run typecheck npm run eval
npm run typecheck:core npm run typecheck:adapter npm run typecheck:mcp npm run typecheck:packages
typecheck:core validates the shared core packagetypecheck:adapter validates the LM Studio adapter packagetypecheck:mcp validates the MCP packagetypecheck:packages validates all workspace packagestypecheck validates all packages plus the root plugin shimnpm run smoke:multi-query npm run smoke:evidence npm run smoke:safety npm run smoke:rerank npm run smoke:hybrid npm run smoke:corrective npm run smoke:core npm run smoke:core-policy npm run smoke:mcp npm run smoke:mcp-filesystem npm run smoke:model-rerank
These are intended to verify deterministic slices of the pipeline quickly.
Run the lightweight regression harness with:
npm run eval
Inputs live in eval/cases/.
Latest aggregated output is written to:
eval/results/all-latest.json
Current suites include:
basic.jsonlhard.jsonlFor live testing in LM Studio, use:
LIVE_TEST_SCRIPT.mdmanual-tests/README.mdmanual-tests/fixtures/The LM Studio plugin exposes configuration in the LM Studio UI.
packages/adapter-lmstudio/src/promptPreprocessor.ts: main LM Studio prompt-preprocessor pipelinepackages/adapter-lmstudio/src/: LM Studio adapter logic and local typespackages/core/src/: shared retrieval, ranking, evidence, and policy logicpackages/mcp-server/src/: MCP contracts, handlers, runtimes, and stdio server entrypointssrc/index.ts: intentional repo-root LM Studio plugin entry shimscripts/: smoke tests and eval runnerexamples/lmstudio.mcp.json: LM Studio MCP config examplemanual-tests/: live-test fixtures and guidanceThe repository currently includes:
the_almighty_shade (187893603920642048)