How to Build a Private Knowledge Base with a Local LLM: A Two-Layer Architecture Guide
This article explains how to build a private knowledge base on top of a locally deployed large language model using a two-layer architecture that separates local inference from an application orchestration platform. It covers capacity, storage, and network planning; container-based platform deployment; connecting an OpenAI-compatible local inference service; and the key engineering details of document parsing, chunking, hybrid retrieval, and grounded generation. It also outlines security, evaluation, and operations practices for running a compliant, continuously improvable enterprise knowledge assistant.
1. Why a Local Knowledge Base Needs a Two-Layer Architecture: Model Plus Platform
Deploying a large language model locally only solves one problem: keeping inference compute under your own control. Making the model answer real enterprise questions requires a full set of data engineering capabilities: document ingestion, format parsing, chunking strategy, vectorization, retrieval, reranking, prompt assembly, citation tracing, evaluation, and canary rollout. Stacking all of these inside a single inference process leads to tight coupling, poor reuse, and limited observability.
The common approach is a two-layer architecture. The bottom layer is a local inference service responsible for model loading and generation. The top layer is an application orchestration platform responsible for the knowledge base lifecycle and the conversation flow. The two layers are decoupled through a standard protocol, so the model can be swapped without binding the knowledge base assets to it. Note that this orchestration layer can be built on open-source community projects, or on general-purpose cloud capabilities such as container platforms, object storage, logging services, and monitoring and alerting. When choosing, focus on whether the data boundary is clear and whether fully offline operation is supported.
2. Upfront Planning: Compute, Storage, and Network Boundaries
On the hardware side, distinguish two types of workload. Inference is constrained by GPU memory capacity and bandwidth: quantized model weights, the KV cache, and concurrent batching all consume GPU memory. When memory is insufficient, inference falls back to system RAM and CPU, and time to first token rises sharply. The platform is a conventional web workload; databases, vector stores, and task queues are more sensitive to CPU and disk I/O. In practice, deploy inference and the platform on separate machines so they do not compete for resources.
On the storage side, plan for three categories of data: raw documents, intermediate parsing artifacts, and vector indexes with metadata. Raw and intermediate data fit object storage or a shared file volume; vectors and metadata belong on a database volume with persistence support. Decouple data volumes from the container lifecycle, otherwise a single image update can wipe out all knowledge assets.
On the network side, define what “offline” really means: model weights, images, and dependency packages must be staged in advance in an internal mirror registry and artifact repository. The platform’s default ports should sit behind a reverse proxy, open only to the internal network, with transport encryption enabled.
3. Deploying the Orchestration Platform
Container-based deployment is the most common choice, and the core steps reduce to four:
# 1. Get the orchestration files and config templategit clone <internal mirror registry>/ai-platform.gitcd ai-platform/docker# 2. Generate local configcp .env.example .env# 3. Adjust upload size, timeout, concurrency as needed# Documents: 50; images: 10; audio/video: 100 (MB)# 4. Start and check container statusdocker compose up -ddocker compose ps
The most overlooked settings during configuration are upload size and timeout. Defaults usually target demo scenarios, and enterprise contracts, scanned PDFs, and meeting recordings often exceed them. When adjusting, also check the reverse proxy’s request body limit and the gateway timeout; otherwise you get a split where the platform allows the upload but the gateway still blocks it.
If the internal network cannot reach external image sources directly, sync images into the internal registry and pin versions, avoiding floating tags that cause environment drift. After initialization, create an account through the admin first-install page, then immediately disable anonymous registration, enforce a strong password policy, and enable login failure lockout.
4. Connecting the Local Model Service
There are two paths to connect a model. One is a compatible hosted inference API, suitable for quick validation. The other is a local inference service, suitable for scenarios with strict data boundary requirements. The common local approach: start the inference service and expose an OpenAI-style compatible API, then add a model provider in the platform with the internal address, model name, context length, and maximum output length.
Example configuration:
{"provider": "local-inference","base_url": "http://10.0.0.12:11434/v1","model": "local-chat-32b","context_window": 32768,"max_tokens": 2048,"temperature": 0.3}
A few tuning rules of thumb: lower the temperature for knowledge Q&A to reduce fabrication; a larger context window is not always better, since excessive length dilutes useful information and raises GPU memory usage; when you need stable structured output, prefer a service form that supports constrained decoding. After connecting, verify connectivity and streaming output, and confirm that time to first token and concurrency meet business expectations.
5. Key Engineering Details of Knowledge Base Construction
Document parsing sets the ceiling. For PDFs, separate the text layer from the scanned layer, the latter relying on OCR; tables, headers, and footers are common noise sources; code and contract clauses are sensitive to chunk boundaries. Build a parsing quality sampling process and feed failed samples back for correction.
Chunking strategy must match the Q&A granularity. Fixed-length chunking is simple but tends to cut across semantics; chunking by heading hierarchy and paragraph structure is better for citation tracing; for Q&A corpora, store question-answer pairs. A common setup is a chunk size of 300 to 800 characters with 10% to 20% overlap, keeping source file, section path, page number, and last update time in the metadata.
For retrieval, use a hybrid strategy: vector retrieval handles semantic similarity, keyword retrieval handles exact matching of proper nouns and identifiers, and the fused results are then reranked by a reranking model. Metadata filters (department, classification level, time range) should take effect at the retrieval stage rather than trimming after generation, which wastes compute and risks leakage.
At generation time, require the model to cite before answering, and force a refusal when evidence is insufficient. Specifying the output format, citation numbering rules, and uncertainty phrasing in the prompt significantly reduces hallucination.
6. Security, Evaluation, and Operations
For security, enforce least privilege: isolate knowledge bases by department, authenticate APIs at the user level, mask sensitive fields before ingestion, and log operations across the entire chain. For evaluation, maintain a fixed question set and track retrieval hit rate, citation accuracy, refusal accuracy, and response latency, running a regression after every change to chunking or prompts. For operations, collect logs centrally through a logging service, cover GPU memory usage, queue backlog, and error rate with monitoring and alerting, and back up data volumes and indexes regularly while verifying recoverability.
7. Conclusion
The value of a local knowledge base lies not in how large the model is, but in whether the data loop is complete. Decoupling inference from orchestration, making parsing and chunking solid, and moving permissions and evaluation upfront is what lets you keep iterating a genuinely useful enterprise knowledge assistant under compliance constraints.
