lena13144/lorecodex
Tree-indexed RAG that retrieves whole fiction scenes without embeddings
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Tracked from daily D1 telemetry snapshots. Hover any data point for exact daily star counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
LoreCodex is a tree-indexed RAG store for narrative text. A volume → arc → scene hierarchy separates navigation metadata in tree_index.json from source text in tree_texts.json. LLM-assisted indexing adds scene summaries, volume overviews, aliases, and a glossary without replacing the source. SillyTavern and TauriTavern run retrieval in the browser through browser_engine.js, with IndexedDB or SillyTavern's /api/files for persistence. The browser and Node paths share a zero-dependency JavaScript ESM retrieval core; the Node entrypoints require Node.js 18 or newer.
The default agent browses the hierarchy, searches aliases or character timelines, and calls read_scene before it can select a scene. That tool reads up to ten scenes per call. Selected scenes enter the generation prompt in source order, alongside a retrieval guide. The same core is available through the Node HTTP service, MCP stdio at src/mcp_server.js, and the DeepSeek Harness plugin at src/dsh_plugin.js. The MCP interface distinguishes six direct lookup tools from two corpus-building or index writeback tools and one delegated retrieval tool.
Key Capabilities & Differentiators
The browser workbench imports TXT with UTF-8 or GB18030 detection, EPUB, Markdown, SillyTavern worldbook JSON, V2 character cards with character_book, and .lorepack.json. Structural preflight lets users check the split before spending model calls. LLM indexing can resume from saved progress and upgrade individual volumes. Full-text alias expansion finds appearances omitted from the scene metadata and marks them [CAMEO]. Character timelines are not restricted to a top-K candidate list, and the local Loria notebook stores verified source pointers and decaying co-occurrence links. Both are useful for recurring queries across volumes, with maxOrder limiting chapter-bound retrieval and notebook recall.
For chat endpoints without function calling, low-cost mode narrows candidates at the volume and scene levels before one final Chat selection call. The optional Decision path pools volumes and uses multiple keys; candidate assembly reserves slots for grep and notebook hits. If all Decision keys hit HTTP 429, retrieval can fall back to chunked reranking or local BM25F plus grep. The chat model can use an OpenAI-compatible endpoint, including compatible DeepSeek or Gemini endpoints and OpenRouter. The single final Chat call does not include any Decision or rerank requests made upstream.
Trade-offs & Limitations
A hand-maintained worldbook is simpler for a small set of stable facts. LoreCodex earns its setup cost when a chat needs exact dialogue, aliases, or an intact scene rather than a short entry. Compared with fixed-chunk vector RAG, the hierarchy preserves scene boundaries and reading order and avoids vector rebuilds. The trade-off is a stronger dependence on clean imports, accurate summaries, and good alias coverage. Local lexical fallback can miss paraphrases with little word overlap; optional model ranking provides a semantic path at the cost of request volume and latency.
Building the LLM-enhanced index costs model time up front. The deep agent typically takes two to four tool round trips when it checks the source, and injecting several full scenes can consume substantial context even in low-cost mode. Size browser memory and disk against the actual corpus and benchmark end-to-end retrieval with the chosen endpoint, context window, and concurrency. maxOrder follows reading order rather than in-world chronology, and general setting entries not tied to chapters are exempt, so test both nonlinear narratives and unassigned lore before relying on spoiler protection.
Hardware & Deployment Guide
Start with the SillyTavern or TauriTavern extension if browser storage and direct model access meet your needs. It does not require a separate Node or Python backend. For a standalone workbench, shared on-disk corpora under corpora/, or a provider whose endpoint runs into browser CORS restrictions, run node src/server.js on Node.js 18 or later. It listens on 127.0.0.1:5240 by default; binding with --host 0.0.0.0 requires --token or the APITOKEN environment variable. The Python 3 builder supports offline splitting with --no-llm. npm test runs offline tests without an API key, including mock indexing, resume behavior, and spoiler gating.
v3.2.2 hardened st-files synchronization with revision checks and recovery safeguards. Upgrade all participating clients before relying on conflict detection: older clients can overwrite files without advancing rev. SillyTavern file sync keeps API keys local, but configured hosted model endpoints still receive the inputs needed for inference. v3.3.0 removes the Embedding and Int8 vector layer entirely, so the earlier vector-assisted path is no longer a deployment option.
SillyTavern and TauriTavern roleplay, or MCP-based lore research, where exact dialogue, recurring aliases, and chapter-level spoiler limits matter.
A small worldbook already covers your needs, your corpus lacks useful narrative structure, or normal chat retrieval must work without any model calls.
Quick Start & Installation
# 离线全量测试(无需 API Key,覆盖双端解析、Mock LLM 建库与断点续传、MCP、dsh 插件、防剧透门控与别名搜索) npm test # 构建 dist/releases/ 下的 4 个发行包 npm run build:releases
Comparison vs. Top RAG, Data & Memory Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| lorecodex ★ | 21 | +8 | JavaScript | MIT | Tree-indexed RAG that retrieves whole fiction scenes without embeddings |
| firecrawl | 216.5k | +4.6k | TypeScript | AGPL-3.0 | Local and hosted web ingestion that turns sites into RAG-ready Markdown |
| markitdown | 199.7k | +909 | Python | MIT | Python library and CLI that turn mixed-format documents into Markdown for RAG in |
| claude-mem | 121.7k | +1.4k | TypeScript | Apache-2.0 | Hook-driven memory and hybrid search for coding agents that need cross-session r |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/lena13144/lorecodex.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about lorecodex
How does LoreCodex put source text into a chat, and can I use it outside SillyTavern?
Do I need a GPU, and what should I size for?
Can I use it commercially or self-host a library of published fiction?
When is this a better fit than a worldbook or vector RAG?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy