How to Build a Knowledge Base After Deploying a Local LLM
This guide explains why a locally deployed LLM still needs a separate knowledge base, and walks through building a private Retrieval-Augmented Generation (RAG) system: the five-layer architecture, environment setup with a containerized orchestration platform, connecting online or local models, chunking and indexing strategies, prompt constraints, evaluation, and operations. It also covers upload size limits, reranking trade-offs, incremental updates, data governance, and common troubleshooting pitfalls.
1. Why a Local LLM Still Needs a Separate Knowledge Base
Deploying an LLM locally solves three baseline problems: data stays inside your network, inference cost is predictable, and response latency is under control. What it does not solve is making the model “know your business.” Once training finishes, the model’s parameters are fixed. It knows nothing about internal documents, product manuals, support tickets, or coding standards — the private information that changes frequently. Ask it a direct question and you often get an answer that sounds plausible but cannot be traced to any source. This is the hallucination problem.
A knowledge base injects external information dynamically at inference time, turning “answering from memory” into “answering from retrieved evidence.” The standard technical approach is Retrieval-Augmented Generation (RAG): a retriever first finds the passages most relevant to the question from your own corpus, then the model generates a final answer using those passages together with the original question. The value is threefold:
- Updating knowledge only requires rebuilding the index, not retraining the model.
- Answers can include citations, making manual verification easy.
- Corpus access can be controlled at document granularity, reducing the risk of unauthorized access.
One point deserves emphasis: the quality ceiling of RAG is determined by retrieval quality, not model size. In practice, most disappointing results trace back to document parsing, chunking, and recall — not to generation.
2. Overall Architecture and Component Responsibilities
A usable private knowledge base typically has five layers:
- Ingestion layer: handles file upload, format parsing, and incremental sync across plain text, office documents, PDFs, web pages, and code repositories.
- Preprocessing layer: removes noise, strips headers and footers, restores heading hierarchy, splits on semantic boundaries, and attaches metadata to each chunk.
- Indexing layer: converts chunks into vectors and writes them to a vector database; optionally builds a keyword inverted index to support hybrid retrieval.
- Retrieval layer: runs similarity recall, keyword recall, result fusion, and reranking, controlling how many chunks enter the context and in what order.
- Generation layer: assembles the prompt template, constrains the model to answer only from the provided material, and outputs citations and confidence hints.
Decoupling these five layers means any layer with a quality problem can be diagnosed and replaced independently, without rebuilding the whole system.
3. Environment Setup and Platform-Based Deployment
If you would rather not implement all five layers from scratch, an open-source LLM application orchestration platform can handle workflow orchestration, document management, and prompt debugging. Using a containerized deployment as an example, the typical steps are (commands are generic illustrations):
# Get the source codegit clone <platform-repo-url>cd <platform-directory>/docker# Prepare the environment variable configurationcp .env.example .env
The configuration file contains several upload size limits, for images, audio, video, and general documents respectively. Defaults usually range from ten to a hundred megabytes. If you need to upload large scanned files or long meeting recordings, raise the relevant thresholds in advance and adjust the request body limits on your reverse proxy and gateway accordingly. Otherwise requests get truncated at the gateway: the upload fails but nothing appears in the application logs.
# Upload size limits (example, in MB)UPLOAD_IMAGE_FILE_SIZE_LIMIT=10UPLOAD_AUDIO_FILE_SIZE_LIMIT=50UPLOAD_VIDEO_FILE_SIZE_LIMIT=100UPLOAD_FILE_SIZE_LIMIT=50
Then start the services:
docker compose up -d # newer orchestration command# docker-compose up -d # older orchestration command
The first startup pulls several base images; if network access is restricted, configure a mirror registry and retry. The service exposes port 80 by default, so open http://localhost/install in a browser to complete administrator initialization. In production, put the entry point behind an internal load balancer, enable unified identity authentication, and clearly separate the administrator, editor, and regular end-user roles for the knowledge base.
4. Model Integration: Online API vs. Local Inference
Once the platform is ready, connect a model provider. There are usually two options.
The first is calling an online API. Fill in the service endpoint, key, and model identifier on the platform’s model configuration page. The advantage is no GPU resources required and fast time to launch; the drawback is that data must leave your network, and you are subject to call quotas and network stability.
The second is connecting a local inference service. First load the local weights with an inference framework that exposes an OpenAI-compatible API, publishing a standard chat completions endpoint:
python -m vllm.entrypoints.openai.api_server \--model /models/your-local-model \--served-model-name local-llm \--host 0.0.0.0 --port 8000
Then in the platform, select chat model as the model type, set the endpoint to http://<inference-host>:8000/v1, and keep the model name identical to --served-model-name. Besides the chat model, you need to configure an embedding model separately for text embedding. If you do not deploy an embedding model locally, you can fall back to the platform’s built-in lightweight embedding option, but Chinese semantic retrieval quality typically degrades.
An often-overlooked companion component is the reranking model. It reorders candidate chunks after recall and noticeably improves first-hit accuracy, at the cost of one extra inference pass per question — a trade-off to weigh against your latency budget.
5. Key Parameters and Strategies for Building the Knowledge Base
Once documents are in the knowledge base, the chunking strategy has the largest impact on final quality. General recommendations:
- Chunk size: keep each chunk between 300 and 800 Chinese characters, with 10% to 20% overlap, so answers are not cut off at boundaries.
- Split on structure: prefer natural boundaries such as heading levels, clause numbers, and table rows over mechanical fixed-length splitting.
- Metadata design: write fields such as source file, section path, effective date, classification level, and department into each chunk; use them as filters at retrieval time to enforce per-user isolation.
- Indexing: vector retrieval handles semantically similar but differently worded content; keyword retrieval handles exact matches on proper nouns, IDs, and model numbers. Hybrid recall plus fused ranking gives the most stable results.
- Incremental updates: use document fingerprints to detect changes and rebuild only affected chunks, avoiding the compute waste and service disruption of full rebuilds.
For tables and scanned content, do structured extraction before ingestion; otherwise lost layout information seriously distorts retrieval results.
6. Prompt Constraints and Quality Evaluation
At generation time, use the prompt to make the boundaries explicit: answer only from the retrieved material; state clearly when the material is insufficient; tag every conclusion with the source chunk ID; do not invent numbers or dates absent from the material. Example template:
You are an enterprise knowledge assistant. Answer questions using only the [Material] below.If the material is insufficient to support a conclusion, state "insufficient material" directly. Do not fabricate.At the end of your answer, list the cited sources as [chunk ID].[Material]{retrieved_chunks}[Question]{question}
Evaluation should form a closed loop: prepare 50 to 200 real business Q&A pairs as a regression set, and measure recall hit rate, answer accuracy, and correct-refusal rate separately. After launch, collect unanswered and low-rated sessions, trace whether the cause is a parsing error, poor chunking, or insufficient recall, and adjust accordingly. Tuning without a regression set is essentially guesswork.
7. Operations, Security, and Common Pitfalls
- Resource planning: embedding and reranking continuously consume GPU memory or RAM, so isolate them from online inference resources to keep batch jobs from crowding out peak question traffic.
- Data governance: define corpus classification levels and retention periods, and delete the index entries when documents are deleted, so that “deleted files can still be retrieved” never happens.
- Observability: monitor and alert on retrieval latency, context length, timeout rate, and failed retries; avoid logging full sensitive document content.
- Common failures: for upload failures, check the size-limit chain first; for irrelevant retrieval results, check whether the embedding model matches the corpus language; for verbose answers, the context usually has too many chunks with no deduplication; for startup failures, look at port conflicts or configuration file syntax errors.
8. Conclusion
A local model plus a knowledge base is fundamentally about connecting general reasoning capability to a private source of facts. The engineering effort lies not in model selection but in the seemingly mundane steps: document parsing, chunking, hybrid retrieval, and the evaluation loop. Make that chain solid and the Q&A system will reliably produce traceable, maintainable answers. If you want to reduce the burden of self-managed operations, you can also evaluate general-purpose container platforms, object storage, and log monitoring products from cloud vendors such as Baidu AI Cloud to carry the deployment and governance layers.
