<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged semantic-search</title>
<link>https://coderlegion.com/tag/semantic-search</link>
<description>Powered by Question2Answer</description>
<item>
<title>Oracle AI Vector Search Workflow: From Data to Semantic Search</title>
<link>https://coderlegion.com/11167/oracle-ai-vector-search-workflow-from-data-to-semantic-search</link>
<description>&lt;h2 id=&quot;oracle-ai-vector-search-workflow-from-data-to-semantic-search&quot;&gt;Oracle AI Vector Search Workflow: From Data to Semantic Search&lt;/h2&gt;
&lt;p&gt;Oracle Database 23ai introduces AI Vector Search, enabling semantic search capabilities directly within the database. Unlike traditional keyword-based searches, vector search understands the meaning and context behind your queries, allowing you to find relevant information even when exact keywords don't match.&lt;/p&gt;
&lt;h3 id=&quot;what-are-vector-embeddings-&quot;&gt;What Are Vector Embeddings?&lt;/h3&gt;
&lt;p&gt;Vector embeddings are mathematical representations that capture the semantic meaning of your data. They convert unstructured data like text, images, or audio into numerical vectors that can be mathematically compared.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each embedding is an array of numbers (typically 128 to 1536 dimensions)&lt;/li&gt;
&lt;li&gt;Semantically similar content has vectors that are close together in vector space&lt;/li&gt;
&lt;li&gt;Distance between vectors indicates similarity in meaning&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-oracle-ai-vector-search-workflow&quot;&gt;The Oracle AI Vector Search Workflow&lt;/h3&gt;
&lt;p&gt;The workflow consists of four primary steps:&lt;/p&gt;
&lt;h4 id=&quot;step-1-generate-vector-embeddings&quot;&gt;Step 1: Generate Vector Embeddings&lt;/h4&gt;
&lt;p&gt;You can generate embeddings either &lt;strong&gt;within&lt;/strong&gt; or &lt;strong&gt;outside&lt;/strong&gt; Oracle Database.&lt;/p&gt;
&lt;h5 id=&quot;option-a-within-oracle-database-onnx-&quot;&gt;Option A: Within Oracle Database (ONNX)&lt;/h5&gt;
&lt;p&gt;Load ONNX embedding models directly into the database:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Load the embedding model
EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL(
    'DM_DUMP',
    'all_MiniLM_L12_v2.onnx',
    'doc_model'
);

-- Generate embedding from text string
SELECT TO_VECTOR(
    VECTOR_EMBEDDING(doc_model USING 'hello world' AS data)
) AS embedding;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Common Embedding Patterns:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Convert Text String to Embedding:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_EMBEDDING(doc_model USING 'semantic search' AS data) AS vec;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;2. Convert File → Text → Chunks → Embeddings:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;INSERT INTO doc_chunks (doc_id, chunk_id, chunk_data, embedding)
SELECT 
    d.id,
    JSON_VALUE(c.column_value, '$.chunk_id' RETURNING NUMBER),
    JSON_VALUE(c.column_value, '$.chunk_data'),
    VECTOR_EMBEDDING(doc_model USING 
        JSON_VALUE(c.column_value, '$.chunk_data') AS data)
