Building a Local Web Novel Knowledge Base with LLM API Calls

    This article explains why a local knowledge base does not require running a model locally, and instead pairs cloud LLM API inference with local data handling and orchestration. It covers a four-layer architecture, chapter-aware chunking and metadata strategies, dual vector and keyword retrieval, structured prompt assembly with source citations, model routing for cost control, and a troubleshooting table for common issues.

    1. Why a “Local Knowledge Base” Is Not the Same as “Running a Model Locally”

    When creators set out to build a web novel knowledge base, the first instinct is often to download the model and run it on their own machine. That approach usually does not hold up in engineering practice. Full-parameter general-purpose LLMs typically reach hundreds of billions of parameters, with heavy demands on VRAM, memory bandwidth, and inference compute. What consumer-grade GPUs can actually host are mostly distilled, compressed mid- and small-parameter variants. Such lightweight models are acceptable for general conversation, but once a task requires long-range reasoning—extended narrative, complex character relationships, or paying off earlier foreshadowing—their quality drops noticeably, with contradictions across sections, lost details, and unstable instruction following.

    A more pragmatic route is therefore: keep inference on a cloud API, and keep data and orchestration local. The local side handles document parsing, chunking, vectorization caching, retrieval, and prompt assembly, while model inference happens over a standard HTTP interface. Three benefits follow:

    • No high-end GPU is needed locally; an ordinary office laptop can manage the knowledge base.
    • You can feed in hundreds of thousands or even over a million characters of material in one pass, without the length limits of a web chat window.
    • Peak-hour queuing and unresponsive sessions are avoided; tasks can be retried asynchronously, so a single failure does not invalidate the whole run.

    Note that cloud APIs also have rate limits and queue delays, and response times anywhere from a few seconds to a minute or two are normal. Architecturally, “slow” should be treated as the normal case, not as an exception.

    2. Overall Architecture: Four Layers

    A usable local web novel knowledge base can be abstracted into four layers:

    1. Access layer: a unified wrapper for API calls that hides differences in authentication, request formats, and rate limiting across vendors.
    2. Processing layer: document parsing, cleaning, chapter splitting, and metadata extraction.
    3. Index layer: a vector index plus a keyword inverted index, with dual-channel recall.
    4. Application layer: Q&A, setting retrieval, character card generation, timeline organization, and style consistency checks.

    A sketch of the access layer wrapper (pseudocode, structure only):

    1. class LLMClient:
    2. def __init__(self, base_url, api_key, model):
    3. self.base_url = base_url
    4. self.api_key = api_key
    5. self.model = model
    6. def chat(self, messages, temperature=0.3, timeout=180):
    7. # Exponential backoff retry to handle rate limits and queuing
    8. for attempt in range(4):
    9. try:
    10. return self._request(messages, temperature, timeout)
    11. except RateLimited:
    12. time.sleep(2 ** attempt)
    13. raise RuntimeError("Call failed, please retry later")

    Key design points: set generous timeouts, retry with backoff, and keep temperature low. Knowledge base retrieval tasks aim for stable, reproducible output rather than creative divergence.

    3. Ingesting the Corpus: Chunking Strategy Sets the Retrieval Ceiling

    Web novel material has very distinct structural traits: organized by chapter, several thousand characters per chapter, heavy on dialogue and interior monologue, and dense with proper nouns. Recommended chunking strategy:

    • Use the chapter as the base unit, then split again by semantic paragraph, keeping each chunk at 500–800 characters with 10%–15% overlap so key settings are not cut apart.
    • Retain metadata explicitly: work title, chapter number, point-of-view character, timeline position, and tags (for example “sect setting” or “cultivation system”).
    • Build a terminology dictionary: map character aliases, place names, and technique names to canonical forms, and expand with synonyms at retrieval time.
    • Dual-index recall: vector retrieval handles semantic similarity (“the protagonist’s master’s past”), keyword retrieval handles exact matches (an invented move name), and the two result sets are merged and reranked.

    The ingestion pipeline is best built as resumable batch processing: after each batch completes, write to a local queue, and replay failed batches separately. That way API rate limiting does not roll back the entire job.

    4. Prompts and Context Assembly

    Retrieved fragments should not be concatenated and handed to the model as-is; they need structured assembly:

    1. You are a setting review assistant. Answer only from the material below, and state "not covered by the material" when it is insufficient.
    2. [Material]
    3. [1] Source: work title / Chapter N
    4. ...
    5. [Question]
    6. ...
    7. [Output requirements]
    8. 1. State the conclusion first; 2. then list the source numbers used as evidence; 3. mark anything uncertain as to be confirmed.

    Three practical lessons:

    • Require source numbers in citations, which significantly reduces fabrication.
    • Allow “admit when the material is insufficient”, turning hallucinations into detectable gaps.
    • Summarize long context in segments, then aggregate: first generate a structured summary for each batch of material, then do a second pass over those summaries. This is more stable than stuffing in the full text at once.

    5. Model Selection and Cost Control

    A single platform usually offers both a reasoning-oriented and a conversation-oriented model. The former is good at multi-step reasoning and divergence, and suits plot logic analysis and foreshadowing analysis, but is more prone to making things up; the latter is more restrained and suits fact-based retrieval and excerpt organization. The recommendation is to route by task rather than use one model globally.

    Cost control measures:

    • Caching: cache retrieval results for repeated questions locally, and skip the call on a hit.
    • Tiering: run a cheap first-pass filter, and call the reasoning model only for high-value questions.
    • Quotas: set a daily call limit and a maximum input length per request.
    • Offline fallback: summarization and extraction tasks can run on a local lightweight model, reserving cloud quota for complex reasoning.

    6. Common Issues and Troubleshooting

    Symptom Common cause Fix
    No response for a long time Server-side queuing Loosen the timeout, retry asynchronously
    Answers that contradict the source text Chunking broke the context Increase overlap, split by chapter
    Confused proper nouns No terminology mapping Build an alias dictionary
    Inaccurate retrieval recall Relying on vectors only Add a keyword channel and merge results
    Quota consumed too fast No caching or tiering Introduce caching and task routing

    7. Conclusion

    The core strength of a local web novel knowledge base is not “how large a model you can run,” but the quality of data organization and the precision of retrieval. Hand inference to a stable API service, and invest your effort in chunking, metadata, the terminology system, and prompt constraints—ordinary hardware can then support a creation-assistance system that keeps evolving over time. If you later need higher concurrency or data compliance, you can evaluate combining general cloud capabilities such as containerized deployment, object storage archiving, and logging with monitoring and alerting.