simple-rag
Simple RAG on your knowledge bases. Only support Markdown Files.
Install the gem directly:
gem install simple-rag-zcSetup RAG
-
Setup Config JSON *Required
- Copy
example_config.jsontoconfig.json, then edit the paths to absolute path. - All
run-*executables default to./config.json, then~/.config/simple-rag/config.jsonif no config path is provided.
- Copy
-
SQLite index is required
- Set per-path
dbassqlite_file_path@table_name
- Set per-path
-
Run
run-index config.json*Required- By default this uses delta build mode: after the first complete scan, it only reads files modified since the last completed scan.
- Delta mode automatically falls back to a full build when the index DB or per-path scan timestamp is missing.
- Use
run-index --build-mode full config.jsonto scan all matching docs and rebuild/prune from the complete current file set. - Use
run-index --non-interactive config.jsonto print only per-path final summaries. - Index summaries report matched files separately from read files; in delta mode, read files are the changed-file workload.
-
Run
run-server config.json- Open
http://localhost:4567/q.htmlto search/ask from your knowledge bases- Use Search for standard retrieval
- Use Search+ for agentic query expansion and fast text match
- Open
http://localhost:4567/duplicate.htmlto review duplicate clusters - Open
http://localhost:4567/random.htmlto explore notes randomly - Open
http://localhost:4567/graph.htmlto explore search results as a graph
- Open
-
Run
run-query "your question"for CLI retrieval (LLM-friendly)-
run-query --helpshows usage and all configuredpaths(name => dir) - Uses the same standard retrieval pipeline as the web UI Search action
- Automatically uses a matching server at
http://127.0.0.1:4567; otherwise it retrieves locally - Set
RAG_SERVER_URLto use a different server URL - Default JSON output is a flat locator list with
path, roundedscore, anchorchunk, and brieftext - Use
--fullfor complete chunk text and retrieval debug details
-
-
Benchmark retrieval latency with a representative query set:
ruby test/benchmark/retrieval_benchmark.rb --config config.json-
Reports minimum, median, p95, and maximum latency plus embedding and local retrieval time.
-
Use
--max-p95-ms 2000orRAG_RETRIEVAL_MAX_P95_MS=2000to fail on a latency regression. -
Compare top-10 retrieval results across configs and candidate depths:
ruby test/benchmark/retrieval_quality_benchmark.rb ^
--config qwen=config-v2.json ^
--config other=config.json ^
--depth previous=120,200 ^
--depth current=64,100- Configs and depth profiles are combined into comparison scenarios.
- Reports top-10 overlap, Jaccard similarity, rank displacement, and latency.
- Cached scenario results and timestamped JSON reports are written under
tmp/retrieval-quality. - Use
--refreshto ignore cached results.
Setup Map Generator
To create a fancy map like the screenshot, complete these additional steps:
- Setup Python map generator
- Python 3.10+ is required for the faster map generator.
- From the repo root, install the Python package and dependencies:
python -m pip install -e python-
Update
config.jsononmap.pathfields. -
Run
run-index-map-v2 config.json.- It clusters indexed notes into mountains and writes the map data JSON.
- Optional include-only paths:
- set
map.includePathsin config.json (array ofpaths[].name) - or call
run-index-map-v2 config.json journal,learning
- set
- For faster iteration, run graph-only output first:
run-index-map-v2 config.json --stage graph- Or run the full pipeline:
run-index-map-v2 config.json --stage all- Label generation uses concurrent LLM requests. Tune it with either
map.labelWorkersinconfig.jsonor--label-workers:
run-index-map-v2 config.json --stage labels --label-workers 6- Open
http://localhost:4567/map-v2.htmlto explore knowledge mountains and click dots intoq.html
Publishing
To release a new version to RubyGems, run:
gem build simple-rag.gemspec
gem push simple-rag-zc-$(ruby -Ilib -e 'require "simple_rag/version"; puts SimpleRag::VERSION').gemTo test the version as a local install:
gem install simple-rag-zc-$(ruby -Ilib -e 'require "simple_rag/version"; puts SimpleRag::VERSION').gem