Examples¶
The repository's examples/ folder
has one short script per stage of the pipeline. Each runs offline with no arguments; add
ollama (and a model name) to use real embeddings and an LLM. Run them from a clone:
git clone https://github.com/aion7891/SpectraFuse.git && cd SpectraFuse
pip install -e ".[all]"
python examples/search_example.py
One script per stage¶
| Script | Shows | Run with Ollama |
|---|---|---|
load_example.py |
loading documents, counting tokens and sentences | |
chunk_example.py |
chunking; 60 20 shows packing and overlap with small chunks |
|
embed_example.py |
embedding, saving, loading and a plain dense search | ollama |
edges_example.py |
the six edge signals | ollama gemma3:4b (adds LLM utility questions) |
ingest_example.py |
the whole offline pipeline with SpectRAGIngestion |
ollama gemma3:4b |
seed_example.py |
hybrid seeds: dense + BM25 + utility questions, fused with RRF | ollama |
expand_example.py |
graph expansion and proximity re-scoring | ollama |
search_example.py |
the full pipeline with the two main classes | ollama 400 (400-token budget) |
answer_example.py |
an answer with sources | needs Ollama: ollama qwen3:4b picks the model |
evaluate_example.py |
SpectraFuse against dense and hybrid top-k on 12 questions | ollama gemma3:4b (adds answer scores) |
Sample documents¶
examples/docs/: three short documents (Aurora Labs, Helios Energy, River Valley Farming), used byquickstart.pyand most examples.examples/eval/: 14 documents and 12 questions with their evidence passages, 9 of them multi-hop. The format ofquestions.jsonis the onetune()and the evaluation helpers read:
[
{"question": "In which city is the company that hired the co-founder of Aurora Labs as chief technology officer based?",
"answers": ["Porto"], "type": "bridge",
"evidence": ["She later joined Helios Energy as its chief technology officer",
"Helios Energy is a solar power company based in Porto"]}
]
Each evidence string is copied exactly from a document. A chunk counts as gold evidence when
it contains the string.
Compare against plain top-k¶
spectrafuse.utils.evaluation.evaluate_retrieval() scores SpectraFuse, dense top-k and hybrid top-k
with the same token budget:
from spectrafuse import SpectRAGIngestion, SpectRAGRetrieval
from spectrafuse.utils.evaluation import evaluate_retrieval, load_questions
SpectRAGIngestion("eval_index").ingest("examples/eval/docs")
search = SpectRAGRetrieval("eval_index")
questions = load_questions("examples/eval/questions.json")
report = evaluate_retrieval(search, questions, budget=512)
print(report["summary"]) # precision, recall, f1, mrr, complete for dense, hybrid, spectrafuse
report["rows"] holds the same metrics for each question. With the offline hash embedder and
the default settings, SpectraFuse does not beat hybrid top-k on this small set (evidence recall
0.889 against 0.944 at 512 tokens). Real embeddings and tuning matter.
Interactive examples¶
- SpectraFuse, step by step: every stage on a 12-chunk corpus.
- The spectral part, explained visually.
- Graph view of the evaluation set, with one question's retrieval path.