#ifndef DBMS_VECTOR_TEXT_INTERNAL_HPP #define DBMS_VECTOR_TEXT_INTERNAL_HPP /* * DBMS_VECTOR / DBMS_VECTOR_CHAIN shared text core. * * This module owns the single shared implementation of UTL_TO_CHUNKS * (native chunker engine with the Oracle VECTOR_CHUNKS param grammar) and, * later, UTL_TO_GENERATE_TEXT (provider dispatch over the REST/credential * core), consumed by thin SQL facades in BOTH packages. Business logic * must not be duplicated into dbms_vector.cpp or dbms_vector_chain.cpp. */ #include extern "C" { #include "postgres.h" #include "utils/jsonb.h" } // extern "C" /* * Chunking core behind every UTL_TO_CHUNKS facade: takes the input document * and the jsonb params (by / vocabulary / max / overlap / split / * custom_list / language / normalize / norm_options / extended, the Oracle * grammar) and returns a palloc'd JSON document (text form) - an array of * {"chunk_id","chunk_data","chunk_length","chunk_offset"} objects. * chunk_offset is the 1-based character position of the chunk in the * (normalized) input and chunk_length its character count; both are null * unless "extended": true (Oracle EXTENDED parity). Parameter violations * raise the Oracle parity errors with the ORA-20003 detail. * * Engine notes (documented port semantics; Oracle delegates to its * VECTOR_CHUNKS SQL function, which does not exist here): * - units: "chars"/"characters" count characters (of the database * encoding), "words" count maximal non-whitespace runs; * - "max" bounds a chunk in units (default 1000), "overlap" repeats that * many units of the previous chunk at the start of the next one * (default 0, must be < max); * - "split" (default "recursively") chooses the preferred chunk * boundaries: none / blankline / newline / space / sentence / custom * (custom_list literals, kept at the end of the segment they close) / * recursively (blank lines, then newlines, then spaces, then fixed * windows); segments longer than max are cut into fixed windows; * consecutive segments are packed while they fit; * - "normalize" runs before splitting: widechar (fullwidth -> ASCII), * punctuation (ASCII punctuation removed), whitespace (runs collapsed to * one space and trimmed); offsets refer to the normalized text; * - "language" is accepted and validated as a string but the tokenizer is * language-agnostic (single generic tokenizer); * - "by": "vocabulary" is rejected: vocabulary storage is not ported. */ extern "C" char *dbms_vector_text_chunks(const char *data, size_t len, Jsonb *params); /* * Text generation core behind every UTL_TO_GENERATE_TEXT facade (Oracle * TO_OPENAI_GENERATE_TEXT, pls:3049-3140): provider dispatch ('openai' * only - every other provider is rejected with the Oracle message), * CHECK_REST_PARAMS pre-flight, credential resolution to a bearer key and * the OpenAI-protocol POST through the shared REST core. A url containing * "v1/completions" sends the legacy {"prompt": data, ...passthrough} * body; anything else sends the chat body with the fixed system message * "You are a helpful assistant" and the input as the user message. The * answer is $.choices[0].text, else $.choices[0].message.content, else * the EXCP_PROVIDER_ERR parity error carrying GET_PROVIDER_ERROR of the * response. Returns a palloc'd string with the generated text. */ extern "C" char *dbms_vector_text_generate(const char *data, size_t len, Jsonb *params); #endif // DBMS_VECTOR_TEXT_INTERNAL_HPP