Building a Local Web Novel Knowledge Base with LLM APIs: A Practical Guide
This guide explains how to build a local knowledge base for web novels by keeping data and indexes on your own machine while running model inference through an API. It covers a four-layer architecture, document cleaning and chunking, hybrid keyword and vector retrieval, prompt design with context budgeting, caching and incremental updates, model selection, cost control, and quality checks such as source tracing and consistency validation. The goal is to handle long-form text reliably on ordinary hardware without depending on local model deployment.
1. Why a “Local Knowledge Base” Does Not Mean Running the Model Locally
For personal knowledge base projects, many people’s first instinct is to download the model onto their own machine. From an engineering perspective, however, two different things need to be separated: keeping the data and knowledge base local, and keeping the model weights local. The former addresses file management, retrieval, and privacy boundaries; the latter addresses inference compute.
For web novels, a single title can easily run to hundreds of thousands of characters, and a full series can reach tens of millions. What really determines the experience is not where the model runs, but three things: whether the context can fit, whether retrieval can hit the right passages, and whether inference quality stays stable.
Deploying a full-parameter large model locally demands a lot of VRAM, memory, and bandwidth. Meanwhile, compressed or distilled small-parameter versions often degrade noticeably on long-range reasoning, character relationship mapping, and foreshadowing detection, tending to produce contradictions and lose details. For most individual users, the more practical route is therefore: keep the knowledge base and document processing local, and run model inference through an API.
This division of labor brings three direct benefits:
- No single-input-box limit: entire volumes and series are stored locally, and the program handles splitting and retrieval, sending only the necessary passages to the model.
- Avoiding peak-hour congestion: even if API-side queuing slows things down, it only means waiting, rather than an immediate “currently busy” response as on web front ends.
- Predictable cost: billing is per call, with no charges while idle, which suits long-term, accumulating personal use.
2. Overall Architecture: Four Layers
A usable local web novel knowledge base is best split into four layers, each with a single responsibility and easy to replace:
- Storage layer: raw text, cleaned text, and metadata (title, chapter number, word count, timeline tags).
- Index layer: a full-text index plus a vector index. The former handles exact matches for character names, move names, and place names; the latter handles semantically similar recall.
- Orchestration layer: handles chunking, recall, reranking, prompt assembly, API calls, and result caching.
- Application layer: question answering, character relationship mapping, setting consistency checks, and summarization plus rewriting assistance.
A sketch of the orchestration logic (pseudocode, showing flow only):
def ask(question, top_k=6):# 1. Keyword recall: exact hits on proper nounshits_kw = keyword_search(question, top_k=top_k)# 2. Semantic recall: fills in synonyms and contextually related passageshits_vec = vector_search(embed(question), top_k=top_k)# 3. Merge, deduplicate, and rerank to control the token size sent to the modelchunks = rerank(merge(hits_kw, hits_vec))[:top_k]prompt = build_prompt(question, chunks)# 4. Return cached results on a hit to avoid repeated billingreturn cache.get(prompt) or call_model_api(prompt)
3. Key Engineering Details
1. Document Cleaning and Chunking
Web novel text is noisy: ad lines, repeated chapter titles, blank lines, and mixed full-width and half-width characters. Start with rule-based cleaning, then split on three levels: chapter, section, and semantic paragraph. Chunks should be neither too large nor too small; typically each chunk is kept at the smallest semantic unit that can be understood on its own, with a small overlap so key sentences are not cut off. Every chunk must carry metadata, which is the basis for later filtering and source tracing.
2. Hybrid Retrieval Beats a Single Method
Vector retrieval alone tends to miss exact lookups of proper nouns; keyword retrieval alone cannot handle “asking about the same thing in different words”. Merging the two and applying a lightweight rerank noticeably improves both hit rate and stability.
3. Prompts and Context Budget
Content sent to the model should include the task description, constraints, retrieved passages with their source numbers, and output format requirements. Requiring the model to cite source numbers in its answer significantly reduces the share of content that “looks plausible but is not in the source text”.
4. Caching and Incremental Updates
Repeated calls on the same question are the main cost driver. Use “question + passage fingerprint” as the cache key; when new chapters are added, index only the new chunks incrementally instead of rebuilding everything.
4. Model Selection and Cost Control
For model selection, prepare two kinds: one biased toward reasoning and divergence, suited to character relationship inference and foreshadowing analysis; one biased toward restraint and stability, suited to reference lookup and fact checking. The former is more creative but more likely to “fill in” settings that do not exist; the latter is better for retrieval-style question answering. The practical recommendation is to run both tracks in parallel: route queries to the stable model and creative work to the reasoning model.
Cost control can start from four areas: limiting the number of recalled passages, trimming redundant prompt wording, enabling caching, and running large batch summarization jobs during off-peak hours. If the provider offers a paid acceleration tier, you can choose it as needed; essentially it trades money for shorter queue times.
5. Quality Checks and Common Pitfalls
- Source tracing: require every conclusion to carry a source chunk number for manual spot checks.
- Consistency checks: maintain a separate “settings sheet” and periodically use the model to compare new chapters against existing settings for conflicts.
- Preventing hallucination spread: for hard information such as timelines, forms of address, and power levels, insist on “no citation, no acceptance”.
- Privacy and compliance: the value of local storage lies in clear boundaries, but the scope of use for personal data and copyrighted content still needs attention.
6. Summary
For ordinary creators and curators, the right path is not to wrestle with local inference but to focus effort on knowledge base structure design, retrieval quality, and validation mechanisms: manage data and indexes locally, and inference in the cloud. This setup runs on ordinary office hardware, accommodates very long texts, avoids peak-hour congestion, and keeps long-term marginal cost under control.
