Zero Labs
Industry News / AI

Building a Custom AI Assistant Inside Your Oracle APEX App

Source · Towards AI By Sarfaraz Merchant

From the publisher’s feed, collected in the ZeroLabs newsroom.

In Part 1 of this series Guide to Your OpenRouter API Key, we grabbed our Free “Universal API Key” from OpenRouter.In Part 2, we used it to architect a full HRMS Portal from scratch using AI.What if your database could actually talk back to you? Imagine a world where you don’t need a report just to find an employee’s remaining leave balance or their last salary hike. What if you could convert your entire data warehouse into a conversational partner, getting instant answers by simply asking questions in Natural Language?Today, in Part 3 of this series we are going to give that application a “brain.”Most enterprise apps are great at showing data, but they struggle to answer simple questions like, “Who is the highest-paid employee in IT?” or “How many leave requests are pending?” Today, we will build an AI Assistant inside APEX to do exactly that.Prerequisite:Must Have API Key from Previous Blog Part 1.Must be Having an APEX instance to Practice this demo. (if you are new to Oracle Apex then create your free workspace now :Get started with APEX.You should have a Sample Application, as we have created in Part 2Step 1: Create Generative AI ConfigurationFirst, we need to establish the connection between APEX and the AI model.Navigation: Go to your application in App Builder -> Shared Components -> Generative AI-> AI Configurations -> Create.AI ConfigurationsCreate New ConfigurationName: Employee APP AI ConfigurationsService: OpenRouter_Free_AI (Service We Created in Part 2 of the Series)System Prompt: > “You are an AI Assistant. Help answer queries related to employees, their departments, salary details, and leave status based on the provided data.”Welcome Message: “Hi, how may I help you today?”Click Create Button.Configuration DetailsAs soon as you click create button you will be redirected to RAG Sources.Step 2: Create RAG SourceNow, we give the AI “eyes” to see your data by creating a RAG source using a specialized SQL query.Navigation: Within your Employee APP AI Configurations, click on the RAG Sources tab -> Create RAG Source.Create RAG SourceName: Employee Assistant RAGDescription: Fetches comprehensive employee, department, salary, and leave details.Source Type: SQL QuerySQL Query:SELECT e.id AS employee_id, e.first_name || ‘ ‘ || e.last_name AS full_name, e.email, e.hire_date, e.job_id, d.name AS department_name, d.location AS department_location, m.first_name || ‘ ‘ || m.last_name AS manager_name, sh.salary_amount AS current_salary, lr.leave_type, lr.status AS leave_statusFROM hr_employees_1 eJOIN hr_departments_1 d ON e.department_id = d.idLEFT JOIN hr_employees_1 m ON e.manager_id = m.idLEFT JOIN ( SELECT employee_id, salary_amount FROM (SELECT employee_id, salary_amount, ROW_NUMBER() OVER (PARTITION BY employee_id ORDER BY effective_date DESC) as rn FROM hr_salary_history_1) WHERE rn = 1) sh ON e.id = sh.employee_idLEFT JOIN ( SELECT employee_id, leave_type, status FROM (SELECT employee_id, leave_type, status, ROW_NUMBER() OVER (PARTITION BY employee_id ORDER BY updated_on DESC) as rn FROM hr_leave_requests_1) WHERE rn = 1) lr ON e.id = lr.employee_id;Configure RAG SourceStep 3: Create AI Assistant Chat InterfaceFinally, we add the UI component to your application so users can actually interact with the bot.3.1) Create the Launch ButtonNavigate to the page where you want the chatbot (e.g., the Employee Dashboard).Right-click on Breadcrumb Bar and click Create Button.Name: AIAssistantRegion: BreadcrumbButton Template: Text with IconIcon: fa-ai-microchipBehavior Action: Defined by Dynamic ActionAdding Buttoon to Chat interface in Employee Page.3.2) Create the Dynamic ActionRight-click on the new button -> Create Dynamic Action.Name: Assistant ChatbotTrue Action: Show AI AssistantConfiguration: Employee APP AI ConfigurationsDynamic ActionTrue Action to open Chat interfaceResult: Live DemoConclusion: What We AchievedWe successfully transformed static HR data into a conversational interface.Live Insights: The bot uses RAG to fetch real-time salary and leave status.Efficiency: Users get answers via natural language instead of running manual reports.Native Integration: A modern, AI-first experience built entirely within the APEX framework.What’s Next?This concludes our 3-part series on building AI-powered applications in Oracle APEX. But I am not stopping here! Stay tuned for my upcoming deep dives into the Oracle AI ecosystem, including:AI in Oracle Integration Cloud (OIC)AI in Oracle FusionI Want to Hear From You!Would you like to see a video tutorial covering this entire 3-part blog series? I’d love to walk you through the setup live!Let me know in the comments if a video version would be helpful for your learning journey!Building a Custom AI Assistant Inside Your Oracle APEX App was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.