# Repository Briefing: lena13144/lorecodex
> Source: https://repoforai.com/repo/lena13144/lorecodex (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/lena13144/lorecodex
- **Category**: RAG, Data & Memory (知识库 / 爬虫 / 记忆层)
- **Primary Language**: JavaScript
- **License**: MIT
- **Engineering Health**: A (87/100 · Maintenance 35/35 · Adoption 12/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v3.3.0 (2026-12-03) — https://github.com/lena13144/lorecodex/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Self-Hosted, Local AI, API
- **Momentum**: 21 ★ total (+1 24h / +8 7d) · 3 forks
- **When to Use**: Best for: SillyTavern and TauriTavern roleplay, or MCP-based lore research, where exact dialogue, recurring aliases, and chapter-level spoiler limits matter. Skip if: A small worldbook already covers your needs, your corpus lacks useful narrative structure, or normal chat retrieval must work without any model calls.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Source fidelity: Volume → arc → scene indexing preserves complete scenes and returns selected text in source order.
- Vector-free ranking: v3.3.0 removes Embedding and Int8 indexes; optional Decision and chunked rerank fall back to local BM25F plus alias grep under rate limits.
- Retrieval modes: The default agent reads source scenes before selecting them; low-cost mode needs no function calling and uses one final Chat call after candidate selection.
- Spoiler control: maxOrder gates retrieval and Loria notebook recall by reading order; general setting entries without chapter assignments are exempt.
- Multi-device storage: IndexedDB or SillyTavern st-files, with revision checks, conflict backups, and deletion tombstones in st-files mode.
- Portable libraries: .lorepack.json carries the full corpus; .loreindex.json carries the index and can be reattached to a local source file.
```

## Quick Start / Clone
```bash
# 离线全量测试（无需 API Key，覆盖双端解析、Mock LLM 建库与断点续传、MCP、dsh 插件、防剧透门控与别名搜索）
npm test

# 构建 dist/releases/ 下的 4 个发行包
npm run build:releases
```
