2.9 KiB
2.9 KiB
723. SGMP QA Vector Retrieval
Goal
Store curated question, answer SQL, answer text, and their combined retrieval
document in SGMP_POC. Retrieve the top-K closest examples for a new question
and pass the returned context to the Text2SQL prompt in a later application
integration.
Security boundary
- IAM identity:
sgmp-qa-vector-api - IAM group:
sgmp-vector-embed-group - IAM policy: only
use generative-ai-text-embedding in tenancy - Database credential:
SGMP_POC_QA_VECTOR_CRED, created from that dedicated API signing key only. It does not reuseSGMP_POC_OCI_DEFAULT_CRED. - Network: HTTPS only to OCI GenAI Chicago EmbedText endpoint on port 443. The
SGMP_POCACE is provisioned once by an ADBADMINconnection because an application schema cannot administer network ACLs. - The private key is read from
VECTOR_OCI_API_KEY_FILE; it is never committed, displayed, or persisted outside the encrypted database credential.
Embedding contract
- Model:
cohere.embed-v4.0 - Dimension:
1536FLOAT32 - The current ADB
DBMS_VECTOROCI adapter does not forward Cohere Embed 4'sinput_typefield; both paths therefore use the provider's compatible default request shape. The model and 1536-dimension vector contract remain fixed. Once the adapter exposes Embed 4input_type, switch stored examples tosearch_documentand incoming questions tosearch_query. p_top_kdefault:3(accepted range1..20)
Oracle recommends distinct document/query input types for Cohere Embed 4 RAG flows and its default output size is 1536. See Cohere Embed 4.
Database API
-- Stores question + answer SQL + optional answer and returns EXAMPLE_ID.
SELECT sg_qa_vector_store(:question, :answer_sql, :answer_text) FROM dual;
-- Returns EXAMPLE_ID, QUESTION, ANSWER_SQL, ANSWER_TEXT, MODEL and distance.
DECLARE
results SYS_REFCURSOR;
BEGIN
results := sg_qa_vector_search(:question); -- default top 3
END;
/
-- Ready-to-insert textual context for a prompt.
SELECT sg_qa_vector_context(:question, 3) FROM dual;
SG_QA_VECTOR_STORE는 SQL SELECT 표현식으로 호출되는 저장 함수이므로,
함수 내부의 INSERT는 자율 트랜잭션으로 수행하고 성공 시 commit, 실패 시 rollback
한다. 이 처리가 없으면 Oracle은 ORA-14551로 DML을 거절한다.
Apply
export SGMP_POC_DB_PASSWORD='...'
export SGMP_POC_WALLET_DIR='/path/to/Wallet_SGMPAIPOC'
export VECTOR_OCI_USER_OCID='...'
export VECTOR_OCI_TENANCY_OCID='...'
export VECTOR_OCI_COMPARTMENT_OCID='...'
export VECTOR_OCI_API_KEY_FILE='/secure/path/sgmp_qa_vector_api_key.pem'
export VECTOR_OCI_API_KEY_FINGERPRINT='...'
./scripts/setup-sgmp-qa-vector.sh
For the initial small QA corpus, exact cosine search is deliberate: it makes results immediately verifiable. Add a vector index only after the corpus size and recall/latency target are measured.