Forked from dirty-data/rag-v2
Project Files
README.md
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/lmstudio-shared: LM Studio-specific shared helpers reused by plugin and MCP runtimespackages/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-evidenceImportant 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:
Publish or update the 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:
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:
wsl.exeReplace the path values with the ones for your machine.
typecheck:core validates the shared core packagetypecheck:adapter validates the LM Studio adapter packagetypecheck:mcp validates the MCP packagetypecheck:lmstudio-shared validates the LM Studio shared helper packagetypecheck:packages validates all workspace packagesThese are intended to verify deterministic slices of the pipeline quickly.
Run the lightweight regression harness with:
Inputs live in eval/cases/.
Latest aggregated output is written to:
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.
The repository currently includes:
the_almighty_shade (187893603920642048)typecheck validates all packages plus the root plugin shimpackages/adapter-lmstudio/src/promptPreprocessor.ts: main LM Studio prompt-preprocessor pipelinepackages/adapter-lmstudio/src/: LM Studio adapter logic and adapter-only shaping/typespackages/lmstudio-shared/src/: LM Studio shared model resolution, rerank, and bridge helpers used by plugin and MCP runtimespackages/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 guidancepackages/
core/
lmstudio-shared/
adapter-lmstudio/
mcp-server/
src/
index.ts
scripts/
eval/
manual-tests/
examples/
npm run dev:plugin
npm run push:plugin
npm run mcp:stdio
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"
]
}
}
}
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:lmstudio-shared
npm run typecheck:packages
npm 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
npm run smoke:lmstudio-model-resolution
npm run eval
eval/results/all-latest.json