---
title: "Discussion on \"23ai Vector Search & RAG\" | Hashnode"
description: "Discussion on \"23ai Vector Search & RAG\". Integrate Vector Search with Generative AI to build an efficient Retrieval-Augmented Generation (RAG) solution using Oracle 23ai and Oracle APEX."
url: "https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [23ai Vector Search & RAG](https://blog.cloudnueva.com/23ai-vector-search-rag?utm_source=hashnode&utm_medium=feed)

Integrate Vector Search with Generative AI to build an efficient Retrieval-Augmented Generation (RAG) solution using Oracle 23ai and Oracle APEX.

Nov 7, 2024 · 11 min read · blog.cloudnueva.com  
Updated May 19, 2025  
Read the article

-   [#rag](https://hashnode.com/tag/rag)
-   [#orclapex](https://hashnode.com/tag/orclapex)
-   [#vectorsearch](https://hashnode.com/tag/vectorsearch)
-   [#genai](https://hashnode.com/tag/genai)

## Written by

[Jon Dixon](https://hashnode.com/@orclapex)

@orclapex · San Diego, CA

  
[View profile](https://hashnode.com/@orclapex)

APEX, ORDS & the Oracle Database

I’m Jon Dixon, an Oracle APEX developer and consultant at Cloud Nueva. I write about APEX, ORDS, the Oracle Database, and how AI is changing the way we build software. This blog is where I share practical examples, lessons learned, and ideas from my work.

## Responses 1

Markdown supported · ⌘↵ to post

[Matteo Mitrano](https://hashnode.com/@MatteoMit)

[May 19, 2025](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/682b49b2e8b56e2afad3874b)

Hi, Jon In "rag\_blog\_chunks" function, could you please tell me what is "GC\_AI\_INSTRUCTIONS" constant? Besides, what is "GC\_QR\_PROMPT\_TPL" in "query\_reduction" function?

How can I define the values for those costants to avoid PL/SQL compile errors?

[Matteo Mitrano](https://hashnode.com/@MatteoMit)

[May 19, 2025](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/682b49b2e8b56e2afad3874b#reply-682b6a09c7d4b487fd2b5aa6)

[Jon Dixon](https://hashnode.com/@orclapex) Hello again, Jon. Am I asking too much if you give me the declaration and the value you have assigned to them? I don't see the PKG Spec here in the article, otherwise I wouldn't have bothered you.

Thanks for everything and, above all, thanks in advance for the prompt reply

[Jon Dixon](https://hashnode.com/@orclapex)

[May 19, 2025](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/682b49b2e8b56e2afad3874b#reply-682b72c4bce4a569ad76755b)

[Matteo Mitrano](https://hashnode.com/@MatteoMit) You may need to refresh the post to see the updates, but I see them there noe. Search for 'Constants defined in the package specification.'

[Matteo Mitrano](https://hashnode.com/@MatteoMit)

[May 19, 2025](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/682b49b2e8b56e2afad3874b#reply-682b818a94c25251ec98de9b)

Oh, now I see them. 10x again and... have a nice day

[lemar](https://hashnode.com/@marled)

[Dec 4, 2024](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/67502a60fc12aa6826864e4b)

Hello,

How can we construct a cp\_question\_vector based on the text entered in the page item?

Thank you

[Soothfy App](https://hashnode.com/@soothfyapp)

[Nov 9, 2024](https://hashnode.com/posts/23ai-vector-search-rag/672ce299d9add7cb663e5f2f/comment/672f384f4432cfa51f611189)

To build a Retrieval-Augmented Generation (RAG) solution combining 23ai Vector Search and OpenAI in Oracle APEX, follow this process:

### Overview of RAG

Retrieval-Augmented Generation enhances large language models (LLMs) by providing access to external knowledge via retrieval methods. The idea is to retrieve relevant information before generating a contextually accurate response.

### Steps to Implement RAG Solution

1.  **Query Reduction**: Simplify user queries to enhance search accuracy. For example:
    
    -   Original: "Explain APEX Template Components"
    -   Reduced: "APEX Template Components" Utilize advanced models like GPT-4o for better performance in query reduction.
2.  **Run Vector Search**: Use the previously established methods from the earlier post to conduct semantic searches on the relevant blog content.
    
3.  **Send Instructions to OpenAI**: Construct a prompt to guide OpenAI in generating a response based on the user's question and the retrieved blog post chunks. Ensure to include:
    
    -   Instructions for context
    -   The original user question
    -   Relevant text chunks from the vector search
    -   Blog post IDs for source referencing
    
    **Example Prompt**:
    
    ```
    INSTRUCTIONS:
    You are an expert on Oracle technology. Answer the users QUESTION: using the BLOG POSTS: text below. Always Include the number enclosed in ##number## to reference sources used from the included BLOG POSTS:. Prioritize the content of the BLOG POSTS: when determining your answer.
    QUESTION: Can APEX be used to Extend Oracle Fusion Applications?
    BLOG POSTS:
    ##2272## I enjoyed returning to the APEX Alpe Adria conference...
    ...
    ```
    
4.  **Supplement with Links**: Ensure the AI includes blog post IDs in its response. This allows for easy reference generation with links to the original content.
    
5.  **Display Response**: Present the final answer to users, incorporating the relevant sources for transparency and follow-up.
    

### Code Example for RAG Function

Here’s a simplified version of a PL/SQL function that encapsulates the RAG logic:

```
FUNCTION rag_blog_chunks
 (p_question   IN VARCHAR2,
  p_months_ago IN NUMBER,
  p_max_chunks IN NUMBER,
  p_max_bytes  IN NUMBER,
  p_ai_model   IN VARCHAR2,
  p_ai_temp    IN NUMBER,
  p_qr_model   IN VARCHAR2,
  p_ai_qr_temp IN NUMBER) RETURN VARCHAR2 IS

  CURSOR cr_content (cp_question_vector IN VECTOR) IS
    WITH vs AS (
      SELECT cbp.post_id, cbc.id AS chunk_id, cbc.chunk_text,
             vector_distance(cbc.embedding, cp_question_vector) AS vector_distance
      FROM   cnba_post_chunks cbc, cnba_blog_posts cbp
      WHERE  cbp.post_id = cbc.post_id
      AND    cbp.post_published_date_utc > (SYSDATE - NUMTOYMINTERVAL(p_months_ago, 'MONTH')))
    )
    SELECT vs.post_id, vs.chunk_id, vs.chunk_text, vs.vector_distance
    FROM   vs
    ORDER BY vector_distance
    FETCH EXACT FIRST p_max_chunks ROWS ONLY WITH TARGET ACCURACY 95;

  l_question_vector  VECTOR;
  l_chunks           CLOB;
  l_openai_params    JSON;

BEGIN
  -- Capture Parameter Values and execute the retrieval and generation process
  -- ... Additional code logic ...

  RETURN l_generated_response; -- The final response from OpenAI
END;
```

### Conclusion

This RAG architecture leverages both semantic search and the generative capabilities of AI to provide users with precise, contextually informed responses while ensuring proper sourcing of information.
