How to Build a Self-Hosted Document AI Engine for Your B2B Service Team
Your team sends thousands of AI queries per week through hosted APIs. Each one is billed per token. This blueprint shows you how to run document analysis, drafting, and research on your own hardware for the price of electricity. Full build steps on the blog.

Your team drafts proposals, summarizes contracts, and researches client industries every week. Each of those tasks currently routes through a hosted AI API that bills per token. This blueprint shows you how to run those same workflows on your own hardware for the price of electricity. No per-query charges. No vendor lock-in. Full data privacy.
The problem
Hosted AI APIs solved the initial adoption barrier for B2B service teams. They removed the need to manage GPU hardware and made it trivial to start using AI for drafting, summarization, and client research. The trade-off was always the billing model, and that trade-off now limits teams that have moved past the experimentation phase.
Per-token pricing creates two compounding failures in a growing service business. First, it makes AI costs unpredictable and opaque. Your team sends thousands of queries per week. A short drafting prompt costs a fraction of a cent. Summarizing a 40-page contract costs significantly more. Running a multi-step research workflow across five documents costs even more. The individual calls feel cheap in isolation, but they aggregate into a monthly invoice that grows with headcount and with workflow adoption, not with business outcomes. You cannot predict the bill from the pipeline.
Second, per-token pricing distorts team behavior. When people know each query carries a cost, they start rationing usage. The first thing they cut is the low-value, repetitive work where AI saves the most hours. A team member who would normally ask the model to summarize five vendor proposals stops at two because of cost awareness. Someone who runs an automated contract review on every new client agreement starts reviewing only the large ones. The AI investment becomes a cost center instead of a margin expander. You pay the API bill and you also pay the hidden cost of manual hours your team spends working around the meter.
The structural fix is to own the model. Run inference on hardware you purchased once. Eliminate the per-query cost and give your team unrestricted access to AI for every document workflow without the behavioral distortion of a running meter.
Who this is for
This blueprint is for B2B service business founders in Southeast Asia doing $500k to $5M in annual revenue, with operational teams of five to twenty people. You already use hosted AI APIs for document drafting, contract review, proposal generation, or client research. Your monthly API bill is growing, your team is rationing queries, and you want to flatten the cost curve without cutting capability.
This is not for teams building AI-powered products for external users, or for use cases that require real-time inference at massive scale. Those workloads still benefit from the auto-scaling infrastructure of hosted providers. This blueprint targets internal operational workflows: processing your own documents, answering your own team's questions, and automating your own drafting tasks.
System architecture
The Local Document AI Engine has five components connected in a linear pipeline.
Document intake. The entry point. Team members upload files through a web interface or drop them into a watched folder. Supported formats include PDF, DOCX, TXT, and email exports. The intake layer validates the file, extracts text, and passes it to the orchestrator for processing.
Vector store. A local embedding database (ChromaDB) stores chunked representations of every uploaded document. When a team member asks a question, the system retrieves the most relevant document chunks by semantic similarity rather than keyword matching. This enables the engine to answer questions across your entire document corpus, not just the file currently open on screen.
Local inference model. A quantized large language model runs on the workstation GPU. The model processes retrieved chunks and generates answers, summaries, or drafted content. Two models cover the full range of tasks. A 9B-parameter generalist model handles fast drafting, summarization, and simple Q&A. A 23B-parameter agent model handles complex research tasks that require reasoning across multiple documents or tool use. Both run in 4-bit quantized form, reducing VRAM requirements to fit within a single consumer GPU.
Team interface. A web-based chat interface gives team members access to the local models through a familiar conversation UI. The interface supports document upload, conversation history, and model selection. Open WebUI connects natively to Ollama and requires minimal configuration.
Orchestrator. An n8n workflow connects the components. When a document arrives, the orchestrator chunks it, generates embeddings, and stores them in ChromaDB. When a query arrives, the orchestrator retrieves relevant chunks, routes the query to the appropriate model, and returns the answer. The orchestrator also handles logging, error handling, and optional notifications.
The complete data flow: a team member uploads a vendor contract. The orchestrator chunks the document into 500-token segments, embeds each segment, and stores the vectors in ChromaDB. Later, a team member asks a question about that contract. The orchestrator retrieves the most relevant chunks, passes them to the 9B model with the query, and returns the answer. The entire cycle runs locally. Zero API calls. Zero per-token charges.
Build steps
-
Provision the GPU workstation. Acquire a desktop workstation with an NVIDIA GPU carrying at least 24 GB of VRAM. An RTX 4090 (24 GB), an RTX A5000 (24 GB), or an RTX 6000 Ada (48 GB) are the standard options. The system needs 32 GB of RAM, a modern multi-core CPU, and a 1 TB NVMe SSD for model storage and vector data. Install Ubuntu Server 22.04 LTS. Hardware cost ranges from $2,000 to $4,000 depending on GPU selection. This is a one-time capital expense.
-
Install the model runner. Install Ollama on the workstation. Ollama manages model downloads, quantization, and inference through a local API server. Install via the official script. Verify the installation with
ollama list. Ollama exposes an OpenAI-compatible API atlocalhost:11434, so any tool that already works with OpenAI can be pointed at your local instance with a base URL change. -
Download and validate the models. Pull two models through Ollama. For fast drafting and summarization, use a quantized 9B generalist such as Qwen2.5-7B in 4-bit (Q4_K_M) or Qwythos-9B-v2. For complex research and multi-step tool use, use a 23B agent model such as Agents-A1 in 4-bit quantization, which runs in 23 GB of VRAM and handles research workflows with tool calling. Validate each model by running a test prompt and checking output latency and quality. Target: under 30 seconds for a standard summarization query on the 9B model, under 90 seconds for a research query on the 23B model.
-
Set up the vector database. Install ChromaDB on the same workstation. Run it as a persistent server with data stored on the NVMe SSD. Install a sentence-transformers embedding model for chunk encoding. The all-MiniLM-L6-v2 model (384 dimensions) works for most business document types. If your documents are primarily in Vietnamese or another non-English language, switch to paraphrase-multilingual-MiniLM-L12-v2. Test the pipeline: upload a sample PDF, chunk it, embed it, and run a test query that returns the correct passage.
-
Deploy the team interface. Install Open WebUI on the workstation using Docker. Configure it to connect to the local Ollama instance at
localhost:11434. Create user accounts for each team member. Configure model access so team members can select between the 9B generalist and the 23B agent model. Set up document upload handling so files dropped into the chat are processed through the orchestrator. Test the full loop: upload a contract, ask a question, verify the answer references the contract content. -
Build the ingestion workflow. In n8n (self-hosted on the same workstation or your existing VPS), create a workflow with four nodes. First, a webhook trigger that receives document uploads from the team interface. Second, a text extraction node that reads PDF, DOCX, and TXT files and outputs plain text. Third, a chunking node that splits the text into 500-token segments with 50-token overlap. Fourth, a ChromaDB node that embeds each chunk and stores it with metadata (filename, upload date, document type). Activate the workflow and test with three sample documents.
-
Build the query workflow. Create a second n8n workflow for query handling. The webhook trigger receives a question and optional document filter from the team interface. A ChromaDB retrieval node fetches the top 10 relevant chunks. A model router node sends the query plus retrieved chunks to the 9B model for standard questions or the 23B model for complex research tasks. The model response returns to the team interface. Activate and test with five questions across your sample documents.
-
Migrate workflows from the hosted API. Review your API usage logs from the past 30 days. Identify the highest-volume workflows. Start with the single workflow that consumes the most tokens. Route it to the local engine. Run it in parallel with the hosted API for one week. Compare output quality manually on a sample of 20 queries. If the local model quality is acceptable, cut over the workflow to local-only. Repeat for each remaining workflow. Within four to six weeks, your hosted API bill should drop to near zero, covering only edge cases that require a larger hosted model.
Tools and costs
| Component | Tool | Purpose | Cost |
|---|---|---|---|
| Model runner | Ollama | Downloads, quantizes, and serves local models | Free, open source |
| Generalist model | Qwythos-9B-v2 or Qwen2.5-7B (Q4_K_M) | Drafting, summarization, Q&A | Free, open source |
| Agent model | Agents-A1 (Q4_K_M quantized) | Research, multi-step tool use | Free, open source |
| Vector database | ChromaDB | Embedding storage and semantic search | Free, open source |
| Embedding model | all-MiniLM-L6-v2 | Chunk encoding for vector store | Free, open source |
| Team interface | Open WebUI | Chat UI for document queries | Free, open source |
| Orchestrator | n8n (self-hosted) | Workflow routing and automation | Free on existing VPS |
| GPU workstation | Desktop with 24 GB VRAM GPU | Local inference hardware | $2,000 to $4,000 one-time |
Total ongoing cost: electricity for one workstation running 24/7. Approximately $15 to $30 per month depending on local rates. No per-token charges. No per-seat subscriptions. The entire software stack is open source. The hardware is a one-time purchase that depreciates over three to five years.
Failure modes
Model hallucinates contract terms. The local model invents clause details or misreads legal language. This is the most dangerous failure mode for document analysis because incorrect legal interpretation carries real risk. Fix: implement a citation requirement in the model prompt. Force the model to quote the specific passage it references. Add a verification step in the orchestrator that checks the model output against the source chunk. If the output does not match the source, flag it for human review. For high-stakes documents, maintain a human review step until you have confidence in model accuracy on your specific document types.
Long documents exceed context window. A 60-page contract or a detailed proposal exceeds the model context window, so it cannot process the full document in one pass. Fix: rely on the vector store retrieval pattern. Chunk the document into overlapping segments, embed all segments, and retrieve only the relevant ones at query time. This works for targeted questions. For full-document summarization, use a map-reduce pattern: summarize each chunk individually, then summarize the chunk summaries into a final output. The orchestrator handles this pattern automatically.
Team members bypass the local engine. Some users continue pasting queries into the hosted API out of habit, keeping the bill alive. Fix: remove API credentials from team member accounts after migration. Revoke individual API keys and route all tooling through the local interface. Make the local engine the only available option. The behavioral change takes one to two weeks.
Concurrent queries crash the model. Three team members send queries simultaneously and VRAM fills, causing slow responses or crashes. Fix: configure Ollama to process requests sequentially with a queue. Set concurrency to one. Responses queue behind each other but complete reliably. If your team needs true concurrent access, install a second GPU or add a CPU fallback path for low-priority drafting tasks using GGUF models.
Document ingestion fails silently. A corrupted PDF or a password-protected file hits the intake and the orchestrator skips it without notification. The document never enters the vector store, so queries about it return nothing. Fix: add input validation in the n8n ingestion workflow. Check file type, file size (reject files over 50 MB), and text extractability before embedding. Log all failures to a shared spreadsheet or channel. Send an alert to the team member who uploaded the file.
What good looks like
The engine is operational when these measurable properties hold:
- Standard document queries return answers in under 60 seconds, including vector retrieval, model inference, and response formatting.
- Complex research queries across multiple documents return answers in under 120 seconds.
- The hosted API bill drops to under $50 per month, covering only edge cases the local models cannot handle.
- Team members use the local interface for all drafting, summarization, and document Q&A without hesitation or behavioral rationing.
- The workstation runs continuously without manual intervention. Ollama and ChromaDB start on boot. The n8n workflows are always active.
- New documents are indexed and searchable within five minutes of upload.
- Zero documents are lost to silent ingestion failures. Every upload succeeds or triggers an alert.
Total cost of ownership: a one-time hardware purchase and a monthly electricity bill. No per-seat fees. No per-token billing. No vendor lock-in. Your team runs AI workflows on hardware you own, with models you control, at a marginal cost that approaches zero with each additional query.
