Building a Local Web Novel Knowledge Base: LLM API Integration and Retrieval-Augmented Generation in Practice
This article walks through building a local knowledge base for web novels using cloud LLM APIs instead of local deployment. It covers a four-layer architecture (source, index, retrieval, generation), chunking strategies for long documents, a three-step RAG pipeline with citation constraints to reduce hallucination, how to split work across reasoning, chat, and embedding models, and the reliability, cost, and observability practices needed for external API calls. A deployment checklist and common pitfalls are included. Readers will learn how to keep data local while relying on cloud compute, and why a complete engineering loop matters more than owning high-end hardware.
1. Make a Rational Choice First: Local Deployment or API Calls
Many tutorials jump straight into local deployment steps. Before that, it is worth answering a prerequisite question: do your hardware and your task goals actually match?
Local LLM inference is highly sensitive to VRAM, memory bandwidth, and quantization. Taking a common dense model as an example, the full version at hundreds of billions of parameters requires far more VRAM than a typical consumer GPU can provide, even with low-bit quantization. Distilled small and mid-sized variants can run on ordinary devices, but on tasks such as long-chain reasoning, untangling complex settings, and extracting multi-character relationships, they often fall below a usable threshold. The result: you spend a lot of time configuring the environment, and the output quality is not enough to support a real workflow.
For most individual users and small teams, the more practical path is calling a cloud model API: leave the compute problem to the server side and put your energy into data organization and pipeline design. This approach has three core advantages:
- No local VRAM ceiling: you can feed in very large long documents in one pass, without repeatedly compressing or trimming them;
- No peak-hour unavailability: you are not competing for local resources; server-side queuing may add latency but usually does not fail outright;
- Continuous model upgrades: the platform handles server-side iteration, so the application side does not need to be rewritten.
Calling an API does not mean giving up on keeping things local. On the contrary, the knowledge base itself, the vector index, and all source material stay on your machine; only the fragments that need inference are sent to the server. This split of “data local, compute in the cloud” is a fairly balanced engineering compromise between privacy and quality.
2. Overall Architecture: A Four-Layer Breakdown
A usable local web novel knowledge base can be abstracted into four layers:
- Source layer: raw text files, setting notes, and chapter drafts, all normalized into plain text or a structured markup format;
- Index layer: chunking, vectorization, and writing into a local vector store, with metadata attached (title, chapter number, timeline, character tags);
- Retrieval layer: on receiving a query, first run vector similarity recall, then filter by keyword or metadata, and add reranking when necessary;
- Generation layer: assemble the recalled fragments into a prompt, call the cloud model API to produce an answer, and write back the citation sources.
The benefit of decoupling these four layers is that any one of them can be replaced independently. For example, switching the generation layer from a reasoning model to a general chat model requires no change to the index structure.
3. Long Document Handling: Chunking Strategy Sets the Ceiling
Web novel material is typically “long, scattered, and repetitive.” A single work can easily run to millions of words, with character relationships spanning hundreds of chapters. Stuffing the entire text into the context window is neither economical nor reliable. The common industry practice is chunking plus retrieval:
Raw chapters→ Cleaning (remove ads, remove duplicate separators, normalize punctuation)→ Semantic chunking (by scene/paragraph boundaries, not fixed character counts)→ Overlap between chunks (keep a little context to avoid broken references)→ Vectorize and write into the local index
Chunk size is a tradeoff between “semantic completeness” and “retrieval precision”: chunks that are too large bring noisy recall and the model gets distracted by irrelevant details; chunks that are too small break references and causal chains, and answers become self-contradictory. In practice, keep a certain overlap ratio between chunks and attach structured metadata to each chunk so you can later filter by work, timeline, or character.
4. Retrieval-Augmented Generation: Make Answers Traceable
Relying purely on model memory to answer questions about private settings inevitably produces “plausible but fabricated” results. The value of retrieval-augmented generation (RAG) is to constrain generation to verifiable source material. A robust pipeline has three steps:
- Recall: take Top-K by vector similarity; K should not be too large, so start with a relatively wide range;
- Filter and rerank: filter out irrelevant works by metadata, then use a reranking model or rule-based scoring to compress down to the few fragments actually injected;
- Constrained generation: the prompt explicitly requires “answer only from the given fragments, and state clearly when information is missing.”
Example prompt structure:
You are a setting research assistant. Answer only from the [Source Fragments] below; do not introduce information outside the fragments.If the material is insufficient, state directly: "Not covered by the available material."[Source Fragments]<chunk id="...">...</chunk>[Question]...[Output] Conclusion + cited chunk IDs
Requiring the model to cite chunk IDs is a practical way to suppress hallucination: answers can be traced back, and errors can be located.
5. Model Roles and Prompt Design
Different types of models suit different stages, and mixing them usually works better than “one model for everything”:
- Reasoning models: suited to setting-conflict checks, timeline deduction, and causal analysis of plot; strong at divergence, but need tighter constraints to prevent going out of bounds;
- General chat models: suited to material lookup, summarization, and style imitation; output is more restrained and stable;
- Embedding models: map text into comparable vectors; their quality directly sets the recall ceiling and must match the language of your corpus.
In engineering terms, split “query rewriting,” “answer generation,” and “result verification” into separate calls, each with its own prompt template, so it is easy to pinpoint which stage a quality problem comes from.
6. Stability, Cost, and Observability
Any external API call must be designed on the assumption that “it will fail”:
- Timeouts and retries: set reasonable timeouts and use exponential backoff retries to avoid a transient queue breaking the pipeline;
- Fallback strategy: when the primary model is unavailable, switch to a backup model or return the retrieved fragments for human judgment;
- Cache layer: cache high-frequency repeated queries locally to cut both latency and cost;
- Usage monitoring: log input/output size, latency, and failure rate for every call to build an observability dashboard;
- Cost control: free tiers are fine for prototype validation, while steady use requires pay-as-you-go billing; for lower latency you can choose a higher service tier, which is essentially paying for queue priority.
7. Implementation Checklist
- Complete account registration and key management; store keys only in local environment variables, never in the code repository;
- Choose a model service that supports long context and embedding, and confirm the boundaries of its general capabilities;
- Build a local client or your own scripts that wrap calls, retries, and logging in a unified way;
- Set up a material cleaning and chunking pipeline that outputs text chunks with metadata;
- Write into the local vector index, validate recall quality, and tune parameters;
- Wire up the generation stage, adding citation constraints and missing-information declarations;
- Build an evaluation set (common questions plus reference answers) and run continuous regression so quality does not degrade after switching models.
8. Common Pitfalls
- Blind faith in local deployment: when hardware falls short, the output of a distilled small model is often worse than a cloud API call;
- Feeding the whole text at once: the longer the context, the higher the chance key information gets diluted; retrieval beats piling on material;
- Ignoring metadata: without work and timeline tags, cross-work retrieval will inevitably mix things up;
- Skipping evaluation: any change to the model or chunking parameters can shift results significantly, and without an evaluation set you cannot attribute the cause.
In summary, the key to building a local web novel knowledge base is not whether you own a top-tier GPU, but whether you have established a complete engineering loop of “local data governance + cloud compute calls + retrieval-constrained generation.” Make the controllable parts solid and hand the uncontrollable parts to the server side; that is the sustainable approach.
