Building a Local Knowledge Base for Web Novel Writing with Cloud LLM APIs
This article explains how to build a local knowledge base for web novel creation using cloud-based LLM APIs, without deploying a model on your own hardware. It covers a four-layer architecture (data, processing, retrieval, and generation), task-based model selection, long-text chunking and metadata design, prompt strategies for controlling hallucination, and practical advice on cost, latency, and data security. Readers will find a clear implementation path from a minimal prototype to a scalable, long-running system.
1. A Local Knowledge Base Does Not Require a Locally Deployed Model
Many readers new to LLM applications conflate two different things: running a model on your own machine and keeping your data library on your own machine. The first is a compute problem; the second is a data organization problem. For web novel writing and reference material management, the second is what actually matters—you want to centrally manage hundreds or thousands of long documents, setting bibles, and chapter drafts, and have the model answer questions, run consistency checks, and generate summaries based on that content at any time.
The reasons for not recommending that ordinary users deploy an LLM on personal hardware are not mysterious. The open-source community does offer models at different parameter sizes, but smaller distilled versions show clear gaps compared to the originals in long-range reasoning, detail retention, and instruction following. When handling complex setting relationships, they tend to produce contradictions or omit key constraints. Meanwhile, fully capable versions require far more VRAM, memory, and bandwidth than typical consumer hardware can provide, so the real experience often falls short of expectations. In contrast, calling a cloud model through an API means you only pay for usage and get stable inference capability, while keeping only the data and retrieval logic locally. The architecture is lighter and cheaper to maintain.
It is worth noting that cloud calls introduce network latency, and queuing during peak hours is normal. The engineering response is not to complain about latency but to design requests more sensibly: merge small requests, control context length, cache results, and convert non-real-time tasks into batch jobs.
2. Overall Architecture: Four Layers
A usable local web novel knowledge base can be split into four layers, each with a single responsibility, making them easy to replace and debug.
- Data layer: A local folder manages raw materials, including novel text, setting notes, character cards, and timeline tables. It is best to standardize on plain text or structured text formats, with normalized filename prefixes for easy sorting and incremental syncing.
- Processing layer: Responsible for parsing, cleaning, chunking, and vectorization. Chunk size is the most critical parameter here—chunks that are too large make retrieval imprecise, while chunks that are too small break semantic continuity.
- Retrieval layer: Uses a local vector index for similarity recall, while retaining keyword search as a supplement to form hybrid retrieval. Vector retrieval excels at semantic similarity, and keyword retrieval excels at exact matches on proper nouns. The two complement each other and significantly reduce missed recalls.
- Generation layer: Assembles the recalled fragments into a prompt, calls the cloud model API to produce results, and writes the Q&A records back to local storage, forming reusable knowledge accumulation.
A schematic call skeleton is shown below (it only expresses the general calling logic and does not involve any specific vendor interface):
def ask_knowledge_base(question, retriever, client, top_k=5):# 1. Retrieval: vector recall + keyword recall, deduplicate and take the top kchunks = retriever.hybrid_search(question, top_k=top_k)# 2. Assemble context: label sources for traceability and citationcontext = "\n\n".join(f"[Source {i+1}] {c.text}" for i, c in enumerate(chunks))# 3. Build the prompt: constrain the model to answer only from the contextprompt = ("You are a reference material assistant. Answer only based on the ""materials below. If the materials do not cover something, explicitly ""state 'not mentioned in the materials'. Do not speculate.\n\n"f"Materials:\n{context}\n\nQuestion: {question}")# 4. Call the cloud model; streaming output is recommended to improve the waiting experienceresp = client.chat.completions.create(model="<fill in the model name you use>",messages=[{"role": "user", "content": prompt}],temperature=0.3,stream=True,)return resp
3. Model Selection: Split by Task, Not by Finding the “Strongest Model”
Practical experience shows that different tasks prefer different model characteristics. Creative, divergent tasks—such as plot deduction and brainstorming scenes—are better suited to reasoning models, which are more willing to unfold multi-step thinking. Factual lookup tasks—such as “which chapters does a character first appear in” or “does a setting conflict with later text”—are better suited to a more restrained general-purpose chat model, whose output is more on-topic and less prone to free improvisation.
The engineering recommendation is to abstract the two model types into configuration items and route by task:
models:reasoning: # for deduction, rewriting, and creative divergencetemperature: 0.7factual: # for retrieval Q&A and consistency checkstemperature: 0.2
The temperature parameter is the lowest-cost tuning lever. Lowering the temperature for factual tasks noticeably reduces unwarranted elaboration; raising it moderately for creative tasks gives the output variation. Also, always set a maximum output length and timeout with retry to avoid waiting indefinitely during long-text generation.
4. Key Details for Long-Text Processing
Web novel material typically features extreme length per document, dense proper nouns, and interwoven timelines. Stuffing an entire document into the context is neither economical nor accurate; you must rely on chunking and retrieval.
- Chunking strategy: Prioritize splitting on chapter and natural paragraph boundaries, then add an overlap window (for example, one or two sentences of overlap between adjacent chunks) to avoid cutting off key references.
- Metadata design: Attach the work title, chapter number, timeline marker, and character list to each chunk. At retrieval time, filter by metadata first, then compute similarity within the subset—this noticeably improves accuracy.
- Proper noun protection: Build a local dictionary to normalize synonyms for character names, place names, technique names, and so on, preventing the same entity from being split into multiple entities.
- Incremental updates: Use file hashes to detect changes and process only new or modified files, avoiding a full index rebuild every time.
- Traceable citations: Force answers to carry source numbers for manual verification—this is the baseline for trustworthiness in knowledge base applications.
5. Prompt Design and Output Quality Control
The model “confidently making things up” is the most common failure mode for this kind of system. Switching models cannot fix it at the root; constraint design can:
- Define boundaries: Require the model to explicitly declare missing information when the materials are insufficient, rather than filling in with imagination.
- Structured output: When a summary is needed, directly request a table or fixed fields for easier downstream program parsing.
- Step-by-step verification: Break consistency checks into three steps—“list relevant settings, compare item by item, produce a conflict list”—which is far more stable than a single all-in-one query.
- Secondary validation: Add a low-temperature recheck request with original-text citations for key conclusions. It costs little but catches most errors.
6. Cost, Latency, and Data Security
On cost, the main variable is the total number of input and output tokens. Control measures include: recalling only necessary fragments, caching high-frequency questions locally, and batching summary-type tasks during off-peak hours. Most platforms offer a difference between free tiers and paid tiers, which is essentially a difference in concurrency and queue priority. For light usage, start with the free tier to validate the workflow, then consider paid plans once it is stable.
On latency, streaming output significantly improves the perceived experience. Combined with a prompt that “gives the conclusion first, then fills in details,” users will hardly feel stuck. Also set reasonable client timeouts and backoff retries to avoid a transient failure escalating into a full outage.
On data security, once data leaves the network it is outside the local boundary. It is advisable to desensitize sensitive content or summarize it locally before uploading, use an encrypted channel for transmission, and store keys in local environment variables or a key management service—never hard-code them into source code or commit them to version control. At the same time, keep the local raw materials as the single source of truth, with the cloud serving only the compute role.
7. Suggested Implementation Roadmap
Step one: run a minimal closed loop of “chunking—vectorization—retrieval—calling” with a small set of documents. Step two: add metadata filtering and hybrid retrieval, and evaluate recall quality. Step three: route different models by task and solidify prompt templates. Step four: fill in caching, batching, logging, and monitoring alerts to form a system that can run long-term. If data volume or concurrency grows further, you can then introduce object storage for raw materials, a message queue for peak shaving, and a container platform to host retrieval services, giving the architecture horizontal scaling capability.
