Local LLM Deployment: A Practical Path from Setup to Production

    This article walks through the practical work that follows a local large language model deployment: what changes once inference runs on your own hardware, a three-layer architecture that keeps the inference, orchestration, and application layers decoupled, a VBA example for calling a local endpoint from spreadsheet software, streaming and long-text handling, retrieval-augmented knowledge base integration, security and audit practices, and a four-week rollout plan with acceptance metrics.

    1. What Actually Changes After Local Deployment

    Downloading model weights to a workstation or an internal server and running them as a persistent service is essentially a shift in capability boundaries: inference compute, context data, and call logs all stay within a controlled perimeter. The resulting changes fall into three groups.

    The first is data sovereignty. Contract text, financial statements, and customer tickets become expensive to assess for compliance the moment they are uploaded to an external service; local inference makes “data never leaves the network” the default state. The second is cost structure. Token-based cloud billing is a variable cost, and the bill becomes unpredictable as usage grows; local deployment moves spending forward into a one-time hardware investment plus operations effort, which is easier to control under sustained high-frequency calls. The third is customizability. Model size, quantization precision, system prompts, and decoding parameters are all decided by the operator, which makes continuous tuning against vertical-domain corpora straightforward.

    Local deployment is not free of cost: hardware requirements, inference latency, context length limits, and concurrency are all constrained by the machine. So the first step is not writing code, but choosing a model size and quantization variant that fit the available VRAM and system memory, then running a load test with real business samples and recording time to first token and output tokens per second as a baseline for capacity planning.

    2. Overall Architecture: Three Decoupled Layers

    A maintainable design usually splits into three layers that communicate over standard protocols, so replacing any one layer leaves the others untouched.

    • Inference layer: loads the model, manages VRAM, and exposes compatible HTTP endpoints, typically a chat endpoint such as /api/chat and an embedding endpoint such as /api/embeddings.
    • Orchestration layer: handles knowledge base chunking, vector retrieval, prompt assembly, session memory, and permission checks; it exposes a unified interface and returns the citation sources for each answer.
    • Application layer: the concrete entry points such as office spreadsheets, internal web pages, and ticketing systems. These only care about “ask a question, get an answer” and remain unaware of model details.

    The value of this split is that spreadsheet-side code depends only on the orchestration layer’s interface contract. Swapping models or changing the retrieval strategy later requires no changes in the application layer.

    3. Wiring Model Capabilities into Spreadsheet Software

    Spreadsheets remain the working entry point for many business users. The built-in script editor (opened with Alt + F11) lets you add a module and issue a local HTTP request. Key points follow.

    1. Sub AskLocalModel()
    2. Dim q As String, body As String, resp As String
    3. Dim http As Object
    4. q = ThisWorkbook.Sheets(1).Range("A2").Value
    5. If Len(Trim(q)) = 0 Then Exit Sub
    6. Set http = CreateObject("MSXML2.XMLHTTP")
    7. http.Open "POST", "http://127.0.0.1:8080/v1/chat", False
    8. http.setRequestHeader "Content-Type", "application/json"
    9. http.setRequestHeader "Authorization", "Bearer " & ApiKey()
    10. body = "{""model"":""local-model"",""stream"":false,""messages"":" & _
    11. "[{""role"":""user"",""content"":""" & EscapeJson(q) & """}]"
    12. http.send body
    13. If http.Status = 200 Then
    14. resp = http.responseText
    15. ThisWorkbook.Sheets(1).Range("A4").Value = ExtractContent(resp)
    16. Else
    17. MsgBox "Request failed: " & http.Status & " " & http.statusText
    18. End If
    19. End Sub

    Three engineering details must be handled. First, escaping: double quotes, newlines, and backslashes in a question will break the JSON structure, so a shared escaping function is required; building an object in the script layer and serializing it is the safer route. Second, synchronous blocking: the code above freezes the UI and gives a poor experience for long answers, so switch to an asynchronous callback and write the result back into the cell on completion. Third, key management: never hardcode the key in the module; read it from an environment variable or local configuration, and restrict that key to internal addresses only.

    4. Streaming Responses and Long Text

    If the endpoint returns an event stream, incremental content must be split by line, stripped of event prefixes, and concatenated; stop reading when the [DONE] terminator appears. Because some models emit reasoning fragments followed by the final answer, do the split in the orchestration layer, write only the conclusion into the cell, and store the reasoning in a separate column or discard it, so the sheet is not flooded with intermediate text.

    For hundreds or thousands of rows, row-by-row synchronous calls are very slow. Workable strategies include: capping concurrency (excessive local inference concurrency contends for VRAM and actually slows things down), adding exponential backoff retries, persisting completed results before writing them back, and designing a two-stage “chunked summary plus aggregation” flow for very long inputs.

    5. Adding a Knowledge Base: From Q&A to Something Usable

    A bare model only knows its training corpus and tends to fabricate answers about internal policies. With vector retrieval augmentation, the flow becomes: chunk documents and generate vectors, retrieve the most relevant fragments for a question, send the fragments together with the question to the model, and return the answer with its sources. Engineering attention should go to chunk size and overlap length, hybrid retrieval (keywords and vectors weighted together), and a fallback that explicitly answers “I don’t know” when retrieval returns nothing. For multi-turn follow-ups, maintain a session summary in the orchestration layer rather than the full history, to keep context length under control.

    6. Security, Auditing, and Operations

    Internal deployment does not equal security. Recommended practices: bind the interface to loopback or internal addresses only and enable authentication; scope knowledge base visibility by department and apply row-level permission filtering in the orchestration layer; log the asker, timestamp, matched fragments, and response latency in full for traceability; and apply dual redaction to sensitive output using both regex and dictionary matching. On the operations side, use a container platform for consistent delivery, a log service for centralized search, and monitoring and alerting to track VRAM usage and latency shifts. If inference demand spikes, general-purpose cloud compute can provide elastic overflow while data classification is maintained, with sensitive requests always staying local.

    7. Suggested Rollout Path

    Week one: finish model selection and load testing, and determine the concurrency and context length the hardware can support. Week two: get the orchestration layer interface and authentication working end to end. Week three: connect the spreadsheet-side script and handle escaping, asynchronous calls, and error messages. Week four: add the knowledge base, permissions, and auditing to form a small-scale pilot. Three acceptance metrics are worth locking down: the proportion of answers that are traceable to sources, average time to first token, and the human adoption rate. Expand the user base gradually once the metrics are met, rather than a single full rollout that creates operational pressure.