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: a model inference layer and an application orchestration layer. It covers resource and hardware planning, upload limit configuration, deploying an open-source AI application platform with Docker, connecting local or OpenAI-compatible inference services, and the key engineering steps for document parsing, chunking, embedding, hybrid retrieval, reranking, and evaluation. It also outlines the security, access control, and operations practices needed to move from a prototype to production while keeping all data inside your own network.
1. Why a Local Knowledge Base Needs a Two-Layer Architecture: Model Plus Application Platform
Many teams get a large language model running locally, attach a few documents to a simple chat client, and declare that their knowledge base is done. This works for a quick validation, but it soon runs into three problems. First, the upload entry point enforces strict limits on file size, format, and count. Second, there is no engineering pipeline for document parsing, chunking, vectorization, or retrieval reranking, so answer quality is inconsistent. Third, without session management, citation traceability, permission isolation, and auditing, the setup cannot go into production.
A more sound approach is to split the capabilities into two layers: the model inference layer handles generation, while the application orchestration layer handles knowledge processing and retrieval augmentation. The former can be a locally deployed open-source LLM service; the latter is typically an open-source AI application development platform. When the two connect through standard interfaces, you get a closed loop entirely inside an intranet, and data never leaves your data center.
This separation delivers direct benefits:
- Environment isolation: the entire pipeline runs offline, eliminating the risk of data leakage.
- Data control: documents, vector indexes, and conversation records all stay in your own storage, meeting compliance and audit requirements.
- Comparable experience: retrieval-augmented generation brings answer quality close to commercial closed-source model solutions.
- Replaceability: the model and the platform are decoupled, so swapping the inference backend later does not require rebuilding the knowledge base.
2. Prerequisites: Getting Resource Estimation Right
Hardware and Resources
For the minimal setup where local inference and platform services run on the same machine, at least 2 CPU cores and 16 GiB or more of memory or VRAM are recommended. If VRAM is insufficient, you can fall back to CPU inference, but you should expect a higher time to first token. If you also run a vector database and document parsing tasks, reserve more than 8 GiB of memory headroom. Start with at least 100 GiB of disk for model weights, image layers, and original documents.
Software and Dependencies
The base dependencies are usually just two items: a container runtime and a container orchestration tool. The community edition image is sufficient on the platform side. Note that model weights are large and the first pull takes a long time, so plan bandwidth in advance or set up an image cache inside the intranet.
Planning Capacity and Upload Limits in Advance
Platforms generally set default thresholds for upload file size, configured separately for images, audio, video, and regular documents. These values live in the environment variable configuration file and can be adjusted before the first startup. In production, also raise the request body size limit at the reverse proxy layer; otherwise you get a split situation where the platform allows the upload but the gateway still rejects it.
3. Deploying a General Open-Source Application Platform
The typical flow is as follows (illustrative; follow the documentation for the distribution you use):
# Get the source code (or use an internal mirror address)git clone <platform-repository-address>cd <platform-directory>/docker# Generate the environment configurationcp .env.example .env# Adjust upload size thresholds as needed# UPLOAD_IMAGE_FILE_SIZE_LIMIT / UPLOAD_VIDEO_FILE_SIZE_LIMIT# UPLOAD_AUDIO_FILE_SIZE_LIMIT# Start all servicesdocker compose up -d
After startup, complete administrator initialization at http://<server-address>/install. The community edition listens on port 80 by default. If that conflicts with an existing service, change the port mapping in the orchestration file and use a reverse proxy as the single entry point.
Pay attention to three operational details. First, the platform usually consists of multiple containers (gateway, API, worker, database, vector database, cache, and so on); confirm all of them are healthy before initialization. Second, use persistent volumes for the database and vector database to avoid losing the knowledge base when containers are recreated. Third, if image pulls are slow, add a registry mirror address in the container runtime configuration.
4. Connecting a Local LLM to the Platform
There are two connection options; choose based on your situation.
Option 1: Connect an OpenAI-compatible API. If local inference deployment is not complete yet, you can first use a hosted service that is compatible with the OpenAI protocol to establish the pipeline, validate the knowledge base results, and then switch to local.
Option 2: Connect a local inference service. In the platform’s “Model Provider” section, select the local inference framework type, then enter the intranet address and port. When adding models, note the following:
- Distinguish model types between LLM (chat) and Embedding; knowledge base retrieval depends on the latter, and missing it prevents index construction.
- The context length must match the actual configuration on the inference side; too long causes truncation, too short loses recalled content.
- Use different models for question answering and vectorization. Once the embedding model changes, historical indexes must be fully rebuilt.
After configuration, the platform lists the available models, and you can select them in your application.
5. Key Engineering Steps for Building the Knowledge Base
- Document parsing: prefer a parsing method that supports tables and layout; scanned files must go through OCR first, otherwise the text layer is empty.
- Chunking strategy: 300 to 800 characters is a common range, with 10% to 20% overlap; heading levels can serve as chunk boundaries so a complete clause is not cut apart.
- Vectorization and indexing: use the same embedding model throughout; for document updates, delete old chunks before writing new ones to prevent duplicate retrieval.
- Retrieval and reranking: hybrid retrieval (keyword plus vector) usually outperforms vector-only recall; enabling reranking significantly reduces irrelevant fragments entering the context.
- Prompts and citations: require the model to answer only from recalled content and provide sources, and to explicitly say “no supporting evidence was retrieved” when it cannot answer, which greatly reduces hallucinations.
- Evaluation loop: prepare 30 to 50 real questions as a regression set, rerun it after every change to chunking or model parameters, and measure with both hit rate and human ratings.
6. Security, Permissions, and Operations
Production deployment also requires tenant isolation by department for each knowledge base, unified identity authentication at the interface layer, full operation auditing and conversation retention, file type and virus checks on uploads, logging and monitoring alerts that track inference latency, VRAM usage, and index build queue backlog, plus regular backups of the database and vector data with one full recovery drill.
7. Summary
The core of a local knowledge base is not “getting the model running” but engineering document processing, retrieval augmentation, permission auditing, and the evaluation system together. Build with a decoupled “platform layer plus inference layer,” validate retrieval quality on a small sample first, then gradually scale up the corpus and concurrency. Only this way can you reliably achieve a question-answering experience close to commercial solutions while keeping data inside the intranet.
