Oracle Database and APEX-oriented chatbot proof of concept for a single APEX application for applications unable to run APEX 26.1
The project stores:
- chatbot definitions and prompts
- chatbot display images and searchable product images
- AI model connection settings
- conversation messages and embeddings
It exposes CB_AGENT for provider-backed responses and CB_CONVERSATION for
conversation lifecycle actions such as submitting a turn, archiving, clearing,
and selecting a contextual display image.
The current design is intentionally provider-neutral:
- The APEX app calls
CB_CONVERSATION.submit_turnwith a message, or a blank message to regenerate a response for the latest user message. CB_CONVERSATIONsaves a supplied user message and callsCB_AGENTwith a model configuration row.CB_AGENTloads the bot prompt, current summary, unsummarized history, and recalled summarized messages.- The provider subtype delegates request construction and HTTP execution to
CB_ADAPTER_OPENAIorCB_ADAPTER_CLAUDE. CB_AGENT.get_text_responsereturns assistant text only.CB_CONVERSATIONsaves the assistant message after the call.- An APEX BLOB item can retrieve the image whose definition is closest to the
latest assistant reply through
CB_CONVERSATION.get_current_image_blob. It falls back to the chatbot display image. CB_AGENT.create_summarysummarizes older conversation rows and appends the raw summary toCB_CHATBOTS.CURRENT_SUMMARY.
The scripts are grouped by object type:
database objects/tables/database objects/types/database objects/type bodies/database objects/packages/database objects/package bodies/database objects/triggers/
Key objects:
| Object | Purpose |
|---|---|
CB_CHATBOTS |
Stores chatbot definitions, display image metadata, prompts, welcome text, and running summary text. |
CB_CHATBOT_IMAGES |
Stores chatbot-owned images, image definitions, and definition embeddings for searchable product context. |
CB_AI_MODELS |
Stores provider URL, API key, model name, signature type, and optional default token limit. |
CB_CHATBOT_CONVERSATIONS |
Stores conversation messages, role, embedding, summary flag, and timestamps. |
CB_CHATBOT_ARCHIVES |
Stores complete transcript snapshots as JSON, with chatbot prompt and name snapshots. |
CB_PROVIDER_T |
Abstract provider contract used for polymorphic dispatch. |
CB_OPENAI_PROVIDER_T |
Concrete OpenAI-compatible provider subtype. |
CB_CLAUDE_PROVIDER_T |
Concrete Anthropic/Claude provider subtype. |
CB_AGENT |
Public facade for chat responses and summaries. |
CB_CONVERSATION |
Conversation lifecycle facade for submit/regenerate, archive, clear, and contextual BLOB image retrieval. |
CB_AGENT_UTIL |
Shared validation, JSON, and HTTP helper package. |
CB_MEMORY |
Embedding and semantic recall helpers. |
CB_CHATBOT_CONVERSATIONS_BIU |
Trigger that maintains message embeddings. |
CB_CHATBOT_IMAGES_BIU |
Trigger that maintains image definition embeddings. |
CB_CONVERSATION.submit_turn saves or locates the current user-message row, then
calls CB_AGENT.get_text_response. The agent uses that row's embedding for
memory recall and assembles the request context in this order:
CB_CHATBOTS.PROMPTCB_CHATBOTS.GLOBAL_CONTEXT, when presentCB_CHATBOTS.CURRENT_SUMMARY, when present- recalled summarized messages
- live unsummarized conversation rows
CB_AGENT passes the first four items to provider adapters as one structured,
provider-neutral system-context JSON object. OpenAI-compatible adapters flatten
the object back into one system message. Claude sends separate Anthropic system
blocks: it caches the stable prompt/global-context prefix and adds a second
cache breakpoint after the running summary. Retrieved memory is intentionally
uncached. Claude cache diagnostics are written to APEX_DEBUG from the
provider response usage fields; the default cache lifetime is five minutes.
CB_AGENT.create_summary summarizes older unsummarized rows, appends the model output to CB_CHATBOTS.CURRENT_SUMMARY, and marks the included rows as summarized.
The usual APEX flow is:
- Call
CB_CONVERSATION.submit_turn. - Refresh the chat and image regions.
Typical calls use either a saved model row or direct provider details:
CB_CONVERSATION.submit_turn(
p_model_id => :PXX_MODEL_ID,
p_chatbot_id => :PXX_CHATBOT_ID,
p_user_message => :PXX_MESSAGE
);select cb_conversation.get_current_image_blob(:PXX_CHATBOT_ID) as image
from dual;This project expects an Oracle Database and APEX environment with support for:
APEX_AIAPEX_WEB_SERVICEAPEX_DEBUGUTL_HTTP- object types and polymorphic methods
- the
VECTORdatatype used for embeddings
The embedding helper uses the APEX AI service static ID db_onnx_model.
- The project is scoped to one chatbot proof of concept for one APEX application.
CB_AGENTdoes not insert assistant messages directly;CB_CONVERSATION.submit_turnowns chat-turn persistence.- Archive and clear are intentionally separate operations: archiving is non-destructive.
- Semantic image selection compares the latest assistant reply with image-definition embeddings using cosine distance; it falls back to
CB_CHATBOTS.IMAGE. - Conversation memory is based on summarized rows only.
- Message embeddings are maintained by trigger, not by the provider adapters.
CB_AI_MODELS.API_KEYstores the raw secret, and the packages format provider-specific headers at runtime.- Claude prompt caching does not currently cache conversation history because retrieved context changes before the message array in the Anthropic request.
- The fixed
vector(384, float32)embedding columns require the configured embedding service to continue returning compatible vectors. - Network ACL, wallet, and certificate setup are not documented here yet.
- SQL export packaging and Liquibase support are not part of this repository snapshot.
For a deeper object-by-object breakdown, see database objects/PROJECT_MAP.md.