~/projects/marx-knowledge-base
[04 / 04] ● live python · rag · ollama

marx-knowledge-base

a fully-local rag assistant over 125+ works of marx, engels and lenin. every answer resolves to the passage it came from.

year
2026
role
full build
stack
python, llamaindex
retrieval
chroma + bm25
model
qwen3.5:9b
licence
MIT
[ specimen ]
question to citation, with local models at every step.

[01] the pipeline

the question is condensed with the chat history so follow-ups keep their subject. retrieval runs twice at once, vector search over chroma and bm25 keyword search, fused by reciprocal rank. an optional local cross-encoder re-scores the candidates before qwen3.5:9b reads them and writes the answer in streamlit.

the corpus, the embeddings, the re-ranker and the model all live on the machine. nothing is sent to a third party.

[02] citations that resolve

answers carry markers like [1] or [2, 4] that render as superscript links to a footnote with author, work, year, section and a link back to marxists internet archive. a marker that does not map to a retrieved passage is dropped and reported instead of being rendered as a dead link.

an answer without a source is a rumour with better grammar.

[03] when it does not know

if the model reports that the passages are insufficient, the app widens retrieval once — more passages, a larger candidate pool, no similarity floor — and retries. if the second pass still fails, it says so instead of guessing.

[04] measuring it

25 curated questions drive the evaluation harness. hit@k asks whether the right work appeared at all; mrr@k asks how high it ranked. on this corpus hybrid retrieval lifts hit@6 from about 48% to 68%, and the re-ranker lifts mrr from 0.49 to 0.62.

a second mode runs the full retrieve-cite-answer pipeline against a judge model and reports faithfulness, answer relevancy, citation validity and retry rate.

  • scraper rate-limited to 0.6s between pages, with an identifying user-agent
  • corpus is public domain or cc by-sa, downloaded for research
  • a hardware wizard writes per-machine settings instead of guessing
  • streamlit on localhost, no hosted service