Building a Local Web Novel Knowledge Base by Calling an LLM API

    This article explains why calling a remote LLM API is often more practical than local deployment for a private knowledge base, and walks through the full workflow: preparing an account, API key, and desktop client; choosing between reasoning and general-purpose models; chunking, embedding, retrieving, and reranking source material; writing prompt constraints that reduce hallucination; and handling cost, rate limits, and troubleshooting. Readers will learn how to keep storage and indexing local while offloading compute to the server, so ordinary hardware can support stable, extensible, and cost-controlled knowledge retrieval and writing assistance.

    1. First Decision: Local Deployment or API Calls

    When many people set up a private knowledge base, their first instinct is to download the model and run it locally. The idea is technically valid, but the barrier is widely underestimated. To get an experience close to an online service, you typically need a full model with a very large parameter count, which imposes hard requirements on VRAM, memory bandwidth, power delivery, and cooling. Consumer-grade GPUs can rarely handle it. Even if it barely runs, first-token latency and generation speed make interaction hard to tolerate.

    If you fall back to a distilled small-parameter version, the problem shifts to capability. Distilled models degrade noticeably in instruction following, long-chain reasoning, and terminology consistency. For tasks such as mapping character relationships in long web novels, checking whether foreshadowing is paid off, and detecting setting conflicts, they tend to give off-topic answers and contradict themselves. My recommendation is direct: unless you have the hardware for a full-size model and the operational capacity to maintain it, do not take the local deployment route.

    Calling a remote API is the more pragmatic option, with three core benefits:

    • Locally you only store source material and index files, leaving heavy computation to the server;
    • You are not limited by the length of a web chat window, so you can feed in whole-volume or whole-book documents at once;
    • You avoid the uncertainty of “queue busy, no response at all” during peak hours; requests eventually return a result, they just require more patience.

    Note that the free tier channel may take one or two minutes to respond to a single request during peak hours, but it usually does not fail outright. The paid channel is like a dedicated line with fewer people, so it responds faster. For high-frequency writing workflows, paying a moderate amount to reduce latency is a reasonable trade-off.

    2. Preparation: Account, Key, and Client

    The overall pipeline can be summarized as: source files → client → API gateway → model service → results returned → written to local storage. You need three things.

    First, a usable model service account. Complete registration on the sign-up page of any compliant model service platform, then create an access key (API Key) in the console. The key is equivalent to an account credential and should only be kept in a local environment variable or in the client’s key configuration. Do not write it into a code repository, paste it into a chat group, or commit it to version control.

    Second, a desktop client that supports a knowledge base and switching between multiple models. An open-source or free general-purpose client is fine, but confirm the version number is new enough (0.9 or above). Older versions (the 0.8 series) lack a lot of capability in knowledge bases, embedding model configuration, and tool calling, so following a tutorial will get you stuck at some step.

    Third, organize the source directory. Store files in layers by “work / volume / chapter”, with sequence numbers in filenames, and use plain text or Markdown for the body, stripping headers, footers, and leftover ads. Clean material is the precondition for good retrieval quality later.

    3. Model Selection: Dividing Labor Between Reasoning and General-Purpose Models

    A single platform usually offers several tiers of models, and the most valuable distinction in practice is between two capability types.

    Reasoning models are good at multi-step decomposition and divergence, suited to tasks requiring long-chain thinking such as “what directions could this plot take” and “check whether the timeline across these three chapters conflicts”. But their constraints are weaker, and there is a risk of freely improvising beyond the material. General conversational models are more restrained and more faithful, suited to query- and excerpt-oriented tasks such as “find every passage that mentions a particular technique” and “verify character ages against the setting table”.

    A stable approach is dual-model collaboration: first use a general-purpose model for extraction and locating, use the result as context, then hand it to a reasoning model for judgment and suggestions. A schematic call skeleton follows (pseudocode, expressing the flow only):

    1. # 1) Retrieval: fetch relevant chunks from the local vector index
    2. chunks = index.search(query, top_k=8)
    3. # 2) Extraction: general-purpose model produces faithful excerpts
    4. facts = chat(model="general-chat", messages=[
    5. {"role": "system", "content": "Answer only from the given material; reply \"not found\" if missing."},
    6. {"role": "user", "content": f"Material: {chunks}\nQuestion: {query}"}
    7. ])
    8. # 3) Reasoning: reasoning model judges conflicts and gives advice
    9. advice = chat(model="reasoning", messages=[
    10. {"role": "system", "content": "Reason from confirmed facts and flag uncertain items."},
    11. {"role": "user", "content": f"Facts: {facts}\nPlease check for setting conflicts"}
    12. ])

    4. Building the Knowledge Base: Chunking, Embedding, and Retrieval

    A knowledge base is not a pile of files; it is a searchable index. The process has four steps.

    Chunking. Split on semantic boundaries rather than cutting at a fixed character count. Prefer breaking at chapter or scene transitions, keep each chunk at 300–800 characters, and insert path information “work-volume-chapter” at the start of each chunk, so the model still knows the source even when context is cut.

    Embedding. Call the platform’s text embedding capability to turn each chunk into a vector and store it in a local vector store or a lightweight index file. The embedding model is independent of the later chat model; just pick a general embedding model with stable Chinese performance.

    Retrieval. When the user asks a question, embed it first, run similarity recall, and take the top few chunks; optionally layer keyword retrieval on top for hybrid recall. For low-frequency terms such as proper nouns, technique names, and place names, keyword matching is often more accurate than pure vectors.

    Reranking and assembly. Rerank the recalled results once, drop duplicates and low-relevance content, then assemble into the context within budget. Context is not better when longer; excessive length dilutes key information and raises cost.

    Storage and incremental updates. Write each round’s “question + cited chunks + conclusion” to a local file or database, forming traceable notes; when adding chapters, embed only the new chunks and append to the index instead of rebuilding everything.

    5. Prompts and Context Constraints

    When a knowledge base underperforms, most of the time the model is not the problem; the constraints were not written clearly. Pin four rules in the system prompt:

    1. Answer only from retrieved material, and explicitly reply “not found” when the material does not cover it;
    2. Annotate the source path after each conclusion for manual verification;
    3. When setting values are involved (age, realm, distance, time), list the original textual basis item by item;
    4. Distinguish “material facts” from “your inference”, and label the inferred part separately.

    These constraints significantly reduce hallucination and turn output from “looks reasonable” into “can be accepted”.

    6. Cost, Rate Limits, and Stability

    • Cost optimization: separate embedding and generation call volumes, use cheaper models in the retrieval stage; cache results of high-frequency questions; control top_k and context length.
    • Rate limit handling: set timeouts and exponential backoff retries in the client to avoid misjudging a long silence as a failure.
    • Privacy and compliance: material may contain unpublished content; confirm the platform’s data usage terms before calling, and mask sensitive fields when necessary.
    • Observability: log the model, elapsed time, token usage, and matched chunks for each request locally, to support optimization and review.

    7. Troubleshooting Common Issues

    A request that stays unresponsive for a long time is usually peak-hour queuing: extend the timeout and switch to the paid channel. Answers unrelated to the material usually mean nothing was retrieved at all; print the recalled chunks first to check. Poor recognition of proper nouns calls for adding hybrid keyword retrieval. When a long document “will not fit”, reduce top_k, compress chunk length, or switch to per-section summaries followed by aggregation. If the client has no knowledge base entry point, the version is almost certainly too old; upgrade to 0.9 or above.

    8. Summary

    The key to building a local web novel knowledge base is not bringing a large model home, but getting the division of labor right: storage and indexing local, compute on the server. Choose the right model type, connect the pipeline with a reliable client and key management, ensure recall with semantic chunking plus hybrid retrieval, keep hallucination within an acceptable range with strict prompt constraints, and keep iterating through logs and incremental updates. Follow this process and ordinary hardware can deliver stable, extensible, cost-controlled private knowledge retrieval and writing assistance.