Building a Local Web Novel Knowledge Base with API Calls
This article explains how to build a private knowledge base for web novel writing by calling cloud LLM APIs instead of relying on local deployment. It covers why long-form fiction needs retrieval over the full manuscript, the trade-offs between local inference and API access, how to route tasks between reasoning-oriented and general-purpose models, a four-layer architecture (data, processing, retrieval, inference), chunking and hybrid retrieval details for long documents, prompt constraints and programmatic result validation, and practical tuning advice for latency, vague answers, terminology consistency, and cost control.
1. Why Web Novel Writing Needs a Private Knowledge Base
Writing web novels differs sharply from general short-form writing: a single work often runs to hundreds of thousands or even millions of words, with worldbuilding, character relationships, and foreshadowing scattered across a large number of chapters. What authors actually want is not “have the model write a paragraph,” but to have the model retrieve, compare, and reason over their entire manuscript. Typical questions include:
- Does a supporting character’s identity mentioned in chapter 30 conflict with their own account in chapter 80?
- After a piece of foreshadowing is planted, is the necessary setup missing from earlier text?
- Is the power system and its tier structure self-consistent across the whole book?
- Under a non-linear timeline, do the events still hold in the correct order?
These tasks share three traits: extremely long context, a need for exact quotation from the source, and repeatable verification. General-purpose web chat entry points usually impose a per-input length limit, a limited session context, and queuing at peak times, which makes them a poor fit for book-scale material. Decoupling “model capability” from “local data” and feeding local files to the model through an interface is the more engineering-minded approach.
2. Key Choice: Local Deployment or API Calls
A common misconception is that local deployment is always more private and more cost-effective. In practice, the answer depends on the scenario.
The practical constraints of local deployment. Today’s flagship open-source large-parameter models in the industry demand a great deal of VRAM and system memory, and consumer-grade GPUs generally cannot host a full-precision version. What users can actually run is mostly a distilled or quantized small-parameter variant. Small-parameter models struggle noticeably on long-chain reasoning and cross-chapter consistency checks, often contradicting themselves or dropping constraints, so the return on investment is unattractive.
When calling an API makes sense. Accessing a cloud model through an interface means only the source manuscript and a client stay local, while inference happens on the model side. The advantages are:
- No local hardware ceiling, so you can use models with larger parameter counts and stronger reasoning;
- Any number of long files can be stored locally, with no worry about “fitting into the chat box”;
- No operational overhead for drivers, VRAM, or quantization configuration.
The price to accept is network round-trip latency, and free tiers may queue at peak times; if response speed matters, a higher-priority pay-as-you-go channel is an option.
Conclusion: unless you have hardware able to fully host a flagship-scale model, calling an API is the more pragmatic choice for individual authors and small to mid-sized teams.
3. Model Roles: Pairing Reasoning and General-Purpose Models
Interface platforms usually offer two categories of models, and understanding the difference matters more than memorizing names:
- Reasoning-oriented models: strong at multi-step derivation, divergent thinking, and causal analysis, which suits logic checks, foreshadowing mapping, and setting-conflict detection; they are also more prone to “over-association,” producing plausible-sounding content with no basis in the source text.
- General-purpose models: restrained and closely tied to the input, which suits deterministic tasks such as data lookup, summary extraction, and terminology unification.
The practical recommendation is routing by task: use the reasoning-oriented model when a judgment is needed, and the general-purpose model when extraction is needed. Also, requiring citations to the source in the prompt (chapter number or paragraph locator) significantly suppresses unfounded fabrication.
4. Overall Architecture: A Four-Layer Local Knowledge Base
A maintainable design can be split into four layers:
- Data layer: a local directory holds chapter plain text with consistent encoding and naming (e.g.,
book/vol01/ch001.txt) so references are easy to locate. - Processing layer: handles cleaning (removing ads and duplicate paragraphs), chunking, and generation of vector and keyword indexes.
- Retrieval layer: hybrid retrieval, where vector recall handles semantic similarity and keyword recall handles exact matches on proper nouns such as character names, place names, and technique names.
- Inference layer: calls the model through an interface, assembles retrieved fragments into context, and outputs conclusions with citations.
A sketch of the call flow (pseudocode that expresses the process only and points to no specific interface):
def ask(question, book_id, top_k=8):chunks = hybrid_search(book_id, question, top_k) # vector + keywordcontext = "\n\n".join(f"[{c.chapter}] {c.text}" for c in chunks)prompt = f"""You are a setting review assistant. Answer only from the source text below,and mark the source chapter after each conclusion; if the source does not mention it, answer "Not found in the source text".Source text:{context}Question: {question}"""return llm.chat(model=select_model(question), messages=prompt)
5. Long Document Handling: Chunking and Retrieval Details
A long text cannot be pushed into the context whole, so the chunking strategy decides success or failure:
- Split on semantic boundaries: prefer breaking at chapter or scene transitions, avoiding cutting a dialogue in half;
- Moderate overlap: keep some overlap between adjacent fragments to prevent losing cross-fragment references;
- Metadata travels along: each fragment carries the book title, volume, chapter, and paragraph order for traceback and citation;
- Persist indexes: write vector and keyword indexes to disk for reuse, avoiding recomputation on every question;
- Incremental updates: when new chapters are added, process only the increment so the knowledge base stays in sync with writing progress.
6. Prompts and Result Validation
The reliability of review tasks comes mainly from constraints rather than the model’s own restraint. Three rules can be fixed: answer only from the given source text; attach the source chapter to every judgment; and explicitly output “not found” when evidence is insufficient. Running a programmatic check on the returned result, for example verifying whether each cited chapter falls within the candidate fragment set, can intercept most hallucinated output.
7. Common Issues and Tuning Advice
- Slow responses or queuing: prefer a paid priority channel, or turn the task into offline batch processing and run full reviews at night;
- Vague conclusions: increase the number of retrieved fragments and compress the length of each one so the context is more focused;
- Inconsistent proper nouns: maintain a local glossary and inject it into the prompt as a hard constraint;
- Out-of-control cost: separate task tiers, sending extraction tasks to a lightweight model and reasoning tasks to a stronger model, and cache repeated questions.
8. Closing Thoughts
Treating a large model as “a reasoning engine that can be driven by local data” rather than an omniscient author is the core insight of this approach. With sensible model selection, rigorous chunking and hybrid retrieval, and strongly constrained prompts plus result validation, authors can own a private web novel knowledge base on ordinary hardware that keeps accumulating and supports precise traceback, freeing their energy to go back to the story itself.
