Repository avatar
Search & Data Extraction
v0.39.0
active

loreweave

io.github.lets-order-some-fries/loreweave

Durable agent memory over a markdown vault: bitemporal facts, timelines, hybrid graph search.

Documentation

Loreweave

A local temporal knowledge engine for markdown vaults.
Hybrid search, bitemporal facts and agent memory over MCP, with no LLM in the core.

npm CI node >= 22 MIT

Quickstart · What it does · CLI · Agent memory · Benchmarks · How it works · Research

Point Loreweave at a folder of markdown (Obsidian or plain) and it builds a knowledge graph, a bitemporal fact store, and a memory model over your notes, then hands them to you through a CLI and to your AI agents through MCP. Retrieval is measured on three public benchmarks (LongMemEval_S, BEIR/SciFact, LoCoMo), with the numbers and caveats in Benchmarks; the test suite (546 tests) runs in CI on Linux, macOS and Windows.


loreweave demo: temporal search, timeline, as-of facts, session resume

Three guarantees, enforced by the code rather than promised:

  • Your files win. User markdown is never mutated; the engine only appends, and only under lore/. The vault is the source of truth — the index is a cache you can delete at any time and rebuild identically (there's a test for that).
  • No LLM anywhere in the core. Indexing and retrieval use zero tokens and make zero network calls. Same vault, same version, same query: same answer, except that the ranking reads the clock in three places: the boost for passages marked used decays, queries about now weigh dates by their age, and indexing gives notes modified in the last 30 days a small importance bonus.
  • Memory you can read. Every fact an agent stores is a markdown line you can open, edit, and git diff.

Quickstart

Try it on a folder without installing: npx --allow-scripts=better-sqlite3 loreweave --vault ~/notes search "your query" (the first search indexes the folder into .lore/).

npm i -g --allow-scripts=better-sqlite3 loreweave   # the flag is for npm 12: see Requirements
cd ~/my-vault
lore init          # creates .lore/
lore index         # incremental sync; one changed note: 32 ms at 1k notes, 656 ms at 20k (see Scale)

lore search "why did we drop the queue design"
lore ask "what's the status of project atlas"
lore dream         # what's duplicated, contradicted, stale, unlinked

Zero configuration and no network: out of the box it runs on BM25 + knowledge-graph spreading activation. Add local embeddings when you want them:

// .lore/config.json
{ "embedding": { "provider": "ollama", "model": "mxbai-embed-large" } }

Pick mxbai-embed-large (670 MB) for quality or nomic-embed-text (274 MB) when disk and indexing speed matter more — required task prefixes are applied automatically for both, and for the E5, BGE and Arctic families. The measured difference between the two is in Benchmarks. No embedding provider means lexical + graph retrieval, still fully functional.

Works with non-English vaults: Chinese, Japanese and Korean text is segmented per character so it is searchable at all, and other scripts index as written.

What it does

1. Knowledge that has a timeline. Facts are bitemporal: when they were true in the world (valid_from/valid_until) and when the system learned them (recorded_at). Contradictions supersede rather than overwrite, so history stays queryable.

$ lore assert "Ledger Format" status draft --valid-from 2026-01-01
✓ Ledger Format :: status :: draft
  journal: lore/journal/2026-11-15.md
$ lore assert "Ledger Format" status final --valid-from 2026-08-01
✓ Ledger Format :: status :: final
  superseded: "draft" (now valid until 2026-08-01)
  journal: lore/journal/2026-11-15.md

(lore and loreweave are the same binary — the global install gives you both; npx --allow-scripts=better-sqlite3 loreweave runs it without installing.)

Both time axes are queryable, which is what makes it bitemporal rather than merely historical. --as-of asks what was true then; --as-known-at asks what was believed then. They disagree exactly when you learn something after the fact — which is when you most need to reconstruct what a past decision was actually based on:

$ lore facts --subject Vendor --as-of 2024-06-01
Vendor :: reliability :: poor — outage postmortem  (2024-01-01 → now)
    asserted · lore/journal/2024-08-01.md#@0

$ lore facts --subject Vendor --as-known-at 2024-06-01
Vendor :: reliability :: good  (2024-01-01 → 2024-01-01)  [superseded]
    asserted · lore/journal/2024-01-01.md#@0

Which fact wins is decided deterministically (newest valid-time, provenance as tiebreak) — never by asking a language model which one looks fresher. And the whole history of anything is one command — every value change merged chronologically with the dated prose that mentions it:

$ lore timeline Project Atlas
2024-01-15  status: planning  (until 2024-09-01)
2024-02-10  • [[Project Atlas]] kicked off with a three-person crew.  [kickoff.md]
2024-09-01  status: planning → active
2025-06-20  • The [[Project Atlas]] midpoint review went long but well.  [review.md]

Temporal-graph systems build this by running an LLM over every document at ingestion. Here the supersede chain has been maintained all along, so it is a read-side join: no LLM, no network, same answer every time.

2. Retrieval that follows connections, not just words. Queries fuse BM25, dense similarity (when configured), and Personalized PageRank over the vault's own graph — wiki-links, shared entities, tags, co-occurrence. Two-hop neighbors surface even when they share no vocabulary with your query, and every result says how it matched:

$ lore search "riverbed protocol"
• people/amara-osei.md  [all terms]  ⟨via riverbed protocol⟩
  Dr. Amara Osei leads the hydrology group. She maintains the [[Glacier Dataset]] and advises the [[Riverbed Protocol]] work.
…
• data/glacier-dataset.md  [no direct match]
  The Glacier Dataset holds meltwater sensor readings from 2019-2024. Access requires signing the data agreement.

3. Memory with dynamics. Every passage carries FSRS-style stability and retrievability — a power-law forgetting curve. Passages that actually get used (not merely retrieved) decay slower; important-but-fading knowledge gets surfaced for review instead of silently rotting. Nothing is ever deleted.

4. It dreams. lore dream is an idle-time consolidation pass that reviews the vault and reports duplicate passages, contradicted facts, stale knowledge, missing links between notes that clearly belong together, and orphans. With --apply it writes a digest and a review queue — append-only, under lore/. It never rewrites your prose: LLM-driven whole-file rewriting is a documented failure mode — each rewrite quietly drops details until the file collapses to mush — so the architecture forbids it.

5. Questions retrieval can't answer. Counting, grouping, and date-range queries run as deterministic SQL over the fact store, not as vibes over embeddings:

$ lore count --predicate trip_to --since 2025-01-01 --until 2025-12-31
    2  Japan
    1  Kenya

6. Facts come from your notes, not from a form. Nobody hand-writes - [fact] X :: y :: z, so the extractor mines the conventions vaults already use:

status: shipped              # frontmatter
- owner:: Priya              # Dataview inline field
- [location] Hyderabad       # Basic Memory observation

Only unambiguous field syntax is accepted automatically. Prose formatting like - **Owner:** Priya is precise on entity notes and noisy on report notes, so it is opt-in (facts.extract: "all") — or an agent can review candidates via lore_propose_facts and assert the real ones. Judgement stays out of the index.

7. Time means when it happened, not when you saved the file. --since and --until filter on content time — frontmatter dates, dated filenames (2025-03-14-standup.md), or dates in the text — falling back to file mtime only when a note carries no date of its own. lore watch keeps the index current so you never have to remember to reindex.

8. Built for agents. An MCP server exposes 15 typed tools so Claude Code, Cursor, or any MCP client can use your vault as durable memory. Session continuity is a query, not a paraphrase — lore resume returns exactly what changed since the agent last connected, computed from record time:

$ lore resume
since 2026-08-11 15:55
~ lore/journal/2026-08-11.md
+ Project Atlas :: status :: shipped (since 2026-08-11)
± Project Atlas :: status: active → shipped

$ lore resume
since 2026-08-11 15:56
nothing changed

Alternatives that summarize the previous session with an LLM inject a paraphrase; this is a deterministic diff. Full setup in Agent memory.

The CLI

CommandWhat it does
lore initcreate .lore/ with a default config
lore index [--full] [--no-nlp] [--rebuild-similar]incremental sync of vault → index
lore search <q> [-k] [--since] [--until] [--tag] [--folder] [--json]hybrid retrieval with provenance
lore ask <q>extractive answer: current facts + top passages (no LLM needed)
lore facts [--subject] [--predicate] [--as-of] [--as-known-at] [--history] [--limit]query the fact store (200 rows unless --limit says otherwise; a capped list says how many it left out)
lore timeline <entity> [--since] [--until]chronological history: fact changes merged with dated mentions
lore resume [--since]what changed since the last resume: notes, facts, supersessions
lore review [--threshold] [--limit]important-but-fading knowledge to revisit or archive
lore assert <s> <p> <o…> [--valid-from]record a fact (journalled, supersedes)
lore invalidate <s> <p>close the current fact in a slot
lore count [--predicate] [--group-by] [--since]aggregate over fact history
lore capture <text…>append a timestamped line to lore/inbox.md
lore dream [--apply]consolidation pass + optional digest/review queue
lore watchreindex automatically as the vault changes
lore mark-used <note> [anchor]reinforce a passage that proved useful
lore graph export --format json|graphml|dotexport the graph
lore doctorhealth check: broken links, integrity, coverage
lore statsvault statistics and top entities
lore serve --mcpstart the MCP server on stdio

Use it as agent memory (MCP)

// Claude Code: .mcp.json  (or claude_desktop_config.json)
{
  "mcpServers": {
    "loreweave": {
      "command": "npx",
      "args": ["--allow-scripts=better-sqlite3", "-y", "loreweave",
               "--vault", "/path/to/vault", "serve", "--mcp"]
    }
  }
}

The --allow-scripts argument is for npm 12; Requirements explains it, and docs/install.md how to clear an install npx already made without it.

ToolWhat the agent gets
lore_searchhybrid retrieval with provenance and temporal filters
lore_context_packone-call session context: relevant passages + current facts + recent changes
lore_read_notefull text of a note by path
lore_assert_fact / lore_invalidate_factwrite/close facts — journalled, superseding, never destructive
lore_query_factspoint-in-time fact queries (asOf, asKnownAt, history)
lore_timelinean entity's merged fact + prose chronology
lore_resumeexactly what changed since the agent last connected
lore_reviewimportant-but-fading passages worth resurfacing
lore_aggregate_factscount/group-by over fact history
lore_captureappend a timestamped line to the inbox
lore_mark_usedreinforcement signal: this passage actually helped
lore_propose_factsextraction candidates for the agent to review and assert
lore_dream_reportthe consolidation report (duplicates, contradictions, stale, orphans)
lore_indextrigger a reindex

Facts asserted through MCP are written back to lore/journal/YYYY-MM-DD.md as readable markdown, so an agent's memory is something you can open, edit, and git diff:

- [fact] Ledger Format :: status :: final {valid_from=2026-08-01, recorded_at=2026-11-15T09:09:05.709Z, confidence=0.9, source=stated}

Delete .lore/ and reindex — every fact and edge is reconstructed from those files.

- [fact] lines are replayed out of any note, but the source= attribute is read back only under lore/journal/, which is the only path loreweave writes. The same line in an ordinary note still records the fact, as extracted — a note can state something; it cannot say that you stated it.

Compared to hosted memory services (Mem0, Zep): those run LLMs at write time to extract and summarize into their own store; loreweave runs no model in the core, keeps memory in your files under your version control, and makes every retrieval reproducible. The trade: they do abstractive summarization, this engine deliberately does not. Retrieval quality against their published benchmarks is below — with the caveats stated, because most published agent-memory numbers measure end-to-end QA with an LLM, which is a different quantity than retrieval.

Benchmarks

These are third-party benchmarks with relevance labels nobody here chose. All loreweave numbers are retrieval metrics — it finds the evidence, it does not write the answer — so they are not comparable to the end-to-end QA accuracy quoted by systems that put a language model after retrieval. Reproduce any number: docs/benchmarks.md. Field comparison with the traps called out: docs/scoreboard.md.

LongMemEval_S (ICLR 2025) — 500 questions, each with ~50 sessions of chat history; find the sessions holding the evidence. Session-level recall, all 500 questions:

configurationR@1R@5R@10
model-free (no embeddings, no network)0.5520.8990.943
+ embeddings & 8-turn chunking0.5900.9590.983

The embedder (mxbai-embed-large) and the chunking in the second row were chosen by comparing configurations on 100-question samples (every fifth question) of these same 500 questions, with 95.2% R@5 as the target, so there is no held-out split.

For context only: agentmemory's historical report lists 86.2% (BM25), 95.2% (BM25 + vector) and 96.6% (MemPalace, vector-only) R@5 on LongMemEval-S. Those use any-hit scoring (a question counts if any gold session is in the top 5), an older input pipeline and, for the two vector rows, the all-MiniLM-L6-v2 embedder; their author now says the 95.2% cannot be compared with strict recall-all. The loreweave rows above score the fraction of gold sessions found. The author's current evaluation (2026-10-28) reports that metric too: 91.7% fractional recall@5 for agentmemory's BM25 component, over the 470 answerable questions (the rows above also include the 30 abstention questions) and with a different input pipeline. No ranking against any of these figures is claimed here.

BEIR / SciFact — 5 183 scientific abstracts, 300 claims, scored by nDCG@10 (ranking quality: rewards putting relevant documents nearer the top):

configurationnDCG@10Recall@10
BM25 baseline (BEIR paper, Anserini)0.665—
loreweave, model-free0.6810.817
loreweave + nomic-embed-text0.7270.865
loreweave + mxbai-embed-large0.7420.884

SciFact abstracts have no links and almost no tags, so the graph channel, whose candidates enter the ranking only when links, tagged notes and facts together reach one per 50 notes, is gated off and these rows do not measure it; the model-free row is in effect loreweave's own BM25, which scores 0.6815 run alone. The gain from local embeddings is 0.681 → 0.742.

LoCoMo — 10 long conversations, 1 982 evidence-labelled questions, turn-level recall. No comparable third-party retrieval number exists (published LoCoMo results are LLM QA accuracy), so these are offered as a target rather than a comparison. The turns have no links, tags or facts, so the graph channel is gated off here too:

R@1R@5R@10R@20
model-free0.3370.5380.6100.656
+ embeddings0.3180.5320.6270.705

What the numbers say, plainly. Recall is strong and rank-1 is the weakness — LongMemEval R@10 0.983 vs R@1 0.590 — which is why figures here are quoted at R@5 and why an agent consuming these results should read a top-5 list, not trust rank 1. The single biggest quality lever measured is the embedding model itself: mxbai over nomic is worth more than every downstream tuning combined on document (BEIR) and session (LongMemEval) retrieval — and measures flat on LoCoMo's single-turn passages, so it is a scale effect, not magic. A cross-encoder reranker is available (rerank in config) but earns its keep only for rank-1 consumers without embeddings — stacked on embeddings it loses recall on both public benchmarks, so leave it off unless that trade is yours. Full analysis, including the failed experiments and the defect that benchmarking caught: docs/evaluation.md.

Loreweave also ships an internal regression benchmark (npm run eval) over three purpose-built vaults — including a temporal-perturbation test where the shipped config scores 100% consistency vs BM25's 0%, gated in CI on every push. Internal corpora are good for regression and worthless as proof, so the details live in docs/evaluation.md rather than here.

Scale

Measured, like the quality numbers — npm run scale reproduces this on your own machine (synthetic vaults, 3 blocks per note, dense interlinking):

notesblocksentitiesedgesfull indexincrementalsearch p50p95dreamheap
1 0003 0002 76617 k1.2 s32 ms3 ms4 ms0.2 s63 MB
5 00015 00013 76685 k6.1 s165 ms9 ms12 ms1.0 s145 MB
20 00060 00055 016339 k22.5 s656 ms38 ms53 ms4.8 s333 MB

Full index scales at 0.93× per note from 5 k to 20 k — linear or better, no superlinear step hiding in the middle. "Incremental" is one changed note, which is what lore watch actually does all day. Everything here is one process, one SQLite file, no daemon — and search at 3-38 ms p50 is fast enough to sit inside an agent loop.

How it works

vault/*.md ──parse──▶ notes · blocks · wiki-links · tags · entities
                            │  (incremental: mtime + content hash)
                            ▼
                  SQLite .lore/index.db  ── disposable cache, rebuildable
                            │
        ┌───────────────────┼────────────────────┐
        ▼                   ▼                    ▼
   graph (CSR)         retrieval             facts
   blocks ∪ entities   BM25 + dense + PPR    bitemporal, supersession,
   2-iteration PPR     → weighted RRF        deterministic freshness,
   α = 0.5             → FSRS boosts         aggregates
        └─────────┬─────────┴──────────┬─────────┘
                  ▼                    ▼
             dream (idle-time)     CLI · MCP

Design rules the code enforces:

  • Files win. User markdown is never mutated. The engine only appends, and only under lore/.
  • Invariants in code, not prompts. Schema, migrations, graph construction, and supersession are typed, versioned, and tested — no LLM re-specifies them at runtime.
  • No LLM required anywhere in the core. Indexing and retrieval use zero tokens. Language models are consumers of this engine, not dependencies of it.
  • Everything is re-derivable. A full rebuild reproduces byte-identical derived state (there's a test for that).

Research lineage

Every significant choice traces to 2024-2026 literature; the survey lives in docs/research/.

ChoiceSource
Dense-sparse fusion + PPR with dense reset probabilitiesHippoRAG 2 (ICML 2025), 2502.14802
Shallow 2-iteration PPR, heterogeneous nodesNodeRAG (2025), 2504.11544
Relation-free graph — no LLM triple extractionLinearRAG (ICLR 2026), 2510.10114
No index-time community summarizationLazyGraphRAG (Microsoft, 2024) — same quality at 0.1% index cost
Route/fuse instead of graph-everythingGraphRAG-Bench (ICLR 2026), 2506.05690
Bitemporal facts, invalidate-never-deleteZep/Graphiti (2025), 2501.13956
Power-law forgetting, use-gated reinforcementFSRS; RMM (ACL 2025), 2503.08026
Consolidation as idle-time workSleep-time compute (Letta, 2025), 2504.13171
Never let an LLM rewrite whole memory filesACE (2025), 2510.04618
Computable facts for aggregationUser as Code (2026), 2606.16707
Fine-grained indexing + fact-augmented keysLongMemEval (ICLR 2025), 2410.10813

Library use

import { openContext, indexVault, search, assertFact, queryFacts, dream } from 'loreweave';

const ctx = openContext('/path/to/vault');
await indexVault(ctx.store, ctx.root);
const hits = await search(ctx, 'streaming compaction', { k: 5 });
assertFact(ctx, { subject: 'Atlas', predicate: 'status', object: 'shipped', validFrom: '2026-08-01' });
const asOfMarch = queryFacts(ctx.store, { subject: 'Atlas', asOf: '2026-03-01' });
const report = dream(ctx);
ctx.close();

Development

npm install
npm run build     # the stdio-server tests run the built CLI, and skip without it
npm test          # 546 tests
npm run eval      # retrieval benchmark vs BM25 baseline
npm run typecheck

Requirements

Node 22 or later. Tested in CI on Linux, macOS and Windows across Node 22, 24 and 26. The single native dependency, better-sqlite3, installs from a prebuilt binary on macOS, Linux and Windows with Node 22, 24, 25 or 26 — no compiler needed. Node 23 has none, so there npm compiles it from source, which needs a C++ toolchain.

With npm 12, pass --allow-scripts=better-sqlite3 to npm i -g and npx, as above; without it the install succeeds but every command that opens the index fails. Inside a project, npm 12 refuses that flag: run npm approve-scripts better-sqlite3, then npm rebuild better-sqlite3. npm 10 and 11 need neither. Details, including how to clear an install npx made without the flag: docs/install.md.

License

MIT © Ambuj Upadhyay

NPM
loreweave
Install Command
npm install loreweave
Runtime: npx