Building a Local Knowledge Base for Web Novels with LLM APIs

    This article explains how to build a local knowledge base for web novels by keeping source material on your own machine while delegating inference to remote LLM APIs. It covers why local storage and local model deployment are separate concerns, how to split reasoning-oriented and general-purpose models, a four-layer knowledge base design, practical chunking and hybrid indexing tips, a five-step retrieval-augmented generation workflow with citation verification, and measures for stability, cost control, and observability. It also lists common pitfalls. The approach supports structured organization and accurate question answering over million-character collections without high-end GPUs.

    1. First, a key distinction: a local knowledge base does not require a locally deployed model

    Many creators new to LLM applications assume that “building a knowledge base locally” means running the model locally too. In engineering terms, these are fully decoupled. The knowledge base is the raw material stored on your own machine, the chunked text blocks, the vector index, and the metadata. The model only handles understanding the question and generating an answer, and it can either run locally or be reached over the network as a remote inference service.

    From a feasibility standpoint, running a model locally must satisfy three constraints at once: VRAM capacity, VRAM bandwidth, and quantization precision. As parameter count grows, VRAM requirements rise linearly, while generation speed is mainly determined by memory bandwidth. Consumer-grade GPUs often can only host smaller distilled or heavily quantized variants, and these variants perform noticeably worse on long-range logical reasoning, character relationship mapping, and foreshadowing detection, often producing contradictions and missing key points. For most individual users and small teams, the more pragmatic route is therefore to keep the material local and hand inference to an API.

    This “local data + remote inference” architecture delivers three direct benefits. First, data sovereignty is clear: raw drafts never need to be uploaded, and only the necessary fragments are sent as request content. Second, capacity is not limited by local hardware, so a library of hundreds of thousands or even millions of characters can be managed uniformly. Third, elasticity is much better: peak periods do not saturate your local machine, and rising concurrency does not cause queued failures.

    2. Model selection: dividing work between reasoning and general-purpose models

    Mainstream LLM services usually offer two differently positioned model types: one oriented toward deep reasoning and divergence, good at drawing conclusions from messy clues; and one oriented toward general conversation and instruction following, with more restrained answers that stay closer to the literal facts. In a web novel knowledge base, the two should be assigned different roles rather than treated as an either-or choice.

    • Setting consolidation, timeline reconstruction, faction relationship inference, and foreshadowing payoff judgment are best given to reasoning-oriented models.
    • Term lookups, chapter summaries, fragment retrieval, format conversion, and batch tagging are best given to general-purpose models, which are faster and less prone to “filling in the blanks.”

    It is worth stressing that a stronger reasoning model is not necessarily more factually accurate. It is better at multi-step derivation within the given clues, but also more likely to invent settings on its own when information is insufficient. Engineering practice should therefore separate generation from verification: after the model outputs a conclusion, it must attach the source fragment, and a program or a human must check whether the citation actually exists.

    Some providers also offer paid tiers with faster responses and more generous concurrency, suitable for batch jobs and overnight runs. Free quotas usually come with queuing and rate limits, suitable for small-scale experiments. When selecting a tier, do not look only at unit price; factor in the hidden costs of queue waiting, failed retries, and truncation from overly long contexts.

    3. Layered design of the knowledge base

    A usable web novel knowledge base is not a directory with text dumped into it. It should be split into at least four layers.

    1. Raw layer: store the original text by work, volume, and chapter, with file names carrying the work identifier and chapter number. Keep it read-only; no processing writes back to it.
    2. Chunking layer: split chapters into overlapping text blocks, each recording metadata such as work, chapter, start and end positions, character count, and speaker.
    3. Index layer: generate a vector representation for each text block and build a keyword inverted index, forming a hybrid scheme with both vector and keyword retrieval.
    4. View layer: generate derived data for specific tasks, such as character relationship tables, timelines, setting entries, and chapter summaries.

    The key value of layering is re-runnability. Adjusting the chunking strategy, swapping the embedding model, or rewriting prompts only affects one downstream layer, without re-organizing the raw drafts.

    A sample metadata structure looks like this:

    1. {
    2. "work_id": "novel_001",
    3. "chapter": 128,
    4. "chunk_id": "novel_001-128-03",
    5. "text": "……the body text of the third paragraph of this chapter……",
    6. "char_range": [1024, 1536],
    7. "speaker": "Character A",
    8. "tags": ["scene: sect grand hall", "emotion: confrontation"],
    9. "source_path": "raw/novel_001/vol2/ch128.txt"
    10. }

    4. Practical points for chunking and indexing long documents

    Web novel text has three characteristics: dense dialogue, frequent scene switches, and complex referential relationships. Applying a generic chunking strategy directly usually gives mediocre results. The following principles are recommended.

    • Prefer splitting on semantic boundaries; paragraphs and dialogue turns are natural boundaries, so avoid breaking in the middle of a sentence.
    • Use moderate overlap, usually keeping one or two sentences of context, to prevent losing the referent.
    • Keep block size in the hundreds of characters. Too large makes retrieval hits imprecise; too small loses context.
    • Metadata must travel with each block, especially the work identifier and chapter number, otherwise cross-work retrieval becomes badly contaminated.
    • Build an alias dictionary for proper nouns, merging the multiple names used for the same character, which significantly improves recall quality.

    For index construction, pure vector retrieval excels at cases that are semantically close but use different wording, while pure keyword retrieval excels at exact matches of character names, move names, and place names. Combining the two noticeably reduces misses. A practical implementation is to use keyword retrieval to obtain a candidate set first, then rerank by vector similarity, balancing speed and accuracy.

    5. Orchestrating the retrieval-augmented generation flow

    The question-answering pipeline should be fixed at five steps: question rewriting, hybrid retrieval, context assembly, model invocation, and citation verification.

    1. def ask(question, top_k=6):
    2. # 1. Question rewriting: resolve references, extract key entities
    3. q = rewrite(question)
    4. # 2. Hybrid retrieval: keyword candidates + vector candidates
    5. cands = keyword_search(q) + vector_search(q, top_k)
    6. # 3. Deduplicate and truncate context to budget
    7. ctx = pack_context(dedupe(cands), max_chars=12000)
    8. # 4. Call the remote inference service, requiring a source per item
    9. prompt = f"Answer only based on the material below, labeling each conclusion with the fragment ID:\n{ctx}\n\nQuestion: {question}"
    10. answer = call_model(prompt)
    11. # 5. Citation verification: confirm the IDs exist and the content matches
    12. return verify(answer, ctx)

    Context assembly is the most easily overlooked step. Stuffing in all retrieved content not only drives up cost but also lowers answer quality because irrelevant information interferes. A safer approach is to set a character budget, truncate by relevance order, and explicitly require in the prompt that the model state when the material is insufficient, suppressing fabrication.

    6. Stability, cost, and observability

    When calling remote services, engineering robustness matters more than model choice. Four measures are recommended. First, timeouts with exponential backoff retries, so a single failure at peak time does not abort an entire batch. Second, serialized requests with a local queue, splitting batch jobs into small batches run at staggered times. Third, a cache layer that persists retrieval results and answers for identical questions, so repeated queries hit directly. Fourth, full-chain logging that records each request’s latency, token usage, matched fragments, and failure reason, making it easier to tell whether the problem is retrieval or generation.

    For cost control, first estimate average consumption per chapter on a small sample, then extrapolate the full-library batch scale. Assign high-frequency tasks such as summarization and tagging to more economical model tiers, and invoke the higher-capability model only when multi-step reasoning is needed. Pre-summarizing long text locally before sending it to the model can significantly compress input length.

    7. Common pitfalls

    • Assuming bigger is always better: task fit, context length, and stability often matter more than parameter count.
    • Feeding all material in at once: overly long contexts bring truncation and attention dilution; retrieval is the right answer.
    • Missing citation verification: conclusions without sources are untrustworthy in long-document scenarios.
    • Ignoring incremental updates: web novels are continuously serialized, so the index must support per-chapter appends and invalidation rebuilds.
    • Treating the knowledge base as a ghostwriter: it solves “findable and verifiable,” while creative judgment still belongs to the human.

    8. Summary

    The viable path to a local web novel knowledge base is to keep the heavy assets local and hand the heavy reasoning to an API. The core work concentrates on four things: a sensibly layered data structure, chunking and hybrid indexing that fit the text’s characteristics, a retrieval-augmented flow with citation verification, and an invocation layer with retries and caching. With these four steps done, even without a high-end GPU, you can reliably support structured organization and precise question answering over million-character material. If you later need multi-person collaboration or larger scale, you can add object storage for raw drafts, a message queue for task decoupling, and a container platform to host the index service, together with logging, monitoring, and alerting for full-chain observability.