Building a Local Knowledge Base for Web Novels: A Practical Guide to API Integration
This article explains why a local knowledge base does not require running a model locally, and instead pairs on-device data and retrieval with cloud-based model inference through API calls. It covers a four-layer architecture, task-based model routing, chapter-aware chunking and metadata design, hybrid retrieval with reranking, citation constraints, and practical strategies for stability and cost control. Readers will learn how to handle long-form novel material that exceeds chat window limits while keeping hardware requirements and expenses predictable.
1. Why a “Local Knowledge Base” Does Not Mean Running the Model Locally
Many creators who are new to LLM tools share a common intuition: if the goal is to process local files and protect private source material, the model should run on the local machine too. The idea makes sense conceptually, but it often falls apart in engineering practice.
A general-purpose model with strong reasoning and long-context understanding typically has hundreds of billions of parameters. Loading the weights alone requires multiple high-VRAM accelerators working together, and the memory and bandwidth cost during inference is even higher. Consumer-grade GPUs can generally only run smaller, distilled and compressed variants. These small models degrade noticeably in instruction following, multi-step reasoning, and consistency of proper nouns. They are fine for casual chat, but when analyzing hundreds of thousands of words of novel material and mapping out character relationships and timelines, they tend to produce contradictions and miss key settings, which increases manual proofreading effort instead of reducing it.
A more pragmatic route is therefore to keep the data local and put the compute in the cloud. Only the knowledge base program and the retrieval pipeline run locally, while model inference is completed by calling a cloud service through an API. This yields three direct benefits:
- Long documents are no longer constrained by the capacity of a web chat box, and hundreds of thousands of words of volume-by-volume material can be ingested at once.
- There is no need to compete with peak-hour queues on a web front end; a request enters a queue and eventually returns instead of failing outright.
- The hardware barrier drops to an ordinary office laptop, and cost shifts from a one-time GPU purchase to usage-based operating expenditure.
2. Overall Architecture: A Four-Stage Pipeline
A usable local knowledge base for web novels can be split into four layers, decoupled from one another through standard interfaces, so replacing any one layer does not affect the others.
- Access layer: handles API credential management, request wrapping, timeouts and retries, and concurrency limiting.
- Processing layer: handles document parsing, chapter splitting, metadata tagging, vectorization, and indexing.
- Retrieval layer: handles hybrid recall combining keyword and semantic search, reranking, and context assembly.
- Generation layer: assembles recalled fragments and the user question into a prompt, calls the cloud model to produce a conclusion, and attaches sources.
Illustrative access-layer wrapping logic follows (it expresses a general approach only, not a specific API specification):
def call_model(prompt, context, timeout=180, retry=3):payload = build_payload(prompt, context) # Assemble the message bodyfor i in range(retry):try:return post_with_auth(payload, timeout=timeout)except TimeoutError:if i == retry - 1:raisesleep(backoff(i)) # Retry after exponential backoff
What matters here is not the code itself but three engineering conventions: the timeout threshold must be widened for long-text scenarios; retries must be paired with backoff, otherwise they worsen queuing; and all requests must be logged so the source of an answer can be traced back.
3. Model Selection: Dividing Labor Between Reasoning and Restrained Models
Cloud model services usually offer model options with different emphases. For a knowledge base scenario, they can be abstracted into two categories:
- Reasoning-oriented: strong at multi-step reasoning, foreshadowing analysis, and setting extrapolation. Suited to tasks like “analyze the structural problems in this plot segment” or “reason through whether a character’s motivation is self-consistent.” These models need stronger constraint prompts, or they tend to fill in content that is not in the source text.
- Restrained direct-answer: closer to factual question answering. Suited to retrieval-style questions like “in which volume does a given setting first appear” or “list all characters associated with a particular technique.” Answers are more conservative.
The practical recommendation is a dual channel: route retrieval-style questions to the restrained model, and creative assistance and logic diagnosis to the reasoning model. In code, this appears as routing by task type rather than fixing one model globally.
def route(task_type, prompt, context):model = "reasoning" if task_type in ("plot", "logic") else "concise"return call_model(prompt, context, model=model)
It is worth stressing that any model can generate content that looks plausible but does not exist in the source text. The generation layer must therefore enforce a citation constraint: require every conclusion in the answer to carry a source chapter identifier, and when no basis can be found in the recalled fragments, explicitly answer that the material does not mention it.
4. Knowledge Base Construction: Splitting and Metadata Are the Quality Foundation
The quality of ingesting long text depends eighty percent on the splitting strategy and metadata design, not on model capability.
For splitting, cutting hard at a fixed word count is not advisable. Web novels have a natural chapter structure, so the chapter should be the primary splitting unit. Overly long chapters should be split a second time by semantic paragraph, and a certain proportion of overlap should be kept between adjacent fragments so that cross-paragraph referential relationships are not severed.
For metadata, at least four kinds of fields should be tagged: work identifier, volume/chapter number, the fragment’s offset within the chapter, and coarse-grained tags for characters and locations. These fields determine whether structured filtering is possible later, for example “search only within volume three.”
{"work_id": "w-001","chapter": 128,"offset": 4096,"tags": ["character:protagonist", "location:sect"],"text": "..."}
For vectorization, a commonly used embedding model in the industry is sufficient, but the embedding model version must stay consistent within the same knowledge base. Otherwise the vector spaces are not comparable and recall degrades significantly. If the embedding model is changed, the index must be rebuilt in full.
5. Retrieval Strategy: Hybrid Recall Beats a Single Path
Pure semantic search is good at recalling content with “similar meaning,” but it is unstable for exact, low-frequency matches such as proper nouns, technique names, and place names. Pure keyword search is the opposite. Hybrid recall is therefore recommended: take the top few results from each path, merge and deduplicate them, then use a reranking model to score relevance to the question, and finally feed only the highest-scoring fragments into the context.
Context assembly should follow a “budget first” principle: fill fragments from the highest reranking score downward until approaching the upper limit of the context budget, and clearly label fragment numbers in the prompt so the model can cite them and humans can verify them.
6. Stability and Cost Control
Cloud calls may slow down during peak hours. This is a queuing phenomenon rather than a call failure, and the engineering response is as follows:
- Set a more generous client timeout, paired with backoff retries, to avoid “failing fast but never getting a result.”
- Build a local cache for high-frequency repeated questions, returning immediately on a hit to reduce duplicate billing.
- Separate vectorization tasks during ingestion from online question answering, and run batch jobs during off-peak hours.
- If latency sensitivity is high, evaluate the provider’s high-priority or paid channel, trading a small cost for more stable response times.
- Set up a usage dashboard tracking daily call volume and failure rate; abnormal growth often means something is wrong with the splitting or prompt design.
7. Common Pitfalls
- Pitfall one: stuffing an entire book into a single request. Context has a limit no matter how long it is, and overly long context dilutes key information, so retrieval recall is a necessary intermediate layer.
- Pitfall two: pursuing full automation. The value of a knowledge base is handing the work of “finding” to the system while leaving “judgment” to the author, and conclusions still need sampled manual verification.
- Pitfall three: ignoring version management. Material keeps being added, and once splitting parameters or the embedding model change, index version records should be retained for traceability and rebuilding.
8. Summary
The correct form of a local knowledge base for web novels is a combination of local data and a retrieval pipeline plus cloud model compute. Giving up on forcing a large model to run on ordinary hardware, and instead calling cloud capabilities through standardized interfaces, makes it possible to handle long material far beyond chat window capacity while keeping costs within a predictable range. In implementation, putting effort into four things—splitting strategy, metadata design, hybrid recall, and citation constraints—will make the system far more usable than simply swapping models.
