Spaces:
Running
Running
feat: refactor code structure for improved readability and maintainability (#1)
Browse files- feat: refactor code structure for improved readability and maintainability (3c831c37806631ea4e9c4f161d376d6177ad0e96)
Files changed (18)
- .gitattributes+13
- README.md+40-5
- assets/00_cover.pngAdded
- assets/01_hero_topk_vs_spectrag.gifAdded
- assets/02_six_signals_graph_build.gifAdded
- assets/03_spectral_coordinates.gifAdded
- assets/04_spectral_diffusion.gifAdded
- assets/05_token_budget_selection.gifAdded
- assets/06_by_the_numbers.gifAdded
- assets/SpectRAG_explainer_voiceover.mp4Added+3
- assets/SpectRAG_explainer_voiceover.vttAdded+126
- assets/chart_01_index_footprint.pngAdded
- assets/chart_02_recall_by_depth.pngAdded
- assets/chart_03_accuracy_by_question_type.pngAdded
- assets/chart_04_diversity_win_rate.pngAdded
- assets/chart_05_answer_accuracy.pngAdded
- assets/online-offline-main-pipeline.pngAdded
- index.html+177-17
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353637383940414243444546474832 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/00_cover.png filter=lfs diff=lfs merge=lfs -textassets/01_hero_topk_vs_spectrag.gif filter=lfs diff=lfs merge=lfs -textassets/02_six_signals_graph_build.gif filter=lfs diff=lfs merge=lfs -textassets/03_spectral_coordinates.gif filter=lfs diff=lfs merge=lfs -textassets/04_spectral_diffusion.gif filter=lfs diff=lfs merge=lfs -textassets/05_token_budget_selection.gif filter=lfs diff=lfs merge=lfs -textassets/06_by_the_numbers.gif filter=lfs diff=lfs merge=lfs -textassets/chart_01_index_footprint.png filter=lfs diff=lfs merge=lfs -textassets/chart_02_recall_by_depth.png filter=lfs diff=lfs merge=lfs -textassets/chart_03_accuracy_by_question_type.png filter=lfs diff=lfs merge=lfs -textassets/chart_04_diversity_win_rate.png filter=lfs diff=lfs merge=lfs -textassets/online-offline-main-pipeline.png filter=lfs diff=lfs merge=lfs -textassets/SpectRAG_explainer_voiceover.mp4 filter=lfs diff=lfs merge=lfs -text
123456789101112---title: SpectRAGemoji: 🏃colorFrom: bluecolorTo: graysdk: staticpinned: falselicense: mitshort_description: Spectral graph-augmented retrieval for RAG systems---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference1234567891011121314151617181920212223242526272829303132333435363738394041424344454647---title: SpectRAGemoji: 🐙colorFrom: bluecolorTo: indigosdk: staticpinned: truelicense: mitshort_description: Weighted chunk graphs for multi-hop RAG context selectiontags:- rag- retrieval-augmented-generation- graph- spectral-graph-theory- multi-hop-qa---# SpectRAG: Weighted Chunk Graphs for Token-Budgeted Context Selection in Multi-Hop RAGAn interactive, visual walkthrough of **SpectRAG**. SpectRAG is a retrieval framework that replaces independent top-k ranking with **context-set selection** over a weighted chunk graph and its Laplacian spectrum.- 📄 Paper: [arXiv:2610.36991](https://arxiv.org/abs/2610.36991)- 🤗 Paper page: [hf.co/papers/2610.36991](https://huggingface.co/papers/2610.36991)- 💻 Code (MIT): [github.com/SightAndCite/SpectRAG](https://github.com/SightAndCite/SpectRAG)## Highlights (MultiHopRAG & UltraDomain)| | ||---|---|| Overall gold-evidence recall | **91.8%** (next best 76.1%) || Exact match on inference questions | **95.1%** || Index size vs LightRAG | **46 MB vs 274 MB** (~6× smaller) || Diversity win rate (LLM judge) | **> 50% vs every baseline**, up to 72.5% |## Citation```bibtex@misc{sahinoglu2026spectragweightedchunkgraphs,title={SpectRAG: Weighted Chunk Graphs for Token-Budgeted Context Selection in Multi-Hop Retrieval-Augmented Generation},author={Zafer Sahinoglu and Abdulazeez Mohammed and Buse Yaren Kazangirler and Cahit Berkay Kazangirler},year={2026},eprint={2610.36991},archivePrefix={arXiv},primaryClass={cs.AI},url={https://arxiv.org/abs/2610.36991},}```
123version https://git-lfs.github.com/spec/v1oid sha256:aa2ddddb1d5c3ace8b8190e2aca9f22b9a33c18bdd43b045de38cc9c80b323b8size 9709194123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126WEBVTT
100:00:00.350 --> 00:00:01.409Meet SpectRAG.
200:00:01.409 --> 00:00:05.114Stop retrieving chunks, and start retrieving context.
300:00:06.014 --> 00:00:07.622Ask a multi-hop question,
400:00:07.622 --> 00:00:12.044and classic top-k retrieval grabs six near-duplicate chunks from one cluster.
500:00:12.044 --> 00:00:16.063It finds only one of the three pieces of evidence.
600:00:16.063 --> 00:00:18.475SpectRAG seeds, expands over the graph,
700:00:18.475 --> 00:00:21.690diffuses relevance, and selects a diverse, connected set.
800:00:21.690 --> 00:00:23.298Three out of three.
900:00:24.198 --> 00:00:27.605Offline, every document is split into chunks.
1000:00:27.605 --> 00:00:31.497Then the chunks are connected by six signals:
1100:00:31.497 --> 00:00:33.444adjacency, sections, semantic similarity,
1200:00:33.444 --> 00:00:36.363shared entities, utility questions, and citations.
1300:00:36.363 --> 00:00:39.770Together, they form one weighted chunk graph.
1400:00:40.670 --> 00:00:43.093Now every chunk has two geometries.
1500:00:43.093 --> 00:00:45.920Its embedding captures what the chunk says.
1600:00:45.920 --> 00:00:47.132Its spectral coordinates,
1700:00:47.132 --> 00:00:50.362from the graph Laplacian, capture where it lives.
1800:00:50.362 --> 00:00:52.786Communities pull together, whatever their wording.
1900:00:54.170 --> 00:00:56.826At query time, relevance diffuses along the graph.
2000:00:56.826 --> 00:01:00.147Bridge chunks that never matched the query still light up.
2100:01:00.147 --> 00:01:02.804That is how SpectRAG finds the missing link.
2200:01:06.170 --> 00:01:08.187Instead of a fixed top-k,
2300:01:08.187 --> 00:01:10.205SpectRAG fills a twelve-thousand-token budget.
2400:01:10.205 --> 00:01:14.644A protected core comes first, then coverage-aware picks with no redundancy,
2500:01:14.644 --> 00:01:18.276and finally a backfill, so no space is wasted.
2600:01:20.170 --> 00:01:21.136The result:
2700:01:21.136 --> 00:01:25.96691.8 percent gold-evidence recall, 95 percent accuracy on inference questions,
2800:01:25.966 --> 00:01:29.830and an index six times smaller than LightRAG.
2900:01:30.730 --> 00:01:31.097SpectRAG.
3000:01:31.097 --> 00:01:34.776Retrieve a context set, not a pile of similar chunks.
3100:01:34.776 --> 00:01:37.350Read the paper, and try the code.
12345678910111213141516171819<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /></head><body><div class="card"><h1>Welcome to your static Space!</h1><p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p><p>Also don't forget to check the<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.</p></div></body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>SpectRAG · Retrieve Context, Not Chunks</title><meta name="description" content="SpectRAG: weighted chunk graphs and spectral diffusion for token-budgeted context selection in multi-hop RAG."><meta property="og:title" content="SpectRAG · Retrieve context, not chunks"><meta property="og:image" content="assets/00_cover.png"><style>:root {--bg: #050B1A; --panel: #0A1630; --edge: #1C3466; --text: #E8F1FF; --muted: #93A5C8;--cyan: #4FD1FF; --green: #3DDC97; --yellow: #FFD166; --radius: 14px;}* { box-sizing: border-box; }html { scroll-behavior: smooth; }body { margin: 0; background: var(--bg); color: var(--text);font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }main { max-width: 980px; margin: 0 auto; padding: 0 16px 80px; }a { color: var(--cyan); }img, video { display: block; width: 100%; height: auto; border-radius: var(--radius);border: 1px solid var(--edge); background: #000; }header { text-align: center; padding: 56px 0 28px; }.eyebrow { color: var(--cyan); letter-spacing: .14em; text-transform: uppercase; font-size: 13px; font-weight: 700; }h1 { font-size: clamp(34px, 6vw, 58px); line-height: 1.08; margin: 10px 0 14px; letter-spacing: -.02em; }h1 span { color: var(--cyan); }.lede { color: var(--muted); font-size: clamp(16px, 2.2vw, 20px); max-width: 720px; margin: 0 auto; }.authors { color: var(--muted); font-size: 14px; margin-top: 14px; }.btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 24px; }.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px;border: 1px solid var(--edge); background: var(--panel); color: var(--text); text-decoration: none;font-weight: 600; font-size: 15px; transition: border-color .15s, transform .15s; }.btn:hover { border-color: var(--cyan); transform: translateY(-1px); }.btn.primary { background: var(--cyan); color: var(--bg); border-color: var(--cyan); }section { margin-top: 64px; }h2 { font-size: clamp(24px, 3.4vw, 32px); margin: 0 0 6px; letter-spacing: -.01em; }.sub { color: var(--muted); margin: 0 0 20px; }figure { margin: 0; }figcaption { color: var(--muted); font-size: 14px; text-align: center; margin-top: 10px; }.quote { border-left: 3px solid var(--cyan); padding: 4px 0 4px 18px; font-size: 20px; margin: 28px 0 0; }.steps { display: grid; gap: 40px; }.step { display: grid; grid-template-columns: 1fr 1.35fr; gap: 24px; align-items: center; }.step:nth-child(even) .txt { order: 2; }.num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;background: var(--cyan); color: var(--bg); font-weight: 800; font-size: 15px; margin-bottom: 8px; }.step h3 { margin: 0 0 6px; font-size: 21px; }.step p { margin: 0; color: var(--muted); }.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }.stat { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); padding: 16px; }.stat b { display: block; font-size: 30px; line-height: 1.1; color: var(--cyan); }.stat span { color: var(--muted); font-size: 14px; }.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }.note { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); padding: 18px 20px; }.note ul { margin: 6px 0 0; padding-left: 20px; color: var(--muted); }pre { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); padding: 16px;overflow-x: auto; font-size: 13px; line-height: 1.5; margin: 0; }.copy { margin-top: 10px; }footer { margin-top: 72px; text-align: center; color: var(--muted); font-size: 14px; }@media (max-width: 760px) {.step { grid-template-columns: 1fr; }.step:nth-child(even) .txt { order: 0; }.stats { grid-template-columns: 1fr 1fr; }.charts { grid-template-columns: 1fr; }}</style></head><body><main><header><div class="eyebrow">Multi-hop RAG · arXiv 2610.36991</div><h1>Stop retrieving chunks.<br><span>Start retrieving context.</span></h1><p class="lede">SpectRAG builds a weighted chunk graph from six evidence signals and uses its Laplacian spectrum to select a context set that is <b>relevant, diverse and connected</b>, all under a fixed token budget.</p><p class="authors">Zafer Sahinoglu · Abdulazeez Mohammed · Buse Yaren Kazangirler · Cahit Berkay Kazangirler</p><div class="btns"><a class="btn primary" href="https://arxiv.org/abs/2610.36991" target="_blank" rel="noopener">📄 Paper</a><a class="btn" href="https://github.com/SightAndCite/SpectRAG" target="_blank" rel="noopener">💻 Code</a><a class="btn" href="https://huggingface.co/papers/2610.36991" target="_blank" rel="noopener">🤗 Paper page</a><a class="btn" href="#video">🎬 Watch the explainer</a></div></header><figure><img src="assets/01_hero_topk_vs_spectrag.gif" alt="Animation: classic top-k retrieval picks six near-duplicate chunks and finds 1 of 3 gold passages; SpectRAG seeds, expands, diffuses and selects a diverse set that finds 3 of 3."><figcaption>Same question, same 6-chunk budget. Top-k finds 1/3 of the gold evidence; SpectRAG finds 3/3. (Illustrative toy corpus.)</figcaption></figure><p class="quote">Top-k ranks chunks one at a time. Multi-hop questions need a <b>set</b> of chunks that works together as evidence.</p><section id="how"><h2>How it works</h2><p class="sub">An offline pass builds the graph once; a five-stage online pass selects context for each query.</p><div class="steps"><div class="step"><div class="txt"><div class="num">1</div><h3>A chunk graph built from six signals</h3><p>Semantic similarity, document adjacency, section hierarchy, shared entities, LLM-generated utility questions and citations are fused into one weighted edge.</p></div><img src="assets/02_six_signals_graph_build.gif" alt="Animation: chunks from five documents are connected signal by signal into a weighted chunk graph." loading="lazy"></div><div class="step"><div class="txt"><div class="num">2</div><h3>Two geometries for every chunk</h3><p>The dense embedding captures what a chunk says. The 32-d spectral coordinate from the normalized Laplacian captures where it lives in the corpus.</p></div><img src="assets/03_spectral_coordinates.gif" alt="Animation: points morph from an overlapping embedding layout into well-separated spectral communities." loading="lazy"></div><div class="step"><div class="txt"><div class="num">3</div><h3>Relevance diffuses along the graph</h3><p>Hybrid seeds (dense + BM25 + utility questions) are expanded two hops and re-scored with spectral closeness and Personalized PageRank, so bridge evidence surfaces.</p></div><img src="assets/04_spectral_diffusion.gif" alt="Animation: relevance heat spreads from three seed nodes across a graph." loading="lazy"></div><div class="step"><div class="txt"><div class="num">4</div><h3>Token-budgeted selection</h3><p>A protected core, a coverage-aware tail with a precision floor, and a backfill fill a ~12k-token window, adapting to 10–15 chunks per query.</p></div><img src="assets/05_token_budget_selection.gif" alt="Animation: candidate chunks fill a 12,000-token context window; redundant and low-precision chunks are skipped." loading="lazy"></div></div><figure style="margin-top:40px"><img src="assets/online-offline-main-pipeline.png" alt="Full SpectRAG pipeline diagram: offline indexing and online query-time retrieval." loading="lazy"><figcaption>The full pipeline: offline corpus indexing and online query-time retrieval.</figcaption></figure></section><section id="video"><h2>Explainer video</h2><p class="sub">A 98-second narrated walkthrough. Captions are available in the player.</p><video controls preload="metadata" poster="assets/00_cover.png"><source src="assets/SpectRAG_explainer_voiceover.mp4" type="video/mp4"><track kind="captions" src="assets/SpectRAG_explainer_voiceover.vtt" srclang="en" label="English" default></video></section><section id="results"><h2>Results</h2><p class="sub">MultiHopRAG (2,556 gold-answer questions) and four UltraDomain corpora, against NaiveRAG, Hybrid, HyDE and LightRAG. Every system uses the same generator.</p><div class="stats"><div class="stat"><b>91.8%</b><span>overall gold-evidence recall (next best 76.1%)</span></div><div class="stat"><b>95.1%</b><span>exact match on inference questions</span></div><div class="stat"><b>~6×</b><span>smaller index than LightRAG (46 vs 274 MB)</span></div><div class="stat"><b>>50%</b><span>diversity win rate vs every baseline</span></div></div><div class="charts"><img src="assets/chart_02_recall_by_depth.png" alt="Line chart: recall at 2, 5, 10 and overall for five systems; SpectRAG reaches 91.8% overall." loading="lazy"><img src="assets/chart_01_index_footprint.png" alt="Bar charts: index size 46 MB vs 274 MB and node counts per corpus, SpectRAG vs LightRAG." loading="lazy"><img src="assets/chart_03_accuracy_by_question_type.png" alt="Dot plot: exact match by question type; SpectRAG leads on inference at 95.1%." loading="lazy"><img src="assets/chart_04_diversity_win_rate.png" alt="Bar chart: SpectRAG diversity win rate above 50% against all four baselines in both configurations." loading="lazy"></div><div class="note" style="margin-top:20px"><b>Honest trade-offs</b><ul><li>Hybrid retrieval leads at the very top of the ranking (Recall@2, Recall@5, MRR); SpectRAG wins on breadth.</li><li>End-to-end accuracy gains are narrow (EM 71.2 vs 70.6 for the next best): better retrieval saturates with short multi-hop answers.</li><li>On unanswerable (null) questions SpectRAG is behind the vector baselines, and signal weights can need per-corpus tuning.</li></ul></div></section><section id="cite"><h2>Citation</h2><pre id="bib">@misc{sahinoglu2026spectragweightedchunkgraphs,title={SpectRAG: Weighted Chunk Graphs for Token-Budgeted Context Selection in Multi-Hop Retrieval-Augmented Generation},author={Zafer Sahinoglu and Abdulazeez Mohammed and Buse Yaren Kazangirler and Cahit Berkay Kazangirler},year={2026},eprint={2610.36991},archivePrefix={arXiv},primaryClass={cs.AI},url={https://arxiv.org/abs/2610.36991},}</pre><button class="btn copy" type="button" id="copyBib">Copy BibTeX</button></section><footer>SpectRAG is open source under the MIT license · <a href="https://github.com/SightAndCite/SpectRAG">GitHub</a></footer></main><script>document.getElementById('copyBib').addEventListener('click', async (e) => {try { await navigator.clipboard.writeText(document.getElementById('bib').textContent);e.target.textContent = 'Copied ✓'; }catch { e.target.textContent = 'Select the text above to copy'; }setTimeout(() => { e.target.textContent = 'Copy BibTeX'; }, 2000);});</script></body></html>
.gitattributes+13
README.md+40-5
assets/00_cover.pngAdded

Large File Pointer Details
- SHA256: 3bed2412b444e8768ac8b43438c99bbf254834c00312659c00f419143a4903ce
- Pointer size: 131 Bytes
- Size of remote file: 520 kB
assets/01_hero_topk_vs_spectrag.gifAdded

Large File Pointer Details
- SHA256: 7a6e001f4d71f995669d2be5003869b4bdeb666f3d313048e124120cbad76a4c
- Pointer size: 131 Bytes
- Size of remote file: 498 kB
assets/02_six_signals_graph_build.gifAdded

Large File Pointer Details
- SHA256: f2e118dfd22eca5ea18e754dcb1eee8abab533b8324aef055dad277f1742b2ed
- Pointer size: 132 Bytes
- Size of remote file: 2.29 MB
assets/03_spectral_coordinates.gifAdded

Large File Pointer Details
- SHA256: d4befbad63e70f20f7b6e4a8be31de5e5c506e7bac5074fe6026ae1f5efe4dfb
- Pointer size: 132 Bytes
- Size of remote file: 4.5 MB
assets/04_spectral_diffusion.gifAdded

Large File Pointer Details
- SHA256: 41f37de41145e2851018b51d5b08b49fc2b86229328155cf247c139eed907433
- Pointer size: 132 Bytes
- Size of remote file: 1.78 MB
assets/05_token_budget_selection.gifAdded

Large File Pointer Details
- SHA256: 5ffd2f70cd9fc5c38b4c06d6da007e363c0307c77e8347f00e99ffbd4196b85e
- Pointer size: 131 Bytes
- Size of remote file: 668 kB
assets/06_by_the_numbers.gifAdded

Large File Pointer Details
- SHA256: 834b8acee87d359e808b7ea39852f8e6d4618165f495257ad5654fbd9031099b
- Pointer size: 131 Bytes
- Size of remote file: 489 kB
assets/SpectRAG_explainer_voiceover.mp4Added+3
assets/SpectRAG_explainer_voiceover.vttAdded+126
assets/chart_01_index_footprint.pngAdded

Large File Pointer Details
- SHA256: 6224858bdcaa425f10de18780ae9de15e100c41ad93dba0d3d6ff62a333cff09
- Pointer size: 131 Bytes
- Size of remote file: 109 kB
assets/chart_02_recall_by_depth.pngAdded

Large File Pointer Details
- SHA256: 37a370eb010bd85e851e67e5c5bae2363049bc37a86dbdc2f6a3bd3ad8afb8a8
- Pointer size: 131 Bytes
- Size of remote file: 133 kB
assets/chart_03_accuracy_by_question_type.pngAdded

Large File Pointer Details
- SHA256: f215b2f11d926c38eee77d7bc34283ef701ebe34c63bbb93f6ed4b86ddb8357e
- Pointer size: 131 Bytes
- Size of remote file: 102 kB
assets/chart_04_diversity_win_rate.pngAdded

Large File Pointer Details
- SHA256: 9c3a1a9dee46c6e3e2bbfcfc6a204e976dbb26b8448fd7db0e66fc0748fd7d3d
- Pointer size: 131 Bytes
- Size of remote file: 104 kB
assets/chart_05_answer_accuracy.pngAdded

assets/online-offline-main-pipeline.pngAdded

Large File Pointer Details
- SHA256: f39e157ba4205d43b4d1f0b9f302f9546b6ee68c2ea326eb524f12082d68751a
- Pointer size: 131 Bytes
- Size of remote file: 956 kB
index.html+177-17