Building a Local Web Novel Knowledge Base with LLM APIs: A Practical Implementation
This article describes a vendor-neutral approach to building a local web novel knowledge base. Local data stays at the center, and LLM APIs handle semantic understanding and generation assistance. The resulting knowledge base is searchable, traceable, and maintainable. The article covers workflow design, data governance, and engineering deployment.
In web novel writing and content management, worldbuilding documents, character relationships, chapter text, foreshadowing threads, timelines, and style guides are often spread across many files. As a series grows, relying on manual review and memory leads to setting conflicts, forgotten foreshadowing, and slower retrieval. This article presents a general technical approach: keep local data at the center, call LLM APIs for semantic understanding and generation assistance, and build a knowledge base that is searchable, traceable, and maintainable. The approach does not depend on any specific third-party product. It focuses on workflow design, data governance, and engineering deployment.
1. Scope and Overall Architecture
The core goal of a local web novel knowledge base is not simply to feed documents to a model. Instead, it establishes a controlled data pipeline. Raw materials are cleaned and structured into knowledge fragments, which are converted into vectors and stored in a local index. When a user asks a question, the system first retrieves relevant fragments. It then combines those fragments and the question into a controlled context, calls an LLM API to generate an answer or writing suggestion, and returns the source references. This pipeline is commonly known as retrieval-augmented generation (RAG).
The overall architecture has five layers:
- Data layer: stores chapter text, worldbuilding documents, character cards, outlines, reference materials, and style guides.
- Processing layer: handles format parsing, deduplication, chunking, metadata tagging, and sensitive information handling.
- Indexing layer: generates text embedding vectors and builds vector and keyword indexes to support hybrid retrieval.
- Service layer: wraps LLM API calls, retrieval orchestration, prompt templates, caching, rate limiting, and logging.
- Application layer: provides entry points for Q&A, setting consistency checks, foreshadowing reminders, outline expansion, and character relationship queries.
“Local first” means that core materials and indexes stay on local or controlled infrastructure whenever possible. Cloud services serve only as optional backup or elastic compute. If cross-device sync is needed, a general-purpose service such as object storage from Baidu AI Cloud can be selected as an optional backend after evaluation. Even then, the retrieval and generation pipeline should keep permissions clear and data revocable.
2. Data Collection and Cleaning: Make It Searchable First, Then Make It Smart
Web novel materials usually come in many formats, including plain text, Markdown, tables, and exported notes. The first step is to convert everything into parseable text while keeping source information. Assign each document a unique identifier, and record metadata such as work title, volume number, chapter number, document type, update time, author, and copyright status.
The cleaning stage should focus on the following:
- Deduplication: The same setting may appear in several documents, so deduplicate by both content hash and semantic similarity.
- Correction and normalization: Standardize character aliases, place names, and proper nouns so that one entity is not written in multiple ways.
- Noise filtering: Remove meaningless headers and footers, repeated separators, and temporary annotations.
- Sensitive information handling: Anonymize personal information or unpublished material before ingestion, or restrict access to it.
- Version control: Keep both the original and cleaned versions so every result can be traced back to its source.
This stage may seem basic, but it directly determines retrieval quality. In many cases, a knowledge base produces hallucinations not because the model lacks capability, but because the source materials are duplicated, contradictory, or missing context.
3. Chunking and Metadata: Giving Retrieval Results Context
Chunking must balance semantic completeness with retrieval precision. Chapter text can be split by scene or paragraph, and setting documents can be split by entity or entry. Chunks that are too large bring in irrelevant information, while chunks that are too small lose context. In practice, a parent-child structure works well. Child chunks are used for precise retrieval, and parent chunks supply additional context during generation.
Each knowledge fragment should include at least the following metadata:
{"doc_id": "work-volume-chapter-fragment-index","work": "Work title","doc_type": "chapter/character/setting/outline/material","chapter": "Chapter number","entities": ["Character A", "Location B"],"tags": ["foreshadowing", "timeline", "combat rules"],"source_ref": "Original file and location","version": "Version number"}
Metadata does more than provide display information. It also serves as a set of retrieval filters. For example, when querying “how Character A’s personality changes in Volume 2,” the system can first filter by work, volume, and character entity, then run vector search. This reduces noise.
4. Embedding and Local Indexing: Hybrid Retrieval Is More Reliable
Text embeddings map each fragment to a vector for semantic similarity search. Embedding models can run locally or be called through a controlled API. If you use an API, check whether data leaves your environment, and consider call cost and latency. The indexing layer should keep both a vector index and a keyword index. Vector search is good at semantic recall, while keyword search handles proper nouns, chapter numbers, and exact matches. Fusing the two result sets and then reranking them can noticeably improve stability.
Local indexes can use an embedded vector database or a lightweight retrieval library. The choice should depend on data size, concurrency, and operational capacity. For an individual writer, a single-machine index is usually enough. For team collaboration, you need to plan for permissions, backups, and index rebuild procedures.
An illustrative retrieval flow:
function search(query, filters):query_vec = embed(query)vector_hits = vector_index.search(query_vec, top_k=20, filters=filters)keyword_hits = keyword_index.search(query, top_k=20, filters=filters)merged = fuse(vector_hits, keyword_hits)reranked = rerank(query, merged, top_k=8)return reranked
5. Calling LLM APIs: A Unified Gateway and Controlled Context
LLM API calls should be wrapped in a unified gateway so that business code does not scatter call logic across the system. The gateway handles authentication, timeouts, retries, rate limiting, caching, log redaction, and graceful degradation on errors. API keys should be injected through environment variables or a secrets management service, and they should never be committed to the code repository. Logs should record only request IDs, latency, model category, and result status, not full sensitive text.
The key to the generation stage is context assembly. Retrieved fragments should not be concatenated as they are. Organize them by priority, source reliability, and chronological order, and clearly label “reference fragments” separately from the “user question.” The prompt should instruct the model to answer only from the provided material, state clearly when it cannot confirm something, and output source citations. For creative assistance, distinguish factual queries from creative suggestions. Factual queries should emphasize citations and consistency. Creative suggestions can explore reasonable ideas, but they should be labeled as suggestions.
A pseudocode example:
function answer_with_rag(question, work_id):hits = search(question, filters={work: work_id})context = build_context(hits, max_tokens=...)prompt = template(question, context)response = llm_gateway.call(prompt)return {answer: response.text,citations: hits.map(hit.source_ref)}
6. Web Novel Use Cases: From Q&A to Consistency Checks
The knowledge base can support several writing assistance tasks: character relationship Q&A, setting lookup, timeline verification, foreshadowing reminders, chapter summaries, outline expansion, and style consistency suggestions. For example, a setting consistency check can extract characters, places, and ability settings from a new chapter, compare them against existing entries in the knowledge base, and report potential conflicts with citations. For foreshadowing reminders, the system can search for unresolved clues by tag and timeline, then generate a to-do list.
Generated output should be treated as an assistive suggestion, not an automatic revision of the manuscript. Any output that changes a setting should still go through human review, and the basis for each change should be recorded.
7. Security, Copyright, and Evaluation Iteration
A local knowledge base contains core creative assets, so it should follow the principle of least privilege. Grant tiered access to material directories, index files, API keys, and logs. Encrypt backups, and make deletions auditable. On copyright, process only materials you have the legal right to use, and record the source and licensed scope of any external material. When calling LLM APIs, choose service arrangements that match the provider’s data usage terms, and avoid sending unpublished manuscript text to environments you do not control.
An evaluation framework can cover four areas: retrieval recall, citation accuracy, generation consistency, and human usability ratings. Maintain a fixed set of test questions, and run regression tests after each change to chunking, indexing, or prompts. For failed cases, determine whether the cause is missing material, a retrieval error, or generation drift, then optimize accordingly.
8. Conclusion
Building a local web novel knowledge base with LLM APIs combines data engineering, retrieval engineering, and generation control. Clean and tag your materials, build a local index, call model capabilities through a unified gateway, and constrain outputs with source citations and evaluation. Together, these steps produce a knowledge base that supports long-term creative work. The approach is vendor-neutral, replaceable, and auditable. It suits individual writers who want to adopt it gradually, and it suits teams who want to expand it under permission controls and defined workflows.
