Back to all articles
On-premise private language model container and local data bridge to application infrastructure.

Keep Company Data On-Premises: Local LLM (Ollama) Setup & Oracle APEX REST API Integration

Want the cognitive power of generative AI without exposing confidential company data to third-party clouds? Step-by-step tutorial on running private LLaMA 3 models with Ollama and querying them from Oracle APEX via APEX_WEB_SERVICE.

The Corporate Dilemma: Cloud AI vs Data Privacy

Generative AI offers staggering productivity benefits, but financial institutions, healthcare providers, and defense contractors often face strict compliance laws (GDPR, KVKK, HIPAA) forbidding them from sending sensitive enterprise data to external cloud APIs.

The answer is Local Open-Source LLMs. Using Ollama, you can host state-of-the-art open models like LLaMA 3, Mistral, or DeepSeek on your own local GPU or on-premise server, completely air-gapped from the public internet.


Step 1: Installing Ollama on Ubuntu Server

curl -fsSL https://ollama.com/install.sh | sh
ollama run llama3:8b

By default, Ollama exposes a high-performance REST API on port 11434.


Step 2: Calling Ollama from Oracle APEX via PL/SQL

Using the built-in APEX_WEB_SERVICE package, you can communicate with your local model directly from database triggers, processes, or page items:

DECLARE
    l_req_body  CLOB;
    l_response  CLOB;
    l_prompt    VARCHAR2(4000) := 'Summarize the following customer complaint: ' || :P1_COMPLAINT;
BEGIN
    l_req_body := '{
        "model": "llama3:8b",
        "prompt": "' || apex_escape.json(l_prompt) || '",
        "stream": false
    }';

    apex_web_service.g_request_headers(1).name := 'Content-Type';
    apex_web_service.g_request_headers(1).value := 'application/json';

    l_response := apex_web_service.make_rest_request(
        p_url         => 'http://192.168.1.100:11434/api/generate',
        p_http_method => 'POST',
        p_body        => l_req_body
    );

    :P1_AI_SUMMARY := apex_json.get_clob_elem(p_values => apex_json.parse(l_response), p_path => 'response');
END;

Conclusion

By hosting Ollama internally and connecting it directly to Oracle APEX, enterprises achieve the pinnacle of modern AI capability with 100% data sovereign privacy and zero subscription API fees.