How to Build a Local Knowledge Base for Web Novels with LLM APIs

    This article explains how to build a local knowledge base for web novels using cloud LLM APIs instead of running a model locally. It covers why local storage and cloud inference are separated, how to choose between API calls and local inference, and a four-layer architecture of collection, processing, indexing, and application. It also details retrieval-augmented generation (RAG), prompt templates with citation numbering, combining reasoning-oriented and chat-oriented models, long-text strategies, cost and stability practices, and troubleshooting tips. Readers will learn a practical workflow that runs on ordinary hardware while keeping the knowledge base reusable and verifiable.

    1. Why a “Local Knowledge Base” Does Not Mean Running the Model Locally

    Many readers have an intuitive misconception when they first encounter this concept: if the materials are organized locally, does the model also have to run on their own machine? The answer is usually no, and it helps to separate two things.

    The first is where the data and knowledge base are stored. Raw manuscripts, chapter excerpts, character relationship tables, and setting indexes can all live on a local disk or a self-managed storage directory, with local programs handling splitting, embedding, and retrieval.

    The second is where inference capability comes from. The compute-intensive part is the LLM inference process. Running a full-scale, large-parameter model locally demands a great deal of VRAM, memory, and bandwidth, which ordinary personal devices can hardly support. A common industry approach is to use distilled versions with smaller parameter counts. These versions are acceptable for general conversation, but they clearly struggle with long-chain reasoning and complex setting analysis, and the actual experience often falls short of usable.

    So the more practical route is: local handles data and workflow, cloud APIs handle inference. The direct benefits are three:

    • Local storage can hold files of any length, without the length limits of a web chat window;
    • You avoid competing with queues and rate limits on public entry points;
    • The knowledge base keeps accumulating and becomes a reusable personal asset.

    2. Choosing Between API Calls and Local Inference

    Before you start, use the following decision table for a self-assessment.

    Dimension Lean toward API calls Lean toward local inference
    GPU condition No high-end GPU or limited VRAM Sufficient VRAM and memory
    Data sensitivity Data can be sent out after de-identification Data strictly cannot leave the intranet
    Task complexity Needs long-text reasoning and summarization Simple tasks, weaker results acceptable
    Usage frequency Medium-to-low frequency, pay-as-you-go is cheaper High frequency with idle compute already available

    For most individual users and small-to-medium teams, the conclusion falls on the left. Note that public APIs may respond slowly during peak hours, and waiting one or two minutes for a complex question is normal. The right response is not repeated retries but designing requests as asynchronous batch processing: queue and persist tasks locally first, submit them one by one, and write results back to local files. This way, even a long single wait will not break the overall workflow.

    If the budget allows, look into the accelerated or tiered channels offered by the provider. These usually mean faster responses and shorter queues, essentially a stability gain from resource isolation. This is a general practice; refer to the official documentation for specific billing and quotas.

    3. Overall Architecture: A Four-Layer Structure

    A local knowledge base meant for long-term maintenance is best organized in four layers.

    Layer 1 is the collection layer. It gathers scattered text, including novel text, setting collections, writing notes, and commentary articles. Everything is converted to plain text or a structured markup format, with headers, footers, ads, and duplicate paragraphs removed.

    Layer 2 is the processing layer. This is the most overlooked yet most critical layer, covering cleaning, splitting, and metadata tagging. Split granularity directly determines retrieval quality: too coarse, and one segment mixes multiple topics, diluting the vector semantics; too fine, and context breaks, leaving the model unable to understand. A practical rule is to split along semantic boundaries, such as scenes or chapter subsections, with lengths of roughly 1,000 to 2,000 characters and a certain overlap between adjacent segments.

    Layer 3 is the indexing layer. Each segment is turned into a vector and stored in a local vector store, while a keyword inverted index is kept as well. Retrieval uses a hybrid strategy: first keyword recall for exact matches (names, places, proper settings), then vector recall for semantically similar content, and finally fused ranking.

    A schematic processing flow can be written as:

    1. def build_index(raw_docs, splitter, embedder, store):
    2. for doc in raw_docs:
    3. text = clean(doc.text) # Cleaning: denoise, dedupe, normalize punctuation
    4. chunks = splitter.split(text) # Splitting: along semantic boundaries, with overlap
    5. for c in chunks:
    6. c.meta = {
    7. "source": doc.title, # Metadata: source, chapter, time
    8. "chapter": c.chapter,
    9. }
    10. vec = embedder.encode(c.text) # Embedding: call the embedding API
    11. store.add(c.text, vec, c.meta) # Persist: vector + original text + metadata

    Layer 4 is the application layer. It provides question answering, retrieval, summarization, and relation extraction. The core of this layer is the prompt and context assembly strategy, covered in the next section.

    4. Retrieval-Augmented Generation: Make the Model Read the Material First

    If you ask a model directly “what are the character relationships in this book,” the output is likely a vague impression based on training data, prone to fabrication that conflicts with the original text. The solution is retrieval-augmented generation (RAG), a fixed four-step flow:

    1. Rewrite the user question into a semantically clear search query;
    2. Recall several candidate segments from the local index;
    3. Truncate by relevance, assemble them into the context, and clearly label the sources;
    4. Require the model to answer only from the given segments, and to state clearly “not mentioned in the material” when there is no basis.

    A reusable prompt skeleton:

    1. You are a material analysis assistant. Answer questions only based on the [Material] below.
    2. If the material is insufficient to support a conclusion, state directly "the existing material is insufficient to judge"; do not speculate.
    3. [Material]
    4. [1] Source: xxx Chapter: xx
    5. (Segment content)
    6. [2] Source: xxx Chapter: xx
    7. (Segment content)
    8. [Question]
    9. (User question)
    10. [Output requirements]
    11. 1. Give the conclusion first; 2. Then list supporting points with citation numbers; 3. Finally point out gaps in the material.

    An easily underestimated detail here is the citation numbering mechanism. Requiring the model to output citation sources significantly reduces fabrication and makes manual traceback and verification easier.

    5. Dividing Work Between Model Types: Reasoning vs. Chat

    The same knowledge base often runs different tasks, and using one model for all of them is not economical. The industry commonly groups models into two types by tendency:

    • Reasoning-oriented: good at multi-step derivation, divergence, and causal analysis; suited to plot mapping, foreshadowing analysis, and setting conflict checks, but also more prone to “over-interpretation”;
    • Chat-oriented: restrained in expression and closer to the original text; suited to material lookup, excerpting, and format conversion.

    The practical combination is: give retrieval and excerpting to the chat-oriented model to ensure fidelity; switch to the reasoning-oriented model for cross-chapter reasoning, and run a second check on the output. This division is more stable than “one model does everything” and makes it easier to locate which step a problem comes from.

    6. Three Practical Strategies for Long Text

    Segmented rolling summarization. For very long documents, produce local summaries first, then merge them into a global summary, avoiding stuffing content beyond the context window all at once.

    Hierarchical indexing. Build a three-level “book—chapter—segment” structure; retrieval first locates the chapter and then the segment, significantly reducing ineffective recall.

    Caching and incremental updates. Cache embedding results by content hash, and process only the incremental part when new chapters are added; retrieval results for the same question can also be cached short-term to reduce repeated calls.

    7. Cost Control and Stability

    • Separate embedding calls from generation calls; embedding runs once, while generation is the ongoing cost;
    • Control context length, including only truly relevant segments, since irrelevant content both costs money and interferes with judgment;
    • Retry with backoff; do not retry densely when rate-limited;
    • Persist everything to disk, logging all requests and responses locally for review and reprocessing;
    • De-identify sensitive information, replacing real names, contact details, and similar fields before sending out.

    8. Troubleshooting Common Issues

    Symptom Common cause Fix
    Answers conflict with the original text No RAG, or segments without overlap Enforce citation numbers, adjust split overlap
    Inaccurate retrieval recall Vector-only, missing keyword index Switch to hybrid retrieval with fused ranking
    No response for a long time Peak-hour queueing Switch to asynchronous batch processing, or a tiered channel
    Summary misses key settings Over-compression in one pass Switch to hierarchical rolling summarization

    9. Conclusion

    The technical difficulty of building a local web-novel knowledge base has never been “moving the model to local,” but making the data workflow solid. Clarify the division of responsibility between local and cloud, get the fundamentals right—splitting, metadata, and hybrid retrieval—and combine them with model division of labor and prompt constraints. Even ordinary hardware can then stably support a personal knowledge base that keeps accumulating and remains traceable and verifiable.