FROM documents d,
    DBMS_VECTOR_CHAIN.UTL_TO_CHUNKS(
        DBMS_VECTOR_CHAIN.UTL_TO_TEXT(d.pdf_content),
        JSON('{&quot;by&quot;:&quot;words&quot;, &quot;max&quot;:&quot;100&quot;, &quot;overlap&quot;:&quot;20&quot;, 
              &quot;split&quot;:&quot;recursively&quot;, &quot;language&quot;:&quot;american&quot;}')
    ) c;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Chunking Parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;by&lt;/strong&gt;: Chunking method (&lt;code&gt;words&lt;/code&gt;, &lt;code&gt;sentences&lt;/code&gt;, &lt;code&gt;paragraphs&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;max&lt;/strong&gt;: Maximum size per chunk (e.g., 100 words)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;overlap&lt;/strong&gt;: Overlapping units between chunks (prevents context loss)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;split&lt;/strong&gt;: Splitting strategy (&lt;code&gt;recursively&lt;/code&gt;, &lt;code&gt;custom&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;3. Convert Files to Embeddings:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_EMBEDDING(image_model USING file_content AS data) AS vec
FROM media_files;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;4. End-to-End Pipeline:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;INSERT INTO vectorized_docs
SELECT 
    d.doc_id,
    chunks.chunk_data,
    VECTOR_EMBEDDING(doc_model USING chunks.chunk_data AS data)
FROM source_documents d,
    DBMS_VECTOR_CHAIN.UTL_TO_CHUNKS(
        DBMS_VECTOR_CHAIN.UTL_TO_TEXT(d.pdf_blob),
        JSON('{&quot;by&quot;:&quot;words&quot;, &quot;max&quot;:&quot;100&quot;, &quot;overlap&quot;:&quot;20&quot;}')
    ) chunks;
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;option-b-outside-oracle-database&quot;&gt;Option B: Outside Oracle Database&lt;/h5&gt;
&lt;p&gt;Generate embeddings using third-party services or local models:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from sentence_transformers import SentenceTransformer
import oracledb

model = SentenceTransformer('all-MiniLM-L6-v2')
embedding = model.encode(&quot;Oracle AI Vector Search&quot;)

connection = oracledb.connect(user=&quot;user&quot;, password=&quot;pwd&quot;, dsn=&quot;dsn&quot;)
cursor = connection.cursor()
cursor.execute(
    &quot;INSERT INTO documents (id, text, embedding) VALUES (:1, :2, :3)&quot;,
    [1, &quot;Oracle AI Vector Search&quot;, embedding.tolist()]
)
connection.commit()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;In-Database Advantages:&lt;/strong&gt; No data movement, reduced latency, simplified architecture, enterprise security&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;External Advantages:&lt;/strong&gt; Flexibility in model choice, access to latest models, independent scaling&lt;/p&gt;
&lt;h4 id=&quot;step-2-store-vector-embeddings&quot;&gt;Step 2: Store Vector Embeddings&lt;/h4&gt;
&lt;p&gt;Store embeddings in columns with the VECTOR data type within standard relational tables:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    product_name VARCHAR2(200),
    description CLOB,
    price NUMBER(10,2),
    category VARCHAR2(100),
    description_vector VECTOR(384, FLOAT32)
);

-- Insert with inline embedding generation
INSERT INTO products (product_id, product_name, description, description_vector)
VALUES (
    1001,
    'Wireless Headphones',
    'Noise-cancelling Bluetooth headphones',
    VECTOR_EMBEDDING(doc_model USING 'Noise-cancelling Bluetooth headphones' AS data)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Supported Formats:&lt;/strong&gt; INT8 (memory efficient), FLOAT32 (balanced), FLOAT64 (highest precision)&lt;/p&gt;
&lt;h4 id=&quot;step-3-create-vector-indexes&quot;&gt;Step 3: Create Vector Indexes&lt;/h4&gt;
&lt;p&gt;For large datasets, vector indexes are essential for performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Without Index:&lt;/strong&gt; O(n) complexity - compares against every vector (slow for large datasets)&lt;br&gt;
&lt;strong&gt;With Index:&lt;/strong&gt; O(log n) complexity - checks subset of vectors (dramatically faster)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Index Types:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. HNSW (In-Memory, Fast):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX product_hnsw_idx ON products (description_vector)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- Configure memory
ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 2G SCOPE=BOTH;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;2. IVF (Storage-Based, Scalable):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX product_ivf_idx ON products (description_vector)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;3. Hybrid (Text + Semantic):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX product_hybrid_idx ON products (description)
ORGANIZATION HYBRID
PARAMETERS('EMBEDDING MODEL doc_model');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Choosing the Right Index:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HNSW&lt;/strong&gt;: Dataset fits in memory, need maximum speed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IVF&lt;/strong&gt;: Very large datasets or limited memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid&lt;/strong&gt;: Need both keyword and semantic search&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;step-4-query-with-similarity-search&quot;&gt;Step 4: Query with Similarity Search&lt;/h4&gt;
&lt;p&gt;Use native SQL with specialized functions for similarity searches:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Basic Similarity Search:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
    product_name,
    description,
    VECTOR_DISTANCE(
        description_vector,
        VECTOR_EMBEDDING(doc_model USING 'wireless audio device' AS data),
        COSINE
    ) AS similarity_score
FROM products
ORDER BY similarity_score
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Shorthand Operators:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- &amp;lt;=&amp;gt; is cosine distance
SELECT product_name
FROM products
ORDER BY description_vector &amp;lt;=&amp;gt; 
    VECTOR_EMBEDDING(doc_model USING 'wireless audio device' AS data)
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Combining Semantic and Relational Searches:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is Oracle's key advantage—combining semantic similarity with business logic:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Find similar products within price range and category
SELECT 
    product_name,
    price,
    category,
    VECTOR_DISTANCE(description_vector, :query_vec, COSINE) AS similarity
FROM products
WHERE price BETWEEN 100 AND 500
    AND category = 'Electronics'
ORDER BY similarity
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advanced Hybrid Query:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
    p.category,
    COUNT(*) AS matching_products,
    AVG(p.price) AS avg_price,
    MIN(VECTOR_DISTANCE(p.description_vector, :search_vec, COSINE)) AS best_match
FROM products p
WHERE p.price &amp;lt; 1000 AND p.in_stock = 'Y'
GROUP BY p.category
HAVING COUNT(*) &amp;gt; 5
ORDER BY best_match
FETCH FIRST 3 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Distance Metrics:&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Metric &lt;/th&gt;&lt;th&gt;Operator &lt;/th&gt;&lt;th&gt;Best For&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;COSINE &lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;lt;=&amp;gt;&lt;/code&gt; &lt;/td&gt;&lt;td&gt;Text embeddings&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;EUCLIDEAN &lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;lt;-&amp;gt;&lt;/code&gt; &lt;/td&gt;&lt;td&gt;General purpose&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;DOT &lt;/td&gt;&lt;td&gt;N/A &lt;/td&gt;&lt;td&gt;Normalized vectors&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;MANHATTAN &lt;/td&gt;&lt;td&gt;N/A &lt;/td&gt;&lt;td&gt;Specific applications&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;complete-end-to-end-example&quot;&gt;Complete End-to-End Example&lt;/h3&gt;
&lt;p&gt;Building a semantic search system for customer support:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- 1. Load model
EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL('MODEL_DIR', 'all-MiniLM-L12-v2.onnx', 'support_model');

-- 2. Create table
CREATE TABLE support_articles (
    article_id NUMBER PRIMARY KEY,
    title VARCHAR2(500),
    content CLOB,
    category VARCHAR2(100),
    content_vector VECTOR(384, FLOAT32)
);

-- 3. Insert with embeddings
INSERT INTO support_articles (article_id, title, content, category, content_vector)
VALUES (
    1,
    'How to Reset Your Password',
    'To reset your password, navigate to the login page...',
    'Account Management',
    VECTOR_EMBEDDING(support_model USING 'To reset your password...' AS data)
);

-- 4. Create index
CREATE VECTOR INDEX support_vec_idx ON support_articles (content_vector)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- 5. Semantic search
SELECT 
    title,
    category,
    VECTOR_DISTANCE(
        content_vector,
        VECTOR_EMBEDDING(support_model USING 'cannot log into my account' AS data),
        COSINE
    ) AS relevance_score
FROM support_articles
ORDER BY relevance_score
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Even though the query &quot;cannot log into my account&quot; doesn't match exact keywords, it will find articles about password reset, account recovery, and login troubleshooting.&lt;/p&gt;
&lt;h3 id=&quot;document-processing-pipeline&quot;&gt;Document Processing Pipeline&lt;/h3&gt;
&lt;p&gt;Process PDFs into searchable chunks:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Source documents table
CREATE TABLE source_docs (
    doc_id NUMBER PRIMARY KEY,
    filename VARCHAR2(500),
    file_content BLOB
);

-- Chunked content table
CREATE TABLE doc_chunks (
    chunk_id NUMBER PRIMARY KEY,
    doc_id NUMBER,
    chunk_text VARCHAR2(4000),
    chunk_vector VECTOR(384, FLOAT32)
);

-- Process: PDF → Text → Chunks → Vectors
INSERT INTO doc_chunks (chunk_id, doc_id, chunk_text, chunk_vector)
SELECT 
    ROW_NUMBER() OVER (ORDER BY d.doc_id),
    d.doc_id,
    JSON_VALUE(c.column_value, '$.chunk_data'),
    VECTOR_EMBEDDING(doc_model USING 
        JSON_VALUE(c.column_value, '$.chunk_data') AS data)
FROM source_docs d,
    DBMS_VECTOR_CHAIN.UTL_TO_CHUNKS(
        DBMS_VECTOR_CHAIN.UTL_TO_TEXT(d.file_content),
        JSON('{&quot;by&quot;:&quot;words&quot;, &quot;max&quot;:&quot;100&quot;, &quot;overlap&quot;:&quot;20&quot;}')
    ) c;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;best-practices&quot;&gt;Best Practices&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Chunking:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use 20-30% overlap to prevent context loss&lt;/li&gt;
&lt;li&gt;50-100 words for precise matching, 200-300 for broader context&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Index Configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set TARGET ACCURACY between 90-99%&lt;/li&gt;
&lt;li&gt;Allocate sufficient memory for HNSW indexes&lt;/li&gt;
&lt;li&gt;Monitor and rebuild IVF indexes periodically&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Query Optimization:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;FETCH FIRST n ROWS ONLY&lt;/code&gt; for better performance&lt;/li&gt;
&lt;li&gt;Combine vector search with filters early&lt;/li&gt;
&lt;li&gt;Use bind variables for query vectors&lt;/li&gt;
&lt;li&gt;Prefer approximate search for most queries&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Vector Formats:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FLOAT32&lt;/strong&gt;: Best balance (default choice)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;INT8&lt;/strong&gt;: When memory is constrained&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT64&lt;/strong&gt;: Rarely needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;performance-considerations&quot;&gt;Performance Considerations&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Memory Requirements (HNSW):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Memory = 1.3 × (format_size) × (dimensions) × (row_count)
Example: 1M vectors × 384 dims × 4 bytes × 1.3 = ~2 GB
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Typical Performance:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Exact search: Seconds to hours&lt;/li&gt;
&lt;li&gt;Approximate (HNSW): Milliseconds to seconds&lt;/li&gt;
&lt;li&gt;Approximate (IVF): Seconds for billion-scale datasets&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;use-cases&quot;&gt;Use Cases&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;E-commerce product search&lt;/li&gt;
&lt;li&gt;Customer support article matching&lt;/li&gt;
&lt;li&gt;Document management systems&lt;/li&gt;
&lt;li&gt;Fraud detection&lt;/li&gt;
&lt;li&gt;Recommendation engines&lt;/li&gt;
&lt;li&gt;Image similarity search&lt;/li&gt;
&lt;li&gt;Code search with natural language&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;workflow-summary&quot;&gt;Workflow Summary&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Generate Vector Embeddings&lt;/strong&gt;: Load ONNX model or use external APIs, convert data to vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Store Vector Embeddings&lt;/strong&gt;: Create tables with VECTOR columns alongside business data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create Vector Indexes&lt;/strong&gt;: Choose HNSW, IVF, or Hybrid based on dataset size and requirements&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query with Similarity Search&lt;/strong&gt;: Use native SQL combining semantic and relational searches&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Key Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Unified system (vectors + business data)&lt;/li&gt;
&lt;li&gt;Native SQL with vector extensions&lt;/li&gt;
&lt;li&gt;Enterprise features (security, availability, performance)&lt;/li&gt;
&lt;li&gt;Flexible deployment (in-database or external)&lt;/li&gt;
&lt;li&gt;Scalable (thousands to billions of vectors)&lt;/li&gt;
&lt;li&gt;Hybrid queries (semantic + relational filters)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Oracle Database 23ai eliminates data fragmentation by keeping AI algorithms where the data lives, reducing complexity while providing enterprise-grade security and performance.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/11167/oracle-ai-vector-search-workflow-from-data-to-semantic-search</guid>
<pubDate>Fri, 06 Feb 2026 07:12:33 +0000</pubDate>
</item>
<item>
<title>Chat and Embedding Models in OCI Generative AI</title>
<link>https://coderlegion.com/8520/chat-and-embedding-models-in-oci-generative-ai</link>
<description>&lt;p&gt;Oracle Cloud Infrastructure (OCI) Generative AI provides two powerful categories of models: chat models for conversational AI and text generation, and embedding models for semantic understanding and search. Understanding how to configure and optimize these models is essential for building effective AI applications.&lt;/p&gt;
&lt;h3 id=&quot;understanding-tokens&quot;&gt;Understanding Tokens&lt;/h3&gt;
&lt;p&gt;Before diving into model parameters, it's crucial to understand that &lt;strong&gt;LLMs understand tokens rather than characters&lt;/strong&gt;. A token can be a word, part of a word, or even punctuation. As a general rule, estimate &lt;strong&gt;approximately 4 characters per token&lt;/strong&gt;—meaning 100 tokens is roughly 60-80 words.&lt;/p&gt;
&lt;p&gt;This matters because all LLM limits, costs, and parameters are expressed in tokens, not words or characters.&lt;/p&gt;
&lt;h3 id=&quot;chat-models-configuration-parameters&quot;&gt;Chat Models: Configuration Parameters&lt;/h3&gt;
&lt;p&gt;Chat models in OCI Generative AI offer extensive configuration options to control their behavior and output characteristics.&lt;/p&gt;
&lt;h4 id=&quot;max-output-tokens&quot;&gt;Max Output Tokens&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;maximum number of tokens&lt;/strong&gt; that you want the model to generate per response. Each model has different maximum output token limits specified in their key features.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: Because you're prompting a chat model, the response depends on the prompt and each response doesn't necessarily use up the maximum allocated tokens. Setting this parameter essentially creates a ceiling—the model will stop generating once it hits this limit.&lt;/p&gt;
&lt;h4 id=&quot;preamble-override&quot;&gt;Preamble Override&lt;/h4&gt;
&lt;p&gt;An &lt;strong&gt;initial context or guiding message&lt;/strong&gt; for a chat model that changes the model's overall chat behavior and conversation style. When you don't provide a preamble, the model uses its default.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default Preamble for Cohere Command R Family:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;You are Command. You are an extremely capable large language model built by Cohere. 
You are given instructions programmatically via an API that you follow to the best 
of your ability.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Custom Preamble Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;You are a helpful assistant specialized in Italian cuisine. 
Respond with enthusiasm and include regional context when discussing dishes.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this preamble override, when asked about cannolis, the model responds with regional details about Sicily and specific bakeries like Caffe Sierra and Pasticceria Cappello.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Alternative Approach&lt;/strong&gt;: You can also include preamble-like instructions directly in your conversation. For example: &quot;Answer the following question in a marketing tone. Where's the best place to go sailing?&quot;&lt;/p&gt;
&lt;h4 id=&quot;temperature&quot;&gt;Temperature&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Temperature controls the randomness of the output&lt;/strong&gt;. It's one of the most important parameters for shaping model behavior.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How Temperature Works:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Temperature modulates the probability distribution over words in the vocabulary&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Temperature = 0&lt;/strong&gt;: Makes the model deterministic, always selecting the word with the highest probability (essentially greedy decoding)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Low temperature (&amp;lt; 1.0)&lt;/strong&gt;: Distribution is more peaked around the most likely tokens, producing focused, predictable outputs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Temperature = 1.0&lt;/strong&gt;: Standard probability distribution with no modification&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High temperature (&amp;gt; 1.0)&lt;/strong&gt;: Distribution flattens across all words, increasing randomness and creativity&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Start with temperature set to 0 or less than one, and increase it as you regenerate prompts for more creative output. Be cautious: high temperatures can introduce hallucinations and factually incorrect information.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Low temperature (0.0-0.3)&lt;/strong&gt;: Code generation, factual Q&amp;amp;A, technical documentation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Medium temperature (0.5-0.7)&lt;/strong&gt;: General chatbots, customer service, balanced responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High temperature (0.8-1.0+)&lt;/strong&gt;: Creative writing, brainstorming, diverse idea generation&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;top-k-sampling&quot;&gt;Top-K Sampling&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Top-K&lt;/strong&gt; tells the model to pick the next token from the &lt;strong&gt;top K tokens&lt;/strong&gt; in its list sorted by probability.&lt;/p&gt;
&lt;p&gt;A higher value for K generates more random output, making the text sound more natural. The parameter essentially limits the selection pool to the K most likely candidates at each step.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Range:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Minimum&lt;/strong&gt;: 1 (considers only the single most probable token, essentially deterministic)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maximum&lt;/strong&gt;: Vocabulary size (considers all possible tokens)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OCI Default&lt;/strong&gt;: 0 for Command models, -1 for Llama models (meaning the model considers all tokens and doesn't use this method)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If K=3 and the top three tokens are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&quot;favorite&quot; (40% probability)&lt;/li&gt;
&lt;li&gt;&quot;best&quot; (30% probability)  &lt;/li&gt;
&lt;li&gt;&quot;preferred&quot; (15% probability)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The model randomly selects from only these three options, weighted by their probabilities.&lt;/p&gt;
&lt;h4 id=&quot;top-p-nucleus-sampling-&quot;&gt;Top-P (Nucleus Sampling)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Top-P&lt;/strong&gt; is similar to Top-K but &lt;strong&gt;picks from top tokens based on the sum of their probabilities&lt;/strong&gt;. It's more dynamic than Top-K because the number of tokens considered varies.&lt;/p&gt;
&lt;p&gt;Top-P selects tokens whose cumulative probability exceeds a threshold (p), limiting the pool to the smallest set meeting this sum.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Top-P picks the next token based on cumulative probability, ensuring the sum of probabilities is below a certain threshold.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If Top-P = 0.5 and tokens have probabilities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Token A: 0.3 (30%)&lt;/li&gt;
&lt;li&gt;Token B: 0.2 (20%)&lt;/li&gt;
&lt;li&gt;Token C: 0.1 (10%)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The model only considers A and B (cumulative 50%), excluding C.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Range:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Minimum&lt;/strong&gt;: 0.0 (considers only the single most probable token)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maximum&lt;/strong&gt;: 1.0 (considers all tokens)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A high top-p value means the model looks at more possible words, even less likely ones, making generated text more diverse.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Practical Guidelines:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Top-P = 0.5&lt;/strong&gt;: Only considers words adding up to 50% probability—focused responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Top-P = 0.9&lt;/strong&gt;: Includes many more words—varied and original responses&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-interaction-temperature-top-k-and-top-p&quot;&gt;The Interaction: Temperature, Top-K, and Top-P&lt;/h4&gt;
&lt;p&gt;The selection process works in stages: Top-K tokens with highest probabilities are sampled first, then tokens are further filtered based on Top-P, with the final token being selected using temperature.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Decision Framework:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For tasks requiring accuracy and focus (like code completion), use lower temperature, higher Top-P/Top-K, and moderate max tokens&lt;/li&gt;
&lt;li&gt;For creative writing, experiment with higher temperature, lower Top-P/Top-K, and larger max token limits&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;frequency-and-presence-penalties&quot;&gt;Frequency and Presence Penalties&lt;/h4&gt;
&lt;p&gt;These parameters are &lt;strong&gt;useful if you want to get rid of repetition in your outputs&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Frequency Penalty:&lt;/strong&gt;&lt;br&gt;
A penalty assigned to a token when that token appears frequently. High penalties encourage fewer repeated tokens and produce more random output.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Presence Penalty:&lt;/strong&gt;&lt;br&gt;
A penalty assigned to each token when it appears in the output to encourage generating outputs with tokens that haven't been used.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: If your model keeps repeating the same phrases or concepts, increase these penalties to encourage more diverse vocabulary and concepts.&lt;/p&gt;
&lt;h4 id=&quot;seed-parameter-reproducibility-&quot;&gt;Seed Parameter (Reproducibility)&lt;/h4&gt;
&lt;p&gt;Assigning a number for the seed parameter is similar to tagging the request with a number. The LLM aims to generate the same set of tokens for the same integer in consecutive requests.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Notes:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Allowed values are integers; assigning large or small seed values doesn't affect the result&lt;/li&gt;
&lt;li&gt;Especially useful for debugging and testing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Warning&lt;/strong&gt;: The seed parameter might not produce the same result long-term because model updates might invalidate the seed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;OCI Limits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;API: No maximum value&lt;/li&gt;
&lt;li&gt;Console: Maximum value is 9999&lt;/li&gt;
&lt;li&gt;Leave blank (Console) or null (API) to disable&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;stop-sequences&quot;&gt;Stop Sequences&lt;/h4&gt;
&lt;p&gt;A sequence of characters—such as a word, phrase, newline (\n), or period—that tells the model when to stop the generated output.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If the stop sequence is a period (.), the model stops generating text once it reaches the end of the first sentence, even if the token limit is much higher.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: Useful for controlling output length and format, especially when you want responses limited to single sentences or specific sections.&lt;/p&gt;
&lt;h4 id=&quot;likelihood-display&quot;&gt;Likelihood Display&lt;/h4&gt;
&lt;p&gt;Shows how likely a token is to follow the current generated token. Likelihood is defined by a number between -15 and 0, where more negative numbers mean less likely tokens.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: The word &quot;favorite&quot; is more likely to be followed by &quot;food&quot; or &quot;book&quot; rather than &quot;zebra.&quot;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: This parameter doesn't influence the generation process itself but serves as a diagnostic tool to help understand the model's behavior.&lt;/p&gt;
&lt;h3 id=&quot;embedding-models-converting-text-to-vectors&quot;&gt;Embedding Models: Converting Text to Vectors&lt;/h3&gt;
&lt;p&gt;Embedding models transform text into numerical representations that capture semantic meaning, enabling AI systems to understand relationships between words, sentences, and documents.&lt;/p&gt;
&lt;h4 id=&quot;what-are-embeddings-&quot;&gt;What Are Embeddings?&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Embeddings are numerical representations of text converted to number sequences&lt;/strong&gt;. A piece of text can be a phrase, sentence, or one or more paragraphs.&lt;/p&gt;
&lt;p&gt;A vector embedding is a mapping from input (like a word, list of words, or image) into a list of floating-point numbers. That list represents the input in the multidimensional embedding space of the model.&lt;/p&gt;
&lt;h4 id=&quot;oci-embedding-model-dimensions&quot;&gt;OCI Embedding Model Dimensions&lt;/h4&gt;
&lt;p&gt;OCI Generative AI embedding models transform each phrase, sentence, or paragraph into an array with 384 (light models) or 1024 numbers, depending on the embedding model selected.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Available Models:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cohere Embed English V3&lt;/strong&gt;: 1024 dimensions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohere Embed English Light V3&lt;/strong&gt;: 384 dimensions  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohere Embed Multilingual V3&lt;/strong&gt;: 1024 dimensions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohere Embed Multilingual Light V3&lt;/strong&gt;: 384 dimensions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohere Embed 4&lt;/strong&gt;: Latest version supporting text and images&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Trade-offs:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Light models (384d)&lt;/strong&gt;: Faster processing, lower memory usage, suitable for most applications&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standard models (1024d)&lt;/strong&gt;: Richer semantic representation, better for complex similarity tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;types-of-embeddings&quot;&gt;Types of Embeddings&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Word Embeddings:&lt;/strong&gt;&lt;br&gt;
Capture properties and relationships of individual words. Word2vec was the most well-known embedding model for a long time, accepting only single words but very good at representing semantic meaning, typically outputting 300-dimensional vectors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sentence Embeddings:&lt;/strong&gt;&lt;br&gt;
Associate every sentence with a vector of numbers, capturing meaning at the sentence level rather than individual words.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Document Embeddings:&lt;/strong&gt;&lt;br&gt;
Represent entire paragraphs or documents as single vectors, useful for document similarity and classification tasks.&lt;/p&gt;
&lt;h4 id=&quot;semantic-similarity-the-core-principle&quot;&gt;Semantic Similarity: The Core Principle&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Embeddings that are numerically similar are also semantically similar.&lt;/strong&gt; This is the fundamental principle that makes embeddings powerful.&lt;/p&gt;
&lt;p&gt;Similar words, documents, or images have vectors that are also similar. For example, &quot;basketball&quot; and &quot;baseball&quot; have embedding vectors much closer to each other than &quot;rainforest&quot;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Measuring Similarity:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The most popular way to compare vectors is cosine similarity, which measures the cosine of the angle between two vectors in multi-dimensional space. The closer the vectors, the smaller the angle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Other Distance Metrics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Euclidean distance&lt;/strong&gt;: Straight-line distance between vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dot product (inner product)&lt;/strong&gt;: Especially effective for unit vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manhattan distance&lt;/strong&gt;: Sum of absolute differences&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cosine similarity is popular for text embeddings, measuring the angle between vectors. Dot product can also work, especially for unit vectors, offering performance benefits in vector databases.&lt;/p&gt;
&lt;h4 id=&quot;embedding-model-evolution&quot;&gt;Embedding Model Evolution&lt;/h4&gt;
&lt;p&gt;Word2vec was the pioneer, focusing on single words with 300 dimensions—lightweight and great for semantic meaning. Then came OpenAI's text-embedding-ada-002 in 2022, supporting up to 8192 tokens and outputting 1536 dimensions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2025 State of the Art:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Advances in 2025, driven by LLMs and benchmarks, show transformer-based and instruction-tuned embeddings achieving top performance. Key trends include multilingual models (1000+ languages), domain-specific models (medicine, code), and multimodal models (text-image-audio).&lt;/p&gt;
&lt;h4 id=&quot;embedding-use-cases&quot;&gt;Embedding Use Cases&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;1. Vector Databases and Semantic Search&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The most common use case: Embeddings are mostly used for semantic searches where the search function focuses on the meaning of the text rather than finding results based on keywords.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Workflow:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;User query is converted to a vector representation using an embedding model&lt;/li&gt;
&lt;li&gt;Query vector is stored/compared in a vector database&lt;/li&gt;
&lt;li&gt;Similar vectors are retrieved from private content&lt;/li&gt;
&lt;li&gt;Retrieved content is sent to an LLM for response generation&lt;/li&gt;
&lt;li&gt;LLM sends response back to the user&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We use the embedding model to create vector embeddings for content we want to index. The vector embedding is inserted into the vector database with some reference to the original content.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Recommendation Systems&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;By embedding items (products, articles, movies) and user preferences, systems can recommend semantically similar items even if they don't share obvious keywords.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Text Classification and Clustering&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Embeddings enable text classification and text clustering by grouping semantically similar items together.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Classifying support tickets by department&lt;/li&gt;
&lt;li&gt;Categorizing documents by topic&lt;/li&gt;
&lt;li&gt;Detecting duplicate or similar content&lt;/li&gt;
&lt;li&gt;Sentiment analysis grouping&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;4. Retrieval-Augmented Generation (RAG)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While the most common scenario for vector databases is retrieval-augmented generation (RAG), other possible use cases include recommendations, anomaly detection, and more.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Question Answering Systems&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Create chatbots that respond to questions about your own data—for instance, a chatbot responding to employee questions on healthcare coverage. Hundreds of pages of documentation can be split into chunks, converted into embeddings, and searched based on vector similarity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Semantic Caching&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Reduce cost and latency of LLMs by caching LLM completions. LLM queries are compared using vector similarity—if a new query is similar enough to a previously cached query, the cached query is returned.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;7. LLM Conversation Memory&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Persist conversation history with an LLM as embeddings in a vector database. Applications can use vector search to pull relevant history or &quot;memories&quot; into LLM responses.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;8. Cross-Lingual and Multimodal Search&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We can use vector search across languages since embedding models are frequently trained on more than just English data, and we can use vector search with images if we use multimodal embedding models trained on both text and images.&lt;/p&gt;
&lt;h4 id=&quot;vector-databases-storage-and-retrieval&quot;&gt;Vector Databases: Storage and Retrieval&lt;/h4&gt;
&lt;p&gt;A vector database is a database that can store, manage, retrieve, and compare vectors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Capabilities:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Vector databases are purpose-built to manage vector embeddings, offering data management (insert, delete, update), metadata storage and filtering, scalability with distributed processing, and real-time query performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Popular Vector Databases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pinecone&lt;/li&gt;
&lt;li&gt;Weaviate&lt;/li&gt;
&lt;li&gt;Qdrant&lt;/li&gt;
&lt;li&gt;Milvus&lt;/li&gt;
&lt;li&gt;Chroma&lt;/li&gt;
&lt;li&gt;Oracle Database 23ai (with AI Vector Search)&lt;/li&gt;
&lt;li&gt;Azure Redis&lt;/li&gt;
&lt;li&gt;MyScale&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Advanced Features:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Some vector databases can perform hybrid searches by first narrowing results based on characteristics or metadata before conducting vector search—making searches more effective and customizable.&lt;/p&gt;
&lt;h4 id=&quot;oci-embedding-model-input-requirements&quot;&gt;OCI Embedding Model Input Requirements&lt;/h4&gt;
&lt;p&gt;Input data for text embeddings must meet the following requirements: maximum of 96 inputs allowed for each run, with each input less than 512 tokens for text-only models.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Handling Long Inputs:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If an input exceeds the 512 token limit, you can set the Truncate parameter to Start or End to cut off text to fit within the token limit. Setting it to None will produce an error if inputs exceed limits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Multimodal Support:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For text and image embed models like Cohere Embed English Image V3, you can add either text or one image only.&lt;/p&gt;
&lt;h3 id=&quot;best-practices-for-oci-generative-ai&quot;&gt;Best Practices for OCI Generative AI&lt;/h3&gt;
&lt;h4 id=&quot;chat-model-optimization&quot;&gt;Chat Model Optimization&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Start Simple&lt;/strong&gt;: Begin with default parameters, then adjust based on results&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Temperature First&lt;/strong&gt;: Adjust temperature before other sampling parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Preambles Wisely&lt;/strong&gt;: Set clear behavioral expectations with custom preambles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implement Stop Sequences&lt;/strong&gt;: Control output format and length precisely&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test Reproducibility&lt;/strong&gt;: Use seed parameter during development for consistent testing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monitor Penalties&lt;/strong&gt;: Add frequency/presence penalties if seeing repetition&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;embedding-model-selection&quot;&gt;Embedding Model Selection&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Choose Appropriate Dimensions&lt;/strong&gt;: Use light models (384d) for most applications; standard models (1024d) for complex similarity tasks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Select Right Model&lt;/strong&gt;: English vs. Multilingual based on your data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Batch Process&lt;/strong&gt;: Take advantage of the 96-input limit for efficient processing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Index Strategically&lt;/strong&gt;: Store embeddings in vector databases with appropriate indexes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Measure Appropriately&lt;/strong&gt;: Use cosine similarity for most text applications&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;integration-patterns&quot;&gt;Integration Patterns&lt;/h4&gt;
&lt;p&gt;OCI Generative AI integrates with LangChain for building context-augmented applications and RAG solutions. It also works with LlamaIndex for accessing pretrained models or creating custom models on dedicated AI clusters.&lt;/p&gt;
&lt;p&gt;Understanding chat and embedding models in OCI Generative AI enables you to build sophisticated AI applications. Chat models with properly tuned parameters (temperature, top-k, top-p, penalties) produce high-quality, contextually appropriate responses. Embedding models convert text into semantic vectors that power search, recommendations, and retrieval systems.&lt;/p&gt;
&lt;p&gt;Key takeaways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tokens are the fundamental unit&lt;/strong&gt;—everything is measured in tokens, not characters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Temperature controls creativity&lt;/strong&gt;—low for precision, high for creativity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sampling parameters work together&lt;/strong&gt;—Top-K and Top-P filter candidates before temperature applies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Embeddings enable semantic understanding&lt;/strong&gt;—similar meanings produce similar vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vector databases make it practical&lt;/strong&gt;—efficient storage and retrieval of embeddings at scale&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whether building chatbots, implementing semantic search, or creating RAG applications, mastering these parameters and concepts is essential for production-grade AI systems on OCI.&lt;/p&gt;
</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://coderlegion.com/8520/chat-and-embedding-models-in-oci-generative-ai</guid>
<pubDate>Tue, 16 Dec 2025 08:45:24 +0000</pubDate>
</item>
</channel>
</rss>