<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged vector-search</title>
<link>https://coderlegion.com/tag/vector-search</link>
<description>Powered by Question2Answer</description>
<item>
<title>AI Fundamentals - Part 3: Giving AI Knowledge Beyond Its Training</title>
<link>https://coderlegion.com/22352/ai-fundamentals-part-3-giving-ai-knowledge-beyond-its-training</link>
<description>&lt;p&gt;In &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/21936/ai-fundamentals-part-2-why-ai-gets-things-right-and-wrong&quot;&gt;Part 2&lt;/a&gt;, we learned why AI sometimes hallucinates. One of the biggest reasons is that an LLM can only answer based on what it learned during training and the information available in its context window. We also introduced &lt;strong&gt;grounding&lt;/strong&gt;-providing the model with reliable information at runtime instead of expecting it to know everything.&lt;/p&gt;
&lt;p&gt;But that raises an important question: &lt;strong&gt;Where does that information come from?&lt;/strong&gt; Modern AI applications don't simply dump an entire database or a thousand-page PDF into the prompt. Instead, they first identify the &lt;em&gt;most relevant&lt;/em&gt; pieces of information and only send those to the model. In this article, we'll learn how that works.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;running-example&quot;&gt;Running Example&lt;/h3&gt;
&lt;p&gt;Let's continue building our &lt;strong&gt;AI-powered Travel Planner&lt;/strong&gt;. So far, it can answer general travel questions using the knowledge it learned during training. Now we want to make it much smarter by uploading several documents into our application:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lonely Planet's Japan travel guide&lt;/li&gt;
&lt;li&gt;A PDF containing train schedules&lt;/li&gt;
&lt;li&gt;A document listing recommended local restaurants&lt;/li&gt;
&lt;li&gt;Hotel information&lt;/li&gt;
&lt;li&gt;Internal travel policies for our company&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Together, these documents contain hundreds of pages. Now the user asks:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;I'm staying near Tokyo Station. Which ramen restaurant from our travel guide is within walking distance and is known for vegetarian options?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Somewhere in those hundreds of pages is the answer. The challenge is no longer generating text-it's &lt;strong&gt;finding the right information first.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-problem-an-llm-can-t-read-your-entire-knowledge-base-every-time&quot;&gt;The Problem: An LLM Can't Read Your Entire Knowledge Base Every Time&lt;/h2&gt;
&lt;p&gt;A common misconception is that AI applications simply send all their documents to the model. Imagine our travel guide contains 450 pages, thousands of restaurant listings, hotel descriptions, transportation details, and sightseeing recommendations. Sending all of that to the LLM every time someone asks &lt;em&gt;&quot;Where should I eat tonight?&quot;&lt;/em&gt; creates several problems.&lt;/p&gt;
&lt;p&gt;First, many documents are simply too large to fit inside the model's context window. Second, even if they did fit, making the model read hundreds of irrelevant pages just to answer a simple question is expensive, slow, and inefficient. Instead, we want to send &lt;strong&gt;only the information that matters&lt;/strong&gt;. The question becomes: &lt;strong&gt;How do we find the right few paragraphs from hundreds of pages?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Your first instinct might be: &lt;em&gt;&quot;Why not just search the documents?&quot;&lt;/em&gt; That's exactly what we'll explore next.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;keyword-search-the-traditional-approach&quot;&gt;Keyword Search: The Traditional Approach&lt;/h2&gt;
&lt;p&gt;Before AI became popular, most applications relied on &lt;strong&gt;keyword search&lt;/strong&gt;. The idea is simple: the user searches for a word, and the application finds documents containing that exact word.&lt;/p&gt;
&lt;p&gt;For example, given this travel guide text:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;Tokyo has several excellent vegetarian ramen restaurants...
Mount Fuji is one of Japan's most iconic landmarks...
The Shinkansen connects Tokyo and Kyoto...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the user searches for &lt;em&gt;&quot;vegetarian ramen&quot;&lt;/em&gt;, the search engine finds the first paragraph because it contains both words. While traditional keyword search is simple, fast, and easy to understand, it falls short when matching meaning instead of exact text.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;when-keyword-search-falls-short&quot;&gt;When Keyword Search Falls Short&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Synonyms and Meaning (Example 1):&lt;/strong&gt; If a user asks &lt;em&gt;&quot;Where can I eat meat-free ramen?&quot;&lt;/em&gt; and our document says &lt;em&gt;&quot;Vegetarian ramen is available near Tokyo Station&quot;&lt;/em&gt;, a traditional keyword search may completely miss this result because it searches for exact words, not meaning. It doesn't know that &lt;em&gt;meat-free&lt;/em&gt;, &lt;em&gt;vegetarian&lt;/em&gt;, and &lt;em&gt;plant-based&lt;/em&gt; are closely related concepts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Name Variations (Example 2):&lt;/strong&gt; If a user asks to &lt;em&gt;&quot;Suggest a place near Fujisan&quot;&lt;/em&gt;, and the document says &lt;em&gt;&quot;A day trip to Mount Fuji is highly recommended&quot;&lt;/em&gt;, keyword search often fails because it doesn't understand that &lt;em&gt;Fujisan&lt;/em&gt; and &lt;em&gt;Mount Fuji&lt;/em&gt; refer to the same place.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Terminology Differences (Example 3):&lt;/strong&gt; If a user asks &lt;em&gt;&quot;Where can I find authentic local noodle shops?&quot;&lt;/em&gt; and the guide says &lt;em&gt;&quot;Several ramen restaurants popular with residents...&quot;&lt;/em&gt;, keyword search fails to connect &lt;em&gt;noodle shop&lt;/em&gt; with &lt;em&gt;ramen restaurant&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The real limitation is that keyword search compares &lt;strong&gt;text&lt;/strong&gt;, while humans compare &lt;strong&gt;meaning&lt;/strong&gt;. This is why search systems often return dozens of irrelevant results or miss the best result entirely, as you've likely experienced when searching documentation using a word that differs from the author's chosen terminology.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;semantic-search-searching-by-meaning&quot;&gt;Semantic Search: Searching by Meaning&lt;/h2&gt;
&lt;p&gt;This is where AI changes everything. Instead of asking &lt;em&gt;&quot;Does this document contain the same words?&quot;&lt;/em&gt;, semantic search asks &lt;strong&gt;&quot;Does this document mean the same thing?&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Let's return to our example. The user asks &lt;em&gt;&quot;Where can I eat meat-free ramen near Tokyo Station?&quot;&lt;/em&gt; and the travel guide says &lt;em&gt;&quot;Ichiran offers vegetarian ramen a short walk from Tokyo Station.&quot;&lt;/em&gt; A semantic search understands that &lt;em&gt;meat-free&lt;/em&gt; and &lt;em&gt;vegetarian&lt;/em&gt; express nearly the same idea, allowing it to retrieve the correct passage even though the exact words are different.&lt;/p&gt;
&lt;p&gt;But computers don't naturally understand meaning; they understand numbers. How can a computer determine that &lt;em&gt;vegetarian&lt;/em&gt; and &lt;em&gt;meat-free&lt;/em&gt; are closely related? That's where &lt;strong&gt;embeddings&lt;/strong&gt; come in.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;embeddings-turning-meaning-into-numbers&quot;&gt;Embeddings: Turning Meaning into Numbers&lt;/h2&gt;
&lt;p&gt;An &lt;strong&gt;embedding&lt;/strong&gt; is a numerical representation of text that captures its meaning. Think of it as a fingerprint-not of the exact words, but of what those words represent.&lt;/p&gt;
&lt;p&gt;For example, these three phrases all have different wording but express similar ideas, so their embeddings end up being very similar:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vegetarian ramen&lt;/li&gt;
&lt;li&gt;Meat-free noodles&lt;/li&gt;
&lt;li&gt;Plant-based ramen&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Conversely, phrases like &lt;em&gt;Mount Fuji&lt;/em&gt;, &lt;em&gt;Flight booking&lt;/em&gt;, and &lt;em&gt;Currency exchange&lt;/em&gt; produce embeddings that are quite different because they represent completely unrelated concepts. The key takeaway is: &lt;strong&gt;embeddings represent meaning, not exact wording.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-not-compare-the-original-text-&quot;&gt;Why Not Compare the Original Text?&lt;/h3&gt;
&lt;p&gt;Let's go back to our Travel Planner. Suppose our travel guide contains:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;Ichiran offers vegetarian ramen near Tokyo Station.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now imagine two different users:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;User A:&lt;/strong&gt; &lt;em&gt;Recommend vegetarian ramen.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;User B:&lt;/strong&gt; &lt;em&gt;Where can I find meat-free noodle restaurants?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A computer comparing plain text sees very few matching words between User B's query and the guide. A traditional keyword search might decide they are unrelated. Embeddings solve this by converting both pieces of text into numerical representations where similar meanings end up close together.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;semantic-similarity-measuring-meaning-instead-of-words&quot;&gt;Semantic Similarity: Measuring Meaning Instead of Words&lt;/h2&gt;
&lt;p&gt;Once text is converted into embeddings, comparing sentences becomes much easier. Instead of asking if they contain the same words, we ask: &lt;strong&gt;How similar are their embeddings?&lt;/strong&gt; If two embeddings are close together, they are likely talking about similar ideas; if they are far apart, they are probably unrelated.&lt;/p&gt;
&lt;p&gt;A useful mental model is to imagine every sentence placed on a giant map. Similar ideas appear close together, while unrelated concepts are placed farther apart:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                  Travel

                      ●
                Visit Japan

           ●                   ●
  Vegetarian Ramen      Tokyo Station

                ●
         Meat-free Noodles


--------------------------------------------


                      ●
              JavaScript Closures

                                ●
            Docker Networking
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice how the travel-related concepts naturally cluster together, while completely unrelated software concepts appear elsewhere. This is exactly what embeddings help achieve.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;cosine-similarity-finding-the-closest-match&quot;&gt;Cosine Similarity: Finding the Closest Match&lt;/h2&gt;
&lt;p&gt;Now that every sentence has an embedding, we need a way to compare them mathematically. One of the most common techniques is &lt;strong&gt;cosine similarity&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Suppose our Travel Planner has these restaurant descriptions stored:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A:&lt;/strong&gt; &lt;em&gt;Vegetarian ramen near Tokyo Station.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B:&lt;/strong&gt; &lt;em&gt;Traditional sushi restaurant.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C:&lt;/strong&gt; &lt;em&gt;Italian pizza in Osaka.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the user asks for &lt;em&gt;&quot;Meat-free noodles near Tokyo Station&quot;&lt;/em&gt;, the embeddings might compare like this:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Restaurant                          &lt;/th&gt;&lt;th&gt;Similarity&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Vegetarian ramen near Tokyo Station &lt;/td&gt;&lt;td&gt;  &lt;strong&gt;0.96&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Traditional sushi restaurant        &lt;/td&gt;&lt;td&gt;      0.41&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Italian pizza in Osaka              &lt;/td&gt;&lt;td&gt;      0.09&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The higher the score, the closer the meanings. Notice that the user never mentioned the word &lt;em&gt;vegetarian&lt;/em&gt;, yet Restaurant A is still identified as the best match because the meaning is similar.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Mental Model&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In a library, keyword search works like looking up every book containing the word &lt;em&gt;ramen&lt;/em&gt;. Semantic search works by finding books discussing the same idea, even if they use completely different words.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id=&quot;where-do-these-embeddings-come-from-&quot;&gt;Where Do These Embeddings Come From?&lt;/h2&gt;
&lt;p&gt;Fortunately, you don't have to calculate these numbers yourself. Just as LLMs specialize in generating text, there are &lt;strong&gt;embedding models&lt;/strong&gt; that specialize in generating embeddings. Instead of producing a paragraph, an embedding model takes text and produces a list of numbers representing its meaning:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;User Text (&quot;Vegetarian ramen...&quot;) ──► Embedding Model ──► [0.18, -0.42, 0.91, ...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The resulting list (or vector) usually contains hundreds or thousands of numbers. You never need to interpret them yourself; their only purpose is to make mathematical similarity comparisons possible.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;chunking-breaking-large-documents-into-pieces&quot;&gt;Chunking: Breaking Large Documents into Pieces&lt;/h2&gt;
&lt;p&gt;How do we generate embeddings for a 500-page travel guide? We don't feed the entire book into the embedding model at once. Embedding models have strict input limit constraints (typically measured in tokens), and comparing a whole book's meaning is too vague to be useful. If a user asks about a specific ramen restaurant, we want to retrieve the exact paragraph discussing it, not a 500-page book embedding.&lt;/p&gt;
&lt;p&gt;So, we break the document down into smaller, logical pieces in a process called &lt;strong&gt;chunking&lt;/strong&gt;. A chunk could be a single paragraph, a section of 100-200 words, or a sliding window of text (e.g., 200 words with a 20-word overlap to ensure context isn't cut off at boundaries).&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Mental Model&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Think of chunking like cutting a long movie reel into short, thematic scenes. If you want to find the scene with Mount Fuji, it is much easier to search and index short clips than searching the entire three-hour film.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;💡 Developer's Takeaway&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Choosing the right chunk size is a balancing act. If chunks are too small, they might lose context (e.g., a sentence saying &lt;em&gt;&quot;It is delicious&quot;&lt;/em&gt; without mentioning &lt;em&gt;what&lt;/em&gt; is delicious). If they're too large, the specific details get averaged out, and search accuracy drops.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;vector-databases-storing-and-indexing-meanings&quot;&gt;Vector Databases: Storing and Indexing Meanings&lt;/h2&gt;
&lt;p&gt;Once we have broken our travel guide into thousands of chunks and generated an embedding for each, we need a place to store them. Traditional databases (like PostgreSQL or MySQL) are optimized for finding exact matches like numbers, dates, or strings. They aren't designed to compare thousands of high-dimensional lists of numbers to find which ones are &quot;closest&quot; in meaning.&lt;/p&gt;
&lt;p&gt;That's where &lt;strong&gt;Vector Databases&lt;/strong&gt; come in. A vector database is designed specifically to store and index high-dimensional vectors (embeddings) and search through them based on mathematical similarity (like cosine similarity) extremely fast.&lt;/p&gt;
&lt;p&gt;Common vector database setups include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dedicated vector databases&lt;/strong&gt; (Pinecone, Milvus, Qdrant, Chroma)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vector extensions&lt;/strong&gt; for traditional databases (like &lt;code&gt;pgvector&lt;/code&gt; for PostgreSQL)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;💡 Developer's Takeaway&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You don't need to write complex search algorithms yourself. A vector database handles the indexing and allows you to query it using an embedding, returning the most semantically similar chunks in milliseconds.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;embedding-dimensions-understanding-the-scale&quot;&gt;Embedding Dimensions: Understanding the Scale&lt;/h2&gt;
&lt;p&gt;When you configure a vector database, it will ask you to specify the number of &lt;strong&gt;dimensions&lt;/strong&gt;. Dimensions refer to the size of the list of numbers generated by the embedding model. For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A lightweight model might output vectors with &lt;strong&gt;384&lt;/strong&gt; dimensions.&lt;/li&gt;
&lt;li&gt;A standard model (like OpenAI's &lt;code&gt;text-embedding-3-small&lt;/code&gt;) outputs &lt;strong&gt;1536&lt;/strong&gt; dimensions.&lt;/li&gt;
&lt;li&gt;Large models can output &lt;strong&gt;3072&lt;/strong&gt; dimensions or more.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each dimension represents an abstract feature of meaning that the model learned during training. You don't need to know what each dimension represents; the database only cares that you are comparing vectors of the exact same size.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;💡 Developer's Takeaway&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;An embedding model and a vector database must match: you cannot store a 1536-dimension embedding in a database index configured for 384 dimensions.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;rag-retrieval-augmented-generation-putting-it-together&quot;&gt;RAG (Retrieval-Augmented Generation): Putting It Together&lt;/h2&gt;
&lt;p&gt;Now we have all the pieces to solve our Travel Planner's original challenge: answering questions using our travel guides without sending the entire book to the LLM. We use a pattern called &lt;strong&gt;RAG (Retrieval-Augmented Generation)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;RAG combines &lt;strong&gt;Retrieval&lt;/strong&gt; (finding relevant chunks from our vector database) and &lt;strong&gt;Generation&lt;/strong&gt; (having the LLM write a response using those chunks). Here is the step-by-step workflow:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ingestion (Happens once in advance):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Break documents into chunks.&lt;/li&gt;
&lt;li&gt;Generate embeddings for each chunk.&lt;/li&gt;
&lt;li&gt;Store the chunks and their embeddings in a vector database.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Querying (Happens at runtime):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;User asks: &lt;em&gt;&quot;Recommend a vegetarian ramen shop near Tokyo Station.&quot;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;The application generates an embedding for the user's question.&lt;/li&gt;
&lt;li&gt;The application queries the vector database using this question embedding.&lt;/li&gt;
&lt;li&gt;The database returns the top 2 or 3 most similar text chunks.&lt;/li&gt;
&lt;li&gt;The application merges the user's question and the retrieved chunks into a single prompt (grounding context).&lt;/li&gt;
&lt;li&gt;The LLM reads the context and generates a correct, verified answer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;               User Question
                     │
                     ▼
             Generate Embedding
                     │
                     ▼
    Query Vector DB ──► Stored Chunks
                     │
                     ▼
            Get Relevant Chunks
                     │
                     ▼
    Build Prompt (Question + Chunks)
                     │
                     ▼
             LLM Generates Text
                     │
                     ▼
             Grounded Response
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;💡 Developer's Takeaway&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;RAG is the most popular way to connect proprietary data to LLMs. It ensures the model's response is grounded in facts, reduces hallucinations, and works without needing to retrain the model.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;cag-cache-augmented-generation-the-new-alternative&quot;&gt;CAG (Cache-Augmented Generation): The New Alternative&lt;/h2&gt;
&lt;p&gt;While RAG is powerful, it requires setting up chunking pipelines, embedding models, and vector databases. This can be complex. With modern LLMs having massive context windows (often supporting 1 million to 2 million tokens), another approach has emerged: &lt;strong&gt;CAG (Cache-Augmented Generation)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Instead of retrieving matching chunks at runtime, CAG preloads the entire document set (e.g., our 500-page travel guide) directly into the model's context window. It leverages &lt;strong&gt;KV (Key-Value) Caching&lt;/strong&gt; to precompute and cache the mathematical states of the documents once. When a user asks a question, the LLM reads the cached documents instantly, bypassing the retrieval pipeline entirely.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;RAG&lt;/strong&gt; is like looking up a topic in a library catalog, retrieving three specific books, and reading them to find the answer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CAG&lt;/strong&gt; is like having the entire encyclopedia already open on your desk with the pages instantly readable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;💡 Developer's Takeaway&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;CAG simplifies the architecture by eliminating vector databases and chunking. However, it is limited by the size of the context window and is best suited for relatively static datasets that fit comfortably within the model's limit. RAG remains essential for massive or constantly changing data.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;recap&quot;&gt;Recap&lt;/h2&gt;
&lt;p&gt;In this article, we explored how to give AI knowledge beyond its training. We covered:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Keyword Search vs. Semantic Search&lt;/li&gt;
&lt;li&gt;Embeddings, Semantic Similarity, and Cosine Similarity&lt;/li&gt;
&lt;li&gt;Chunking, Vector Databases, and Embedding Dimensions&lt;/li&gt;
&lt;li&gt;RAG (Retrieval-Augmented Generation) and CAG (Cache-Augmented Generation)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/22353/ai-fundamentals-part-4-building-real-ai-applications&quot;&gt;Part 4&lt;/a&gt;&lt;/strong&gt;, we will answer the next logical question: &lt;strong&gt;How do we connect our model to the outside world so it can execute tasks, use external APIs, and remember users over time?&lt;/strong&gt; We will explore tool calling, memory, Model Context Protocol (MCP), and AI agents.&lt;/p&gt;
</description>
<category>Tutorials</category>
<guid isPermaLink="true">https://coderlegion.com/22352/ai-fundamentals-part-3-giving-ai-knowledge-beyond-its-training</guid>
<pubDate>Sun, 12 Jul 2026 06:45:12 +0000</pubDate>
</item>
<item>
<title>SurrealDB: The &quot;One-Size-Fits-All&quot; Database for Lazy Developers (Part 1)</title>
<link>https://coderlegion.com/19072/surrealdb-the-one-size-fits-all-database-for-lazy-developers-part-1</link>
<description>&lt;p&gt;&lt;em&gt;Intro: &lt;/em&gt; We need to talk about your &quot;Modern Stack&quot;&lt;br&gt;
Let’s be real for a second. We’ve all been there: You have a &quot;simple&quot; project idea. Two hours later, you’re staring at a Docker Compose file with PostgreSQL, Redis for caching, Neo4j because &quot;graphs are cool,&quot; and a Node.js backend just to move JSON from A to B.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why are we doing this to ourselves?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I’m a medior dev. I’ve reached the point in my career where I’m too tired to write the same CRUD boilerplate for the 100th time. I just want to build things that work. And that’s when I stumbled upon &lt;strong&gt;SurrealDB&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is SurrealDB? (Besides a cool name)&lt;/strong&gt;&lt;br&gt;
Imagine if SQL, MongoDB, and GraphQL had a baby, and then that baby was raised by Firebase but grew up to be actually flexible.&lt;/p&gt;
&lt;p&gt;SurrealDB is a multi-model database. It doesn't care if you want documents, relational tables, or complex graph structures. It just says: &quot;Sure, why not both?&quot;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why you (as a lazy dev) should care:&lt;/strong&gt;&lt;br&gt;
The &quot;Backend Killer&quot; (No, seriously): SurrealDB has built-in Row-Level Security (RLS) and authentication. You can connect your frontend (React, Vue, whatever) directly to the database. No more writing 500 lines of Express.js just to check if user_id === owner_id.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Schema-Flexible (The &quot;I'll decide later&quot; feature):&lt;/strong&gt;&lt;br&gt;
You can start schema-less (just dump data) and then enforce a schema once you actually know what you're building. It's perfect for prototyping without the &quot;oops, I forgot a migration&quot; headache.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Graph Relations without the PhD: &lt;/em&gt;&lt;br&gt;
Remember trying to write a recursive CTE in SQL to find &quot;friends of friends&quot;? In SurrealDB, it's literally just an arrow: SELECT -&amp;gt;knows-&amp;gt;person FROM user:me. My brain thanked me.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A Quick Reality Check&lt;/strong&gt;&lt;br&gt;
Is it magic? Almost. Is it perfect? Well, it's still evolving. But if you're building a startup or a side project and you're a &quot;team of one,&quot; using a traditional stack is like bringing a tank to a knife fight. It’s overkill and you’ll probably hurt yourself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What’s next?&lt;/strong&gt;&lt;br&gt;
In the next part of this mini-series, I’m going to show you how I deleted 70% of my backend code using SurrealDB’s auth layer.&lt;/p&gt;
&lt;p&gt;Spoiler: It felt amazing.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/19072/surrealdb-the-one-size-fits-all-database-for-lazy-developers-part-1</guid>
<pubDate>Wed, 27 May 2026 17:11:00 +0000</pubDate>
</item>
<item>
<title>Oracle Database 23ai: Vector Similarity Search - Exact, Approximate, and Multi-Vector Strategies</title>
<link>https://coderlegion.com/12918/oracle-database-23ai-vector-similarity-search-exact-approximate-multi-vector-strategies</link>
<description>&lt;p&gt;Oracle Database 23ai's AI Vector Search provides multiple strategies for finding similar vectors, each with different trade-offs between accuracy, speed, and resource usage. Understanding when to use exact search, approximate search, or multi-vector search—and knowing the essential vector functions—is crucial for building high-performance semantic search applications.&lt;/p&gt;
&lt;h3 id=&quot;understanding-similarity-search-types&quot;&gt;Understanding Similarity Search Types&lt;/h3&gt;
&lt;h4 id=&quot;1-exact-similarity-search-flat-search-&quot;&gt;1. Exact Similarity Search (Flat Search)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Exact similarity search calculates a query vector's distance to all other vectors&lt;/strong&gt;. It's also called flat search or exhaustive search because every vector in the dataset is compared.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Gives the most accurate results&lt;/li&gt;
&lt;li&gt;Perfect search quality (100% recall)&lt;/li&gt;
&lt;li&gt;Involves potentially significant time as dataset grows&lt;/li&gt;
&lt;li&gt;No indexes required&lt;/li&gt;
&lt;li&gt;Suitable for small to medium datasets (thousands to hundreds of thousands of vectors)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  product_id,
  product_name,
  VECTOR_DISTANCE(embedding, :query_vector, COSINE) AS similarity
FROM products
ORDER BY similarity
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;When to Use:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Small datasets where performance is acceptable&lt;/li&gt;
&lt;li&gt;When perfect accuracy is required&lt;/li&gt;
&lt;li&gt;Development and testing phases&lt;/li&gt;
&lt;li&gt;Benchmarking approximate search results&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-approximate-similarity-search&quot;&gt;2. Approximate Similarity Search&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Approximate similarity search uses vector indexes&lt;/strong&gt; to dramatically speed up searches with minimal accuracy loss. Instead of checking every vector, it leverages specialized data structures to narrow the search space.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You must enable vector pool in the SGA&lt;/strong&gt; for HNSW indexes (in-memory neighbor graph indexes).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER SYSTEM SET vector_memory_size = 800M SCOPE=SPFILE;
-- Restart required
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Can be more efficient but less accurate than exact search&lt;/li&gt;
&lt;li&gt;Uses target accuracy setting (typically 90-99%)&lt;/li&gt;
&lt;li&gt;Requires vector indexes (HNSW or IVF)&lt;/li&gt;
&lt;li&gt;Scales to millions or billions of vectors&lt;/li&gt;
&lt;li&gt;Typical accuracy: 95%+ with proper configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Using FETCH APPROXIMATE
SELECT 
  product_id,
  product_name
FROM products
ORDER BY embedding less-than equals greater-than :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Performance Comparison:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;According to Oracle benchmarks, exact search on 50,000 vectors took 1.50 seconds versus 0.47 seconds with HNSW index—over 3x faster with the same top-10 results.&lt;/p&gt;
&lt;h4 id=&quot;vector-index-types&quot;&gt;Vector Index Types&lt;/h4&gt;
&lt;p&gt;Oracle AI Vector Search supports two main types of vector indexes:&lt;/p&gt;
&lt;h5 id=&quot;hnsw-hierarchical-navigable-small-world-&quot;&gt;HNSW (Hierarchical Navigable Small World)&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;In-Memory Neighbor Graph&lt;/strong&gt; vector index that creates a navigable graph structure for ultra-fast similarity search.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Creating HNSW Index:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX products_hnsw_idx
ON products(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fully built in-memory in the vector pool&lt;/li&gt;
&lt;li&gt;Extremely fast queries (sub-100ms)&lt;/li&gt;
&lt;li&gt;Requires substantial memory&lt;/li&gt;
&lt;li&gt;No DML operations allowed after creation&lt;/li&gt;
&lt;li&gt;Not available in RAC environments&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Memory Calculation:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Formula: &lt;code&gt;1.3 times number_of_vectors times number_of_dimensions times dimension_byte_size&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Example for 1M vectors, 768 dimensions, FLOAT32 (4 bytes):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1.3 × 1,000,000 × 768 × 4 = 3.99 GB
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;ivf-inverted-file-flat-&quot;&gt;IVF (Inverted File Flat)&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;Neighbor Partition&lt;/strong&gt; vector index built on disk with blocks cached in the buffer cache.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Creating IVF Index:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX products_ivf_idx
ON products(embedding)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Disk-based, blocks cached in buffer cache&lt;/li&gt;
&lt;li&gt;More scalable for very large datasets&lt;/li&gt;
&lt;li&gt;Supports DML operations (may require periodic rebuild)&lt;/li&gt;
&lt;li&gt;Works in RAC environments&lt;/li&gt;
&lt;li&gt;Slightly slower than HNSW but still very fast&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;How IVF Works:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The index partitions vectors into clusters based on similarity. By default, the number of partitions equals the square root of the dataset size. During search, only relevant clusters are examined.&lt;/p&gt;
&lt;h4 id=&quot;3-multi-vector-similarity-search&quot;&gt;3. Multi-Vector Similarity Search&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Multi-vector similarity search is usually used for multi-document search&lt;/strong&gt; where documents are split into chunks, and chunks are embedded individually into vectors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Long documents split into paragraphs or sections&lt;/li&gt;
&lt;li&gt;Product catalogs with multiple descriptions&lt;/li&gt;
&lt;li&gt;Research papers chunked for semantic search&lt;/li&gt;
&lt;li&gt;Multi-modal data (text + images)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Documents are split into chunks&lt;/li&gt;
&lt;li&gt;Each chunk is embedded individually into a separate vector&lt;/li&gt;
&lt;li&gt;Chunks are stored with partition keys linking them to parent documents&lt;/li&gt;
&lt;li&gt;Search retrieves top chunks across all documents&lt;/li&gt;
&lt;li&gt;Results can be aggregated by document&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Uses partitions&lt;/strong&gt; to organize chunks belonging to the same document.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Table Structure Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE document_chunks (
  doc_id NUMBER,
  chunk_id NUMBER,
  chunk_text CLOB,
  embedding VECTOR(768, FLOAT32),
  PRIMARY KEY (doc_id, chunk_id)
) PARTITION BY RANGE (doc_id) (
  PARTITION p1 VALUES LESS THAN (1000),
  PARTITION p2 VALUES LESS THAN (2000),
  PARTITION p3 VALUES LESS THAN (MAXVALUE)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Multi-Vector Search Query:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Find top chunks across all documents
SELECT 
  doc_id,
  chunk_id,
  chunk_text,
  VECTOR_DISTANCE(embedding, :query_vector, COSINE) AS score
FROM document_chunks
ORDER BY score
FETCH APPROXIMATE FIRST 20 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Aggregating by Document:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Get top documents based on best chunk match
SELECT 
  doc_id,
  MIN(VECTOR_DISTANCE(embedding, :query_vector, COSINE)) AS best_score
FROM document_chunks
GROUP BY doc_id
ORDER BY best_score
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;narrowing-search-results&quot;&gt;Narrowing Search Results&lt;/h3&gt;
&lt;h4 id=&quot;attribute-filtering-with-where-clause&quot;&gt;Attribute Filtering with WHERE Clause&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Use the WHERE clause to filter results based on metadata or business attributes. You are not limited by the use of the ORDER BY clause.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This powerful combination enables hybrid search: semantic similarity (vector search) plus exact filters (traditional SQL).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example: Filter by Category and Date&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  product_id,
  product_name,
  category,
  COSINE_DISTANCE(embedding, :query_vector) AS similarity
FROM products
WHERE category = 'Electronics'
  AND launch_date greater-than DATE '2024-01-01'
ORDER BY embedding less-than equals greater-than :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Example: Price Range Filter&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  product_id,
  product_name,
  price,
  L2_DISTANCE(embedding, :query_vector) AS distance
FROM products
WHERE price BETWEEN 100 AND 500
  AND in_stock = 'Y'
ORDER BY embedding less-than hyphen greater-than :query_vector
FETCH APPROXIMATE FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Best Practices for Filtering:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Apply filters in WHERE clause before vector search&lt;/li&gt;
&lt;li&gt;Use indexed columns for better performance&lt;/li&gt;
&lt;li&gt;Combine multiple conditions as needed&lt;/li&gt;
&lt;li&gt;Leverage partition pruning for partitioned tables&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;testing-other-distance-functions&quot;&gt;Testing Other Distance Functions&lt;/h3&gt;
&lt;p&gt;Oracle provides shorthand distance functions that simplify syntax and improve code readability.&lt;/p&gt;
&lt;h4 id=&quot;distance-function-equivalents&quot;&gt;Distance Function Equivalents&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;L1_DISTANCE(v1, v2)&lt;/strong&gt; is similar to Manhattan distance&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT L1_DISTANCE(
  VECTOR('[1, 2, 3]'),
  VECTOR('[4, 5, 6]')
) AS manhattan_dist
FROM DUAL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;L2_DISTANCE(v1, v2)&lt;/strong&gt; is similar to Euclidean distance&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT L2_DISTANCE(
  VECTOR('[3, 0]'),
  VECTOR('[0, 4]')
) AS euclidean_dist
FROM DUAL;
-- Result: 5.0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;COSINE_DISTANCE&lt;/strong&gt; is the same as cosine&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT COSINE_DISTANCE(
  VECTOR('[1, 0]'),
  VECTOR('[1, 1]')
) AS cosine_dist
FROM DUAL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;INNER_PRODUCT(v1, v2)&lt;/strong&gt; is the same as dot product&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT INNER_PRODUCT(
  VECTOR('[2, 3]'),
  VECTOR('[4, 5]')
) AS dot_product
FROM DUAL;
-- Result: 2*4 + 3*5 = 23
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note on DOT vs INNER_PRODUCT:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;VECTOR_DISTANCE&lt;/code&gt; function with DOT metric returns the &lt;strong&gt;negated&lt;/strong&gt; inner product, while the &lt;code&gt;INNER_PRODUCT&lt;/code&gt; function returns the actual dot product.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- These are NOT equivalent:
SELECT VECTOR_DISTANCE(v1, v2, DOT) FROM table;     -- Returns -1 * dot_product
SELECT INNER_PRODUCT(v1, v2) FROM table;             -- Returns dot_product
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;other-essential-vector-functions&quot;&gt;Other Essential Vector Functions&lt;/h3&gt;
&lt;h4 id=&quot;1-vector-constructors&quot;&gt;1. Vector Constructors&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;TO_VECTOR()&lt;/strong&gt; converts a string or a character large object (CLOB) to a vector&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- From string
SELECT TO_VECTOR('[1.5, 2.3, 4.1]') AS vec FROM DUAL;

-- From CLOB
DECLARE
  my_clob CLOB := '[0.1, 0.2, 0.3, 0.4]';
  my_vector VECTOR;
BEGIN
  my_vector := TO_VECTOR(my_clob);
END;
/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;TO_VECTOR also takes another vector as input, adjusts its format, and returns the adjusted vector as output.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;VECTOR()&lt;/strong&gt; converts a string or CLOB into a vector&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR('[1, 2, 3]', 3, FLOAT32) AS vec FROM DUAL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;TO_VECTOR and VECTOR are synonymous&lt;/strong&gt;—they perform the same function.&lt;/p&gt;
&lt;h4 id=&quot;2-vector-serializer&quot;&gt;2. Vector Serializer&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;VECTOR_SERIALIZE()&lt;/strong&gt; converts a vector into a string or a CLOB&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_SERIALIZE(embedding) AS vec_string
FROM products
WHERE product_id = 1;

-- Result: '[0.12, 0.45, 0.78, ...]'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Exporting vectors for external processing&lt;/li&gt;
&lt;li&gt;Debugging and inspection&lt;/li&gt;
&lt;li&gt;Logging and auditing&lt;/li&gt;
&lt;li&gt;Integration with non-Oracle systems&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-vector-norm&quot;&gt;3. Vector Norm&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;VECTOR_NORM()&lt;/strong&gt; returns the Euclidean norm of a vector—the distance from the origin to the vector.&lt;/p&gt;
&lt;p&gt;Also known as magnitude or length, it's calculated as the square root of the sum of squared components.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;norm = square_root(x1-squared + x2-squared + ... + xn-squared)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_NORM(TO_VECTOR('[3, 4]')) AS magnitude
FROM DUAL;
-- Result: 5.0 (because square_root(9+16) = 5)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Practical Use: Normalizing Vectors&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Normalize vector to unit length
SELECT 
  embedding / VECTOR_NORM(embedding) AS normalized_vector
FROM products
WHERE product_id = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Normalized vectors have a magnitude of 1.0, which is required for meaningful dot product similarity comparisons.&lt;/p&gt;
&lt;h4 id=&quot;4-vector-dimension-count&quot;&gt;4. Vector Dimension Count&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;VECTOR_DIMENSION_COUNT()&lt;/strong&gt; returns the number of dimensions of a vector&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_DIMENSION_COUNT(embedding) AS dimensions
FROM products
WHERE product_id = 1;

-- Result: 768 (for BERT-style embeddings)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Validating embedding dimensions&lt;/li&gt;
&lt;li&gt;Debugging dimension mismatches&lt;/li&gt;
&lt;li&gt;Dynamic schema inspection&lt;/li&gt;
&lt;li&gt;Migration validation&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;5-vector-dimension-format&quot;&gt;5. Vector Dimension Format&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;VECTOR_DIMENSION_FORMAT()&lt;/strong&gt; returns the storage format of the vector&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_DIMENSION_FORMAT(embedding) AS format
FROM products
WHERE product_id = 1;

-- Possible results: 'INT8', 'FLOAT32', 'FLOAT64', 'BINARY'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Schema documentation&lt;/li&gt;
&lt;li&gt;Storage optimization analysis&lt;/li&gt;
&lt;li&gt;Migration planning&lt;/li&gt;
&lt;li&gt;Model compatibility verification&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;complete-working-example&quot;&gt;Complete Working Example&lt;/h3&gt;
&lt;p&gt;Here's a comprehensive example demonstrating all three search types:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Create table
CREATE TABLE research_papers (
  paper_id NUMBER PRIMARY KEY,
  title VARCHAR2(500),
  abstract CLOB,
  category VARCHAR2(100),
  publish_date DATE,
  embedding VECTOR(768, FLOAT32)
);

-- Insert sample data
INSERT INTO research_papers VALUES (
  1,
  'Advances in Vector Search',
  'This paper explores efficient algorithms...',
  'Computer Science',
  DATE '2024-06-15',
  VECTOR('[0.1, 0.2, ...]', 768, FLOAT32)
);
COMMIT;

-- 1. EXACT SIMILARITY SEARCH
-- Most accurate, slower for large datasets
SELECT 
  paper_id,
  title,
  COSINE_DISTANCE(embedding, :query_vector) AS similarity
FROM research_papers
WHERE category = 'Computer Science'
ORDER BY similarity
FETCH FIRST 10 ROWS ONLY;

-- 2. CREATE VECTOR INDEX for approximate search
CREATE VECTOR INDEX papers_hnsw_idx
ON research_papers(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- 3. APPROXIMATE SIMILARITY SEARCH
-- Faster, 95%+ accuracy
SELECT 
  paper_id,
  title,
  publish_date
FROM research_papers
WHERE category = 'Computer Science'
  AND publish_date greater-than DATE '2024-01-01'
ORDER BY embedding less-than equals greater-than :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;

-- 4. MULTI-VECTOR SEARCH (for chunked documents)
-- Create chunked version
CREATE TABLE paper_chunks (
  paper_id NUMBER,
  chunk_id NUMBER,
  chunk_text CLOB,
  embedding VECTOR(768, FLOAT32),
  PRIMARY KEY (paper_id, chunk_id)
);

-- Find best matching chunks
SELECT 
  paper_id,
  chunk_id,
  L2_DISTANCE(embedding, :query_vector) AS distance
FROM paper_chunks
ORDER BY distance
FETCH APPROXIMATE FIRST 20 ROWS ONLY;

-- Aggregate to document level
SELECT 
  p.paper_id,
  p.title,
  MIN(COSINE_DISTANCE(c.embedding, :query_vector)) AS best_match_score
FROM research_papers p
JOIN paper_chunks c ON p.paper_id = c.paper_id
GROUP BY p.paper_id, p.title
ORDER BY best_match_score
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;best-practices&quot;&gt;Best Practices&lt;/h3&gt;
&lt;h4 id=&quot;1-choose-the-right-search-strategy&quot;&gt;1. Choose the Right Search Strategy&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Exact search&lt;/strong&gt;: Less than 100K vectors, need perfect accuracy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Approximate with HNSW&lt;/strong&gt;: 100K to 10M vectors, need sub-100ms latency, have memory available&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Approximate with IVF&lt;/strong&gt;: 10M+ vectors, limited memory, can tolerate slightly higher latency&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-vector&lt;/strong&gt;: Document chunks, multi-modal data, detailed granularity needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-optimize-index-configuration&quot;&gt;2. Optimize Index Configuration&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- For high accuracy (slower but better results)
CREATE VECTOR INDEX idx1 ON table(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 99;

-- For speed (faster but slightly lower accuracy)
CREATE VECTOR INDEX idx2 ON table(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 90;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-use-attribute-filtering-effectively&quot;&gt;3. Use Attribute Filtering Effectively&lt;/h4&gt;
&lt;p&gt;Combine vector similarity with traditional filters to narrow results:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Efficient: Filter first, then search
SELECT * FROM products
WHERE price less-than 100              -- Traditional filter
  AND category = 'Electronics'         -- Traditional filter
ORDER BY embedding less-than equals greater-than :query_vector  -- Vector search
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;4-monitor-and-tune-performance&quot;&gt;4. Monitor and Tune Performance&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Check if index is being used
EXPLAIN PLAN FOR
SELECT * FROM products
ORDER BY embedding less-than equals greater-than :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;5-handle-dimension-mismatches&quot;&gt;5. Handle Dimension Mismatches&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Validate dimensions before comparison
SELECT 
  VECTOR_DIMENSION_COUNT(embedding) AS dims,
  VECTOR_DIMENSION_FORMAT(embedding) AS format
FROM products
WHERE VECTOR_DIMENSION_COUNT(embedding) != 768;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;common-pitfalls-and-solutions&quot;&gt;Common Pitfalls and Solutions&lt;/h3&gt;
&lt;h4 id=&quot;pitfall-1-forgetting-to-enable-vector-pool&quot;&gt;Pitfall 1: Forgetting to Enable Vector Pool&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; HNSW index creation fails with memory error&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Configure vector pool before creating HNSW indexes&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER SYSTEM SET vector_memory_size = 1G SCOPE=SPFILE;
-- Restart database
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;pitfall-2-using-wrong-index-type&quot;&gt;Pitfall 2: Using Wrong Index Type&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Slow performance despite having an index&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Match your workload to index type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;HNSW for read-heavy, memory-available scenarios&lt;/li&gt;
&lt;li&gt;IVF for write-heavy or memory-constrained scenarios&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;pitfall-3-metric-mismatch&quot;&gt;Pitfall 3: Metric Mismatch&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Index not being used despite proper syntax&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Ensure query metric matches index metric&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Index uses COSINE
CREATE VECTOR INDEX idx ON table(embedding)
DISTANCE COSINE;

-- Query must also use COSINE
-- Correct: Uses less-than equals greater-than (COSINE operator)
ORDER BY embedding less-than equals greater-than :query_vector

-- Wrong: Uses less-than hyphen greater-than (EUCLIDEAN operator)
-- This will NOT use the index!
ORDER BY embedding less-than hyphen greater-than :query_vector
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;pitfall-4-not-using-fetch-approximate&quot;&gt;Pitfall 4: Not Using FETCH APPROXIMATE&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Query is slow despite having vector index&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Use &lt;code&gt;FETCH APPROXIMATE&lt;/code&gt; to enable index usage&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Without APPROXIMATE - performs exact search
FETCH FIRST 10 ROWS ONLY;

-- With APPROXIMATE - uses index
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oracle Database 23ai provides a comprehensive vector search framework with multiple strategies to fit different use cases:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Search Strategies:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Exact&lt;/strong&gt;: Perfect accuracy, suitable for smaller datasets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Approximate&lt;/strong&gt;: 95%+ accuracy with dramatic speed improvements using HNSW or IVF indexes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-vector&lt;/strong&gt;: Chunk-level granularity for document search&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Key Requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enable vector pool for HNSW indexes: &lt;code&gt;vector_memory_size&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use FETCH APPROXIMATE for index-accelerated queries&lt;/li&gt;
&lt;li&gt;Match distance metrics between index and query&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Essential Functions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Constructors&lt;/strong&gt;: TO_VECTOR(), VECTOR()&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Serializer&lt;/strong&gt;: VECTOR_SERIALIZE()&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Utilities&lt;/strong&gt;: VECTOR_NORM(), VECTOR_DIMENSION_COUNT(), VECTOR_DIMENSION_FORMAT()&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distance Functions&lt;/strong&gt;: L1_DISTANCE(), L2_DISTANCE(), COSINE_DISTANCE(), INNER_PRODUCT()&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Choose search strategy based on dataset size and accuracy requirements&lt;/li&gt;
&lt;li&gt;Combine vector search with WHERE clause filters for powerful hybrid queries&lt;/li&gt;
&lt;li&gt;Monitor index usage with EXPLAIN PLAN&lt;/li&gt;
&lt;li&gt;Normalize vectors when using dot product similarity&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By understanding these search strategies and vector functions, you can build high-performance semantic search applications that scale from thousands to billions of vectors while maintaining excellent accuracy and query speed.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/12918/oracle-database-23ai-vector-similarity-search-exact-approximate-multi-vector-strategies</guid>
<pubDate>Mon, 16 Mar 2026 08:59:34 +0000</pubDate>
</item>
<item>
<title>Oracle Database 23ai: Creating Vectors and Understanding Distance Metrics for Similarity Search</title>
<link>https://coderlegion.com/12484/oracle-database-23ai-creating-vectors-understanding-distance-metrics-similarity-search</link>
<description>&lt;p&gt;Oracle Database 23ai introduces native vector capabilities that enable semantic search directly within SQL. Understanding how to create vectors, calculate distances, and choose appropriate metrics is fundamental to building effective AI-powered applications. This comprehensive guide explores vector operations in Oracle 23ai with practical examples and best practices.&lt;/p&gt;
&lt;h3 id=&quot;the-vector-data-type&quot;&gt;The VECTOR Data Type&lt;/h3&gt;
&lt;p&gt;Oracle 23ai introduces a native VECTOR data type designed specifically to store and manage vector embeddings efficiently within the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Declaration Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Flexible: any dimensions and format
embedding VECTOR

-- Specific dimensions, flexible format
embedding VECTOR(512)

-- Fully specified: dimensions and format
embedding VECTOR(512, FLOAT32)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Format Options:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;INT8&lt;/strong&gt;: 8-bit integers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT32&lt;/strong&gt;: 32-bit floating-point (IEEE standard, most common)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT64&lt;/strong&gt;: 64-bit floating-point (IEEE standard, higher precision)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BINARY&lt;/strong&gt;: Binary vectors for specialized use cases&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Oracle Database automatically casts values if needed between formats.&lt;/p&gt;
&lt;h3 id=&quot;creating-vectors-with-the-vector-constructor&quot;&gt;Creating Vectors with the VECTOR Constructor&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;VECTOR constructor is a function that allows us to create vectors without storing them&lt;/strong&gt;. It's particularly useful for learning purposes, testing, and ad-hoc queries.&lt;/p&gt;
&lt;h4 id=&quot;basic-syntax&quot;&gt;Basic Syntax&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;VECTOR(array_literal [, number_of_dimensions] [, format])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;array_literal&lt;/strong&gt;: String representation of vector values&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;number_of_dimensions&lt;/strong&gt;: Optional, inferred from array if not specified&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;format&lt;/strong&gt;: Optional (INT8, FLOAT32, FLOAT64, BINARY)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;examples&quot;&gt;Examples&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Simple 2D Vector:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR('[0, 0]');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[0, 0]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vector with Scientific Notation:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR('[10, 0]');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt; &lt;code&gt;[1.0E+001, 0]&lt;/code&gt; (equivalent to [10, 0])&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Specifying Dimensions:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR('[1, 2, 3]', 3, FLOAT32);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Creating Vectors from Variables:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;DECLARE
  my_vector VECTOR;
BEGIN
  my_vector := VECTOR('[0.5, 0.8, 0.2]');
  DBMS_OUTPUT.PUT_LINE(my_vector);
END;
/
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;best-practices-for-learning&quot;&gt;Best Practices for Learning&lt;/h4&gt;
&lt;p&gt;Use small number of dimensions (2-4) when learning vector concepts, as they're easier to visualize and understand. For production, match the dimensions to your embedding model (typically 384-1536).&lt;/p&gt;
&lt;h3 id=&quot;the-vector-distance-function&quot;&gt;The VECTOR_DISTANCE Function&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;VECTOR_DISTANCE is the main function for calculating distance between two vectors&lt;/strong&gt;. It allows you to calculate distance between two parameters and therefore takes 2 vectors as params.&lt;/p&gt;
&lt;h4 id=&quot;syntax&quot;&gt;Syntax&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;VECTOR_DISTANCE(expr1, expr2 [, distance_metric])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;expr1, expr2&lt;/strong&gt;: Two vector expressions to compare&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;distance_metric&lt;/strong&gt;: Optional; defaults to COSINE (or HAMMING for BINARY vectors)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Returns:&lt;/strong&gt; BINARY_DOUBLE representing the distance&lt;/p&gt;
&lt;h4 id=&quot;default-behavior&quot;&gt;Default Behavior&lt;/h4&gt;
&lt;p&gt;If you do not specify a distance metric, then the default distance metric is cosine. If the input vectors are BINARY vectors, the default metric is hamming.&lt;/p&gt;
&lt;h4 id=&quot;basic-example&quot;&gt;Basic Example&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[1, 0]'),
    VECTOR('[0, 1]'),
    COSINE
  ) AS distance;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;vector-distance-metrics-choosing-the-right-one&quot;&gt;Vector Distance Metrics: Choosing the Right One&lt;/h3&gt;
&lt;p&gt;Oracle AI Vector Search supports multiple distance metrics, each suited for different use cases and data characteristics.&lt;/p&gt;
&lt;h4 id=&quot;1-euclidean-distance-l2-&quot;&gt;1. Euclidean Distance (L2)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Euclidean distance gives us the straight-line distance between two vectors. It uses the Pythagorean theorem and is sensitive to both vector size and direction.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;d = square_root[(x2-x1)squared + (y2-y1)squared]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT TO_NUMBER(
  VECTOR_DISTANCE(
    VECTOR('[3, 0]'),
    VECTOR('[0, 4]'),
    EUCLIDEAN
  )
) AS distance;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; &lt;code&gt;5&lt;/code&gt; (forming a 3-4-5 right triangle)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Spatial data and geographical coordinates&lt;/li&gt;
&lt;li&gt;Physical measurements&lt;/li&gt;
&lt;li&gt;Image similarity (pixel-level comparisons)&lt;/li&gt;
&lt;li&gt;When absolute distance matters&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-euclidean-squared-distance-l2-squared-&quot;&gt;2. Euclidean Squared Distance (L2_SQUARED)&lt;/h4&gt;
&lt;p&gt;The Euclidean distance without taking the square root. When ordering is more important than the actual distance values, squared Euclidean distance is very useful as it's faster to calculate, avoiding the square root computation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Advantage:&lt;/strong&gt; Faster computation for ranking/sorting&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT TO_NUMBER(
  VECTOR_DISTANCE(
    VECTOR('[3, 0]'),
    VECTOR('[0, 4]'),
    EUCLIDEAN_SQUARED
  )
) AS distance_squared;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; &lt;code&gt;25&lt;/code&gt; (5 squared)&lt;/p&gt;
&lt;h4 id=&quot;3-cosine-similarity-cosine-distance&quot;&gt;3. Cosine Similarity / Cosine Distance&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Cosine similarity is the most widely used similarity metric, especially in natural language processing (NLP). The smaller the angle, the more similar the vectors are.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Cosine measures the angle between two vectors rather than their magnitude. It's ideal for text embeddings where direction matters more than magnitude.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cosine_similarity = (A dot B) / (magnitude_A times magnitude_B)
cosine_distance = 1 - cosine_similarity
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[1, 0]'),
    VECTOR('[1, 1]'),
    COSINE
  ) AS cosine_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Key Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Range:&lt;/strong&gt; 0 (identical) to 2 (opposite)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Normalized:&lt;/strong&gt; Insensitive to vector magnitude&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Best for:&lt;/strong&gt; Text embeddings, document similarity, semantic search&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Why It's Popular:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Cosine is one of the most useful metrics since it measures the angle between two vectors instead of the difference in size or position. This makes it perfect for comparing text embeddings where the semantic meaning is encoded in direction, not magnitude.&lt;/p&gt;
&lt;h4 id=&quot;4-dot-product-similarity&quot;&gt;4. Dot Product Similarity&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Dot product allows us to multiply the size of each vector by the cosine of their angle. It is equivalent to the sum of the vectors' coordinates. Larger values mean more similar; smaller values mean less similar.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;dot_product = sum(ai times bi)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Oracle's DOT metric calculates the &lt;strong&gt;negated&lt;/strong&gt; dot product, so more negative values indicate greater similarity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[2, 3]'),
    VECTOR('[4, 5]'),
    DOT
  ) AS dot_distance;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Recommendation systems&lt;/li&gt;
&lt;li&gt;Similarity ranking with normalized vectors&lt;/li&gt;
&lt;li&gt;Fast approximate nearest neighbor search&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; For meaningful results, vectors should be normalized to unit length.&lt;/p&gt;
&lt;h4 id=&quot;5-manhattan-distance-l1-&quot;&gt;5. Manhattan Distance (L1)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Manhattan distance is useful for describing uniform grids. It's useful for city blocks, power grids, chessboards, and is faster than Euclidean metrics.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Also known as taxicab distance or L1 distance, it calculates the sum of absolute differences between vector components.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;manhattan = sum of absolute(ai - bi)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[1, 2]'),
    VECTOR('[4, 6]'),
    MANHATTAN
  ) AS manhattan_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; &lt;code&gt;absolute(4-1) + absolute(6-2) = 7&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grid-based problems&lt;/li&gt;
&lt;li&gt;Route planning on city streets&lt;/li&gt;
&lt;li&gt;Feature selection in machine learning&lt;/li&gt;
&lt;li&gt;When diagonal movement isn't allowed&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;6-hamming-distance&quot;&gt;6. Hamming Distance&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hamming distance describes where vector dimensions differ. They are binary vectors and tell us the number of bits that require change to match.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hamming distance computes the position of each bit in the sequence and is used for network error detection and correction.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[1, 0, 1, 1, 0]', 5, BINARY),
    VECTOR('[1, 1, 1, 0, 0]', 5, BINARY),
    HAMMING
  ) AS hamming_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; &lt;code&gt;2&lt;/code&gt; (positions 2 and 4 differ)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Error detection and correction&lt;/li&gt;
&lt;li&gt;Genetic sequence comparison&lt;/li&gt;
&lt;li&gt;Digital communication&lt;/li&gt;
&lt;li&gt;Binary classification problems&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;7-jaccard-distance&quot;&gt;7. Jaccard Distance&lt;/h4&gt;
&lt;p&gt;Jaccard distance measures dissimilarity between binary vectors based on the ratio of intersection to union.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Requirements:&lt;/strong&gt; Both vectors must be BINARY&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Formula:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;jaccard = 1 - (size_of_intersection / size_of_union)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SQL Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  VECTOR_DISTANCE(
    VECTOR('[1, 1, 0, 1]', 4, BINARY),
    VECTOR('[1, 0, 1, 1]', 4, BINARY),
    JACCARD
  ) AS jaccard_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set similarity comparison&lt;/li&gt;
&lt;li&gt;Document deduplication&lt;/li&gt;
&lt;li&gt;Recommendation systems&lt;/li&gt;
&lt;li&gt;Clustering binary data&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;shorthand-distance-operators&quot;&gt;Shorthand Distance Operators&lt;/h3&gt;
&lt;p&gt;Oracle provides convenient shorthand operators for common distance calculations, making SQL queries more concise and readable.&lt;/p&gt;
&lt;h4 id=&quot;available-operators&quot;&gt;Available Operators&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Operator for Euclidean Distance: less-than hyphen greater-than&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT '[1, 2]' &amp;lt;-&amp;gt; '[0, 1]' AS euclidean_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Equivalent to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT L2_DISTANCE(VECTOR('[1, 2]'), VECTOR('[0, 1]')) AS euclidean_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_DISTANCE(VECTOR('[1, 2]'), VECTOR('[0, 1]'), EUCLIDEAN) AS euclidean_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Operator for Cosine Distance: less-than equals greater-than&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT '[1, 0]' &amp;lt;=&amp;gt; '[0, 1]' AS cosine_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Equivalent to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT COSINE_DISTANCE(VECTOR('[1, 0]'), VECTOR('[0, 1]')) AS cosine_dist;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Operator for Negative Dot Product: less-than hash greater-than&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT '[2, 3]' &amp;lt;#&amp;gt; '[4, 5]' AS neg_dot_product;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Equivalent to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT -1 * INNER_PRODUCT(VECTOR('[2, 3]'), VECTOR('[4, 5]')) AS neg_dot_product;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;practical-example&quot;&gt;Practical Example&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Compare products by embedding similarity
SELECT 
  p1.product_name,
  p2.product_name,
  p1.embedding &amp;lt;=&amp;gt; p2.embedding AS similarity_score
FROM products p1, products p2
WHERE p1.product_id = 100
  AND p2.product_id != 100
ORDER BY similarity_score
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;shorthand-distance-functions&quot;&gt;Shorthand Distance Functions&lt;/h3&gt;
&lt;p&gt;In addition to operators, Oracle provides shorthand functions for cleaner code:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;L1_DISTANCE&lt;/strong&gt; - Manhattan distance&lt;br&gt;
&lt;strong&gt;L2_DISTANCE&lt;/strong&gt; - Euclidean distance&lt;br&gt;
&lt;strong&gt;COSINE_DISTANCE&lt;/strong&gt; - Cosine distance&lt;br&gt;
&lt;strong&gt;INNER_PRODUCT&lt;/strong&gt; - Dot product (not negated)&lt;br&gt;
&lt;strong&gt;HAMMING_DISTANCE&lt;/strong&gt; - Hamming distance&lt;br&gt;
&lt;strong&gt;JACCARD_DISTANCE&lt;/strong&gt; - Jaccard distance&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  L2_DISTANCE(v1.embedding, v2.embedding) AS euclidean,
  COSINE_DISTANCE(v1.embedding, v2.embedding) AS cosine,
  INNER_PRODUCT(v1.embedding, v2.embedding) AS dot_prod
FROM vectors v1, vectors v2
WHERE v1.id = 1 AND v2.id = 2;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;performing-similarity-search&quot;&gt;Performing Similarity Search&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The VECTOR_DISTANCE function can be used to perform similarity search&lt;/strong&gt; by ordering results based on vector proximity.&lt;/p&gt;
&lt;h4 id=&quot;exact-similarity-search&quot;&gt;Exact Similarity Search&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  id,
  description,
  VECTOR_DISTANCE(embedding, :query_vector, COSINE) AS distance
FROM documents
ORDER BY distance
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;approximate-similarity-search-with-index-&quot;&gt;Approximate Similarity Search (with Index)&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Using FETCH APPROXIMATE with vector index
SELECT 
  id,
  description
FROM documents
ORDER BY embedding &amp;lt;=&amp;gt; :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Key Difference:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;EXACT&lt;/strong&gt;: Compares query vector with every vector (slower, 100% accurate)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;APPROXIMATE&lt;/strong&gt;: Uses vector indexes (HNSW/IVF) for fast search with approximately 95% accuracy&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;choosing-the-right-distance-metric&quot;&gt;Choosing the Right Distance Metric&lt;/h3&gt;
&lt;h4 id=&quot;decision-matrix&quot;&gt;Decision Matrix&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Use Case &lt;/th&gt;&lt;th&gt;Recommended Metric &lt;/th&gt;&lt;th&gt;Why&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Text embeddings &lt;/td&gt;&lt;td&gt;COSINE &lt;/td&gt;&lt;td&gt;Captures semantic similarity, magnitude-invariant&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Image similarity &lt;/td&gt;&lt;td&gt;EUCLIDEAN &lt;/td&gt;&lt;td&gt;Pixel-level comparisons benefit from absolute distance&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Recommendation systems &lt;/td&gt;&lt;td&gt;DOT (normalized vectors) &lt;/td&gt;&lt;td&gt;Fast computation, works well with normalized data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Grid/route problems &lt;/td&gt;&lt;td&gt;MANHATTAN &lt;/td&gt;&lt;td&gt;Natural fit for grid-based navigation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Binary classification &lt;/td&gt;&lt;td&gt;HAMMING &lt;/td&gt;&lt;td&gt;Direct bit difference counting&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Error detection &lt;/td&gt;&lt;td&gt;HAMMING &lt;/td&gt;&lt;td&gt;Counts differing positions&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Set similarity &lt;/td&gt;&lt;td&gt;JACCARD &lt;/td&gt;&lt;td&gt;Measures intersection/union ratio&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;performance-considerations&quot;&gt;Performance Considerations&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Fastest to Slowest:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;DOT (simple multiplication and sum)&lt;/li&gt;
&lt;li&gt;EUCLIDEAN_SQUARED (avoids square root)&lt;/li&gt;
&lt;li&gt;MANHATTAN (absolute values and sum)&lt;/li&gt;
&lt;li&gt;EUCLIDEAN (includes square root)&lt;/li&gt;
&lt;li&gt;COSINE (normalization overhead)&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;matching-index-and-query-metrics&quot;&gt;Matching Index and Query Metrics&lt;/h4&gt;
&lt;p&gt;If a similarity search query specifies a distance metric that conflicts with the metric in a vector index, the vector index is not used and an exact search is performed instead.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Ensure your query metric matches your index metric for optimal performance.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Index created with COSINE
CREATE VECTOR INDEX docs_idx ON documents(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- Query should also use COSINE for index usage
SELECT id FROM documents
ORDER BY embedding &amp;lt;=&amp;gt; :query_vector  -- Uses COSINE operator
FETCH APPROXIMATE FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;complete-working-example-1&quot;&gt;Complete Working Example&lt;/h3&gt;
&lt;p&gt;Here's a comprehensive example demonstrating vector creation, storage, and similarity search:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Create table with vector column
CREATE TABLE product_embeddings (
  product_id NUMBER PRIMARY KEY,
  product_name VARCHAR2(100),
  description CLOB,
  embedding VECTOR(384, FLOAT32)
);

-- Insert sample data
INSERT INTO product_embeddings VALUES (
  1,
  'Laptop Computer',
  'High-performance laptop for developers',
  VECTOR('[0.2, 0.8, 0.5, ...]', 384, FLOAT32)
);

INSERT INTO product_embeddings VALUES (
  2,
  'Wireless Mouse',
  'Ergonomic wireless mouse',
  VECTOR('[0.1, 0.3, 0.7, ...]', 384, FLOAT32)
);

COMMIT;

-- Create vector index for fast similarity search
CREATE VECTOR INDEX product_emb_idx 
ON product_embeddings(embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- Perform similarity search
DECLARE
  query_vec VECTOR;
BEGIN
  -- Create query vector (in practice, from embedding model)
  query_vec := VECTOR('[0.15, 0.75, 0.6, ...]', 384, FLOAT32);
  
  -- Find similar products
  FOR rec IN (
    SELECT 
      product_name,
      description,
      COSINE_DISTANCE(embedding, query_vec) AS similarity
    FROM product_embeddings
    ORDER BY embedding &amp;lt;=&amp;gt; query_vec
    FETCH APPROXIMATE FIRST 5 ROWS ONLY
  ) LOOP
    DBMS_OUTPUT.PUT_LINE(
      'Product: ' || rec.product_name || 
      ' | Similarity: ' || rec.similarity
    );
  END LOOP;
END;
/
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;best-practices-1&quot;&gt;Best Practices&lt;/h3&gt;
&lt;h4 id=&quot;1-choose-appropriate-dimensions&quot;&gt;1. Choose Appropriate Dimensions&lt;/h4&gt;
&lt;p&gt;Match embedding dimensions to your model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;384&lt;/strong&gt;: MiniLM, lightweight models&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;768&lt;/strong&gt;: BERT, sentence transformers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;1024&lt;/strong&gt;: Cohere embedding models&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;1536&lt;/strong&gt;: OpenAI ada-002&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-normalize-vectors-when-using-dot&quot;&gt;2. Normalize Vectors When Using DOT&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Normalize vector to unit length
SELECT 
  VECTOR_NORM(embedding) AS original_magnitude,
  embedding / VECTOR_NORM(embedding) AS normalized_vector
FROM documents
WHERE id = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-use-appropriate-formats&quot;&gt;3. Use Appropriate Formats&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FLOAT32&lt;/strong&gt;: Default, balances precision and performance&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT64&lt;/strong&gt;: When high precision is critical&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;INT8&lt;/strong&gt;: For quantized models, saves storage&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;4-monitor-index-accuracy&quot;&gt;4. Monitor Index Accuracy&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Check if index is being used
EXPLAIN PLAN FOR
SELECT id FROM documents
ORDER BY embedding &amp;lt;=&amp;gt; :query_vector
FETCH APPROXIMATE FIRST 10 ROWS ONLY;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;5-benchmark-different-metrics&quot;&gt;5. Benchmark Different Metrics&lt;/h4&gt;
&lt;p&gt;Test multiple metrics on your data to find the best performer:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Compare metrics
SELECT 
  'COSINE' AS metric,
  AVG(COSINE_DISTANCE(e1.embedding, e2.embedding)) AS avg_dist
FROM embeddings e1, embeddings e2
WHERE e1.id != e2.id
UNION ALL
SELECT 
  'EUCLIDEAN',
  AVG(L2_DISTANCE(e1.embedding, e2.embedding))
FROM embeddings e1, embeddings e2
WHERE e1.id != e2.id;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;common-pitfalls-and-solutions-1&quot;&gt;Common Pitfalls and Solutions&lt;/h3&gt;
&lt;h4 id=&quot;pitfall-1-dimension-mismatch&quot;&gt;Pitfall 1: Dimension Mismatch&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Comparing vectors with different dimensions&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- This will error
SELECT VECTOR('[1, 2]') &amp;lt;=&amp;gt; VECTOR('[1, 2, 3]');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Ensure all vectors have the same dimensions&lt;/p&gt;
&lt;h4 id=&quot;pitfall-2-wrong-metric-for-data-type&quot;&gt;Pitfall 2: Wrong Metric for Data Type&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Using JACCARD on non-binary vectors&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Use JACCARD only with BINARY vectors&lt;/p&gt;
&lt;h4 id=&quot;pitfall-3-not-using-indexes&quot;&gt;Pitfall 3: Not Using Indexes&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Slow similarity searches on large datasets&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Create appropriate vector indexes (HNSW for speed, IVF for scale)&lt;/p&gt;
&lt;h4 id=&quot;pitfall-4-metric-mismatch-with-index&quot;&gt;Pitfall 4: Metric Mismatch with Index&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Query metric conflicts with index metric, causing full table scan&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Match query metric to index metric&lt;/p&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Oracle Database 23ai's native vector capabilities provide a powerful, integrated platform for semantic search and AI-powered applications. Key takeaways:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vector Creation:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;VECTOR constructor for creating vectors directly in SQL&lt;/li&gt;
&lt;li&gt;Support for multiple formats (INT8, FLOAT32, FLOAT64, BINARY)&lt;/li&gt;
&lt;li&gt;Flexible dimension specification&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Distance Metrics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;COSINE: Default, best for text embeddings and semantic similarity&lt;/li&gt;
&lt;li&gt;EUCLIDEAN: Straight-line distance, good for spatial data&lt;/li&gt;
&lt;li&gt;DOT: Fast for normalized vectors, recommendation systems&lt;/li&gt;
&lt;li&gt;MANHATTAN: Grid-based problems, faster than Euclidean&lt;/li&gt;
&lt;li&gt;HAMMING: Binary vectors, error detection&lt;/li&gt;
&lt;li&gt;JACCARD: Set similarity with binary vectors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Shorthand Operators:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Euclidean distance operator: less-than hyphen greater-than&lt;/li&gt;
&lt;li&gt;Cosine distance operator: less-than equals greater-than&lt;/li&gt;
&lt;li&gt;Negative dot product operator: less-than hash greater-than&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Match metric to your use case and embedding model&lt;/li&gt;
&lt;li&gt;Create appropriate vector indexes&lt;/li&gt;
&lt;li&gt;Ensure metric consistency between index and queries&lt;/li&gt;
&lt;li&gt;Use approximate search for large datasets&lt;/li&gt;
&lt;li&gt;Benchmark different metrics on your data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By understanding these vector operations and distance metrics, you can build efficient, accurate similarity search applications entirely within Oracle Database 23ai.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/12484/oracle-database-23ai-creating-vectors-understanding-distance-metrics-similarity-search</guid>
<pubDate>Mon, 09 Mar 2026 08:00:00 +0000</pubDate>
</item>
<item>
<title>Oracle AI Vector Search: DML and DDL Operations on Vector Columns</title>
<link>https://coderlegion.com/12202/oracle-ai-vector-search-dml-and-ddl-operations-on-vector-columns</link>
<description>&lt;p&gt;Oracle Database 23ai introduces the VECTOR data type, enabling you to store AI embeddings alongside traditional business data. Understanding how to perform Data Manipulation Language (DML) and Data Definition Language (DDL) operations on vector columns is essential for building effective AI-powered applications. This guide covers everything you need to know about working with vector columns, including supported operations and important restrictions.&lt;/p&gt;
&lt;h3 id=&quot;understanding-the-vector-data-type&quot;&gt;Understanding the VECTOR Data Type&lt;/h3&gt;
&lt;p&gt;The VECTOR data type can store vectors with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Arbitrary number of dimensions&lt;/strong&gt;: From 1 to 65,535 dimensions (65,528 for BINARY format)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiple formats&lt;/strong&gt;: INT8, FLOAT32, FLOAT64, or BINARY&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexible or fixed specifications&lt;/strong&gt;: Can be declared with or without constraints&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Declaration Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Flexible: any dimensions and format
CREATE TABLE flexible_vectors (
    id NUMBER,
    embedding VECTOR
);

-- Fixed: specific dimensions and format
CREATE TABLE fixed_vectors (
    id NUMBER,
    embedding VECTOR(384, FLOAT32)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;dml-operations-on-vectors&quot;&gt;DML Operations on Vectors&lt;/h3&gt;
&lt;h4 id=&quot;1-insert-operations&quot;&gt;1. INSERT Operations&lt;/h4&gt;
&lt;p&gt;You can directly insert vectors into tables using several methods:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method A: Insert Using Vector Literals&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Insert vector as array literal
INSERT INTO products (product_id, name, embedding)
VALUES (1, 'Laptop', '[0.1, 0.8, 0.5, 0.3]');

-- Insert with TO_VECTOR function
INSERT INTO products (product_id, name, embedding)
VALUES (2, 'Mouse', TO_VECTOR('[0.2, 0.7, 0.4, 0.6]'));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Method B: Insert with Embedding Generation&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Generate embeddings during insert
INSERT INTO products (product_id, name, description, embedding)
VALUES (
    3,
    'Keyboard',
    'Mechanical gaming keyboard with RGB',
    VECTOR_EMBEDDING(doc_model USING 'Mechanical gaming keyboard with RGB' AS data)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Method C: Insert from Another Table&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Copy vectors from another table
INSERT INTO products_archive (product_id, name, embedding)
SELECT product_id, name, embedding
FROM products
WHERE created_date &amp;lt; ADD_MONTHS(SYSDATE, -12);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-update-operations&quot;&gt;2. UPDATE Operations&lt;/h4&gt;
&lt;p&gt;You can directly update vector columns:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Update with vector literal
UPDATE products
SET embedding = '[0.15, 0.85, 0.55, 0.35]'
WHERE product_id = 1;

-- Update using embedding generation
UPDATE products
SET embedding = VECTOR_EMBEDDING(doc_model USING description AS data)
WHERE embedding IS NULL;

-- Conditional update
UPDATE products
SET embedding = VECTOR_EMBEDDING(doc_model USING description AS data)
WHERE category = 'Electronics'
    AND embedding IS NULL;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-delete-operations&quot;&gt;3. DELETE Operations&lt;/h4&gt;
&lt;p&gt;Delete operations work normally with tables containing vector columns:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Delete specific rows
DELETE FROM products
WHERE product_id = 100;

-- Delete based on relational criteria
DELETE FROM products
WHERE created_date &amp;lt; ADD_MONTHS(SYSDATE, -24)
    AND status = 'ARCHIVED';

-- Delete all rows
DELETE FROM products;
-- or
TRUNCATE TABLE products;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;4-loading-data-using-sql-loader&quot;&gt;4. Loading Data Using SQL*Loader&lt;/h4&gt;
&lt;p&gt;SQL*Loader can load vector data from external files:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Control File Example (products.ctl):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LOAD DATA
INFILE 'products.dat'
INTO TABLE products
FIELDS TERMINATED BY ','
(
    product_id,
    product_name,
    description,
    embedding CHAR(4000)
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Data File Example (products.dat):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1,Laptop,High-performance laptop,&quot;[0.1,0.8,0.5,0.3,0.6]&quot;
2,Mouse,Wireless gaming mouse,&quot;[0.2,0.7,0.4,0.6,0.5]&quot;
3,Keyboard,Mechanical keyboard,&quot;[0.15,0.85,0.55,0.35,0.65]&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Load Command:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;sqlldr userid=username/password@db control=products.ctl log=products.log
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;5-dml-on-tables-with-hnsw-indexes&quot;&gt;5. DML on Tables with HNSW Indexes&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Important Update (23ai Release 23.6+):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In Oracle Database 23ai releases 23.4 and 23.5, DML operations were not allowed on tables with HNSW indexes. Starting with Release 23.6, this restriction has been lifted:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Transactional consistency&lt;/strong&gt;: DML modifications are now supported on tables with HNSW indexes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RAC support&lt;/strong&gt;: Guarantees transactional consistency even in Oracle RAC environments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistent results&lt;/strong&gt;: Vector search queries using HNSW indexes see transactionally consistent results based on their read snapshot&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- These operations now work with HNSW indexes (23.6+)
INSERT INTO products VALUES (101, 'New Product', '[0.1, 0.2, 0.3]');
UPDATE products SET embedding = '[0.2, 0.3, 0.4]' WHERE product_id = 101;
DELETE FROM products WHERE product_id = 101;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;vector-ddl-operations&quot;&gt;Vector DDL Operations&lt;/h3&gt;
&lt;h4 id=&quot;tables-with-multiple-vector-columns&quot;&gt;Tables with Multiple Vector Columns&lt;/h4&gt;
&lt;p&gt;Tables can have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;More than one column&lt;/strong&gt; of VECTOR data type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Different formats and dimensions&lt;/strong&gt; in different columns&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE multimedia_content (
    content_id NUMBER PRIMARY KEY,
    title VARCHAR2(500),
    description CLOB,
    -- Text embedding: 384 dimensions, FLOAT32
    text_embedding VECTOR(384, FLOAT32),
    -- Image embedding: 512 dimensions, FLOAT32
    image_embedding VECTOR(512, FLOAT32),
    -- Audio embedding: 256 dimensions, INT8
    audio_embedding VECTOR(256, INT8),
    -- Flexible dimension column
    metadata_embedding VECTOR
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;adding-vector-columns&quot;&gt;Adding Vector Columns&lt;/h4&gt;
&lt;p&gt;You can add vector columns to existing tables:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Add vector column with specific dimensions
ALTER TABLE products
ADD description_vector VECTOR(384, FLOAT32);

-- Add flexible vector column
ALTER TABLE customers
ADD preference_vector VECTOR;

-- Add with default NULL
ALTER TABLE documents
ADD content_vector VECTOR(768, FLOAT32) DEFAULT NULL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;After Adding, Populate the Column:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Generate embeddings for existing data
UPDATE products
SET description_vector = VECTOR_EMBEDDING(doc_model USING description AS data);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;dropping-vector-columns&quot;&gt;Dropping Vector Columns&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Drop a specific vector column
ALTER TABLE products
DROP COLUMN description_vector;

-- Drop multiple columns
ALTER TABLE products
DROP (description_vector, image_vector);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;dropping-tables-with-vector-columns&quot;&gt;Dropping Tables with Vector Columns&lt;/h4&gt;
&lt;p&gt;Tables containing vector columns can be dropped normally:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Drop table
DROP TABLE products;

-- Drop table with CASCADE CONSTRAINTS
DROP TABLE products CASCADE CONSTRAINTS;

-- Drop and purge from recycle bin
DROP TABLE products PURGE;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;prohibited-operations-on-vector-columns&quot;&gt;Prohibited Operations on Vector Columns&lt;/h3&gt;
&lt;p&gt;Oracle Database 23ai has specific restrictions on where and how vector columns can be used. Understanding these limitations is crucial for proper database design.&lt;/p&gt;
&lt;h4 id=&quot;1-table-and-storage-restrictions&quot;&gt;1. Table and Storage Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Cannot Define Vector Columns In:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;External Tables:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- This will fail
CREATE TABLE ext_vectors (
    id NUMBER,
    embedding VECTOR
)
ORGANIZATION EXTERNAL (...);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; As of Oracle Database 26ai, external tables CAN be created with VECTOR columns, allowing vector embeddings in text or binary format stored in external files to be rendered as the VECTOR data type. Check your database version for availability.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Index-Organized Tables (IOTs):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Cannot use as primary key
CREATE TABLE iot_vectors (
    embedding VECTOR PRIMARY KEY,  -- Not allowed
    data VARCHAR2(100)
)
ORGANIZATION INDEX;

-- Cannot use as non-key column either
CREATE TABLE iot_vectors (
    id NUMBER PRIMARY KEY,
    embedding VECTOR,  -- Not allowed
    data VARCHAR2(100)
)
ORGANIZATION INDEX;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Clusters and Cluster Tables:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Vectors cannot be part of clusters
CREATE CLUSTER vector_cluster (
    id NUMBER,
    embedding VECTOR  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Global Temporary Tables:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- This will fail
CREATE GLOBAL TEMPORARY TABLE temp_vectors (
    id NUMBER,
    embedding VECTOR  -- Not allowed
)
ON COMMIT DELETE ROWS;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Manual Segment Space Management (MSSM) Tablespaces:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Only the SYS user can create vectors as BasicFiles in MSSM tablespaces. Regular users should use Automatic Segment Space Management (ASSM) tablespaces:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Create ASSM tablespace for vectors
CREATE TABLESPACE vector_data
DATAFILE '/u01/app/oracle/oradata/vector_data01.dbf' SIZE 1G
SEGMENT SPACE MANAGEMENT AUTO;  -- Required for non-SYS users
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-partitioning-restrictions&quot;&gt;2. Partitioning Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Sub-partitioning Keys:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Vector columns cannot be sub-partition keys
CREATE TABLE sales_data (
    sale_id NUMBER,
    sale_date DATE,
    embedding VECTOR(384, FLOAT32)
)
PARTITION BY RANGE (sale_date)
SUBPARTITION BY HASH (embedding)  -- Not allowed
(...);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Vectors in Partitioned Tables (Allowed):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Vectors CAN exist in partitioned tables
CREATE TABLE sales_data (
    sale_id NUMBER,
    sale_date DATE,
    product_name VARCHAR2(200),
    embedding VECTOR(384, FLOAT32)
)
PARTITION BY RANGE (sale_date) (
    PARTITION p2023 VALUES LESS THAN (DATE '2024-01-01'),
    PARTITION p2024 VALUES LESS THAN (DATE '2025-01-01')
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-constraint-restrictions&quot;&gt;3. Constraint Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Primary Keys:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE vectors (
    embedding VECTOR PRIMARY KEY  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Foreign Keys:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE vectors (
    id NUMBER PRIMARY KEY,
    embedding VECTOR
);

CREATE TABLE related (
    id NUMBER PRIMARY KEY,
    vector_ref VECTOR REFERENCES vectors(embedding)  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Unique Constraints:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE vectors (
    id NUMBER PRIMARY KEY,
    embedding VECTOR UNIQUE  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Check Constraints:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE vectors (
    id NUMBER PRIMARY KEY,
    embedding VECTOR CHECK (embedding IS NOT NULL)  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Default Values:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE vectors (
    id NUMBER PRIMARY KEY,
    embedding VECTOR DEFAULT '[0,0,0,0]'  -- Not allowed
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;4-column-modification-restrictions&quot;&gt;4. Column Modification Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Cannot Modify Vector Column Definition:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Cannot change dimensions or format
ALTER TABLE products
MODIFY (embedding VECTOR(512, FLOAT64));  -- Not allowed

-- Cannot change to/from VECTOR type
ALTER TABLE products
MODIFY (embedding CLOB);  -- Not allowed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Workaround - Add New Column:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Instead, add a new column
ALTER TABLE products
ADD embedding_new VECTOR(512, FLOAT64);

-- Migrate data (with conversion if needed)
UPDATE products
SET embedding_new = VECTOR_EMBEDDING(model USING description AS data);

-- Drop old column
ALTER TABLE products DROP COLUMN embedding;

-- Rename new column
ALTER TABLE products RENAME COLUMN embedding_new TO embedding;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;5-index-restrictions&quot;&gt;5. Index Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Non-Vector Indexes:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Vector columns cannot be part of traditional indexes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- B-tree index
CREATE INDEX idx_embedding ON products(embedding);  -- Not allowed

-- Bitmap index
CREATE BITMAP INDEX idx_embedding ON products(embedding);  -- Not allowed

-- Reverse key index
CREATE INDEX idx_embedding ON products(embedding) REVERSE;  -- Not allowed

-- Function-based index
CREATE INDEX idx_embedding ON products(UPPER(embedding));  -- Not allowed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Vector Indexes Only:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- HNSW vector index
CREATE VECTOR INDEX idx_hnsw ON products(embedding)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- IVF vector index
CREATE VECTOR INDEX idx_ivf ON products(embedding)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;6-other-restrictions&quot;&gt;6. Other Restrictions&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Continuous Query Notification (CQN):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Vector columns are not supported in CQN queries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Comparison Operators:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Standard comparison operators cannot be used:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- These will fail
SELECT * FROM products WHERE embedding = '[0.1, 0.2]';
SELECT * FROM products WHERE embedding &amp;gt; '[0.1, 0.2]';
SELECT * FROM products WHERE embedding &amp;lt; '[0.1, 0.2]';
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Use Vector Distance Functions Instead:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Correct approach
SELECT product_name
FROM products
ORDER BY VECTOR_DISTANCE(embedding, '[0.1, 0.2, 0.3]', COSINE)
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;best-practices-for-vector-dml-and-ddl&quot;&gt;Best Practices for Vector DML and DDL&lt;/h3&gt;
&lt;h4 id=&quot;1-design-considerations&quot;&gt;1. Design Considerations&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Good: Specify dimensions and format upfront
CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    name VARCHAR2(200),
    embedding VECTOR(384, FLOAT32)  -- Clear specification
);

-- Less optimal: Flexible vectors harder to optimize
CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    name VARCHAR2(200),
    embedding VECTOR  -- May lead to performance issues
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-batch-operations&quot;&gt;2. Batch Operations&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Efficient: Batch update
UPDATE products
SET embedding = VECTOR_EMBEDDING(doc_model USING description AS data)
WHERE embedding IS NULL;

-- Less efficient: Row-by-row updates in loop
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-transaction-management&quot;&gt;3. Transaction Management&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Good practice: Commit after large operations
BEGIN
    INSERT INTO products_archive
    SELECT * FROM products WHERE created_date &amp;lt; DATE '2023-01-01';
    
    COMMIT;
END;
/
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;4-use-assm-tablespaces&quot;&gt;4. Use ASSM Tablespaces&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Create tablespace with ASSM for vector tables
CREATE TABLESPACE vector_ts
DATAFILE '/u01/oradata/vector_ts01.dbf' SIZE 10G
AUTOEXTEND ON NEXT 1G MAXSIZE UNLIMITED
SEGMENT SPACE MANAGEMENT AUTO;

-- Create table in ASSM tablespace
CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    embedding VECTOR(384, FLOAT32)
) TABLESPACE vector_ts;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;5-monitor-vector-column-usage&quot;&gt;5. Monitor Vector Column Usage&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Check vector column statistics
SELECT 
    table_name,
    column_name,
    data_type,
    nullable
FROM user_tab_columns
WHERE data_type = 'VECTOR';

-- Check table size with vectors
SELECT 
    segment_name,
    segment_type,
    bytes/1024/1024 AS size_mb
FROM user_segments
WHERE segment_name = 'PRODUCTS';
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;DML Operations Supported:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;INSERT vectors directly or with embedding generation&lt;/li&gt;
&lt;li&gt;UPDATE vector columns&lt;/li&gt;
&lt;li&gt;DELETE rows from tables with vectors&lt;/li&gt;
&lt;li&gt;Load data using SQL*Loader&lt;/li&gt;
&lt;li&gt;DML on tables with HNSW indexes (23.6+)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;DDL Operations Supported:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create tables with multiple vector columns&lt;/li&gt;
&lt;li&gt;Different formats and dimensions per column&lt;/li&gt;
&lt;li&gt;ADD vector columns to existing tables&lt;/li&gt;
&lt;li&gt;DROP vector columns&lt;/li&gt;
&lt;li&gt;DROP tables containing vectors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Key Restrictions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;External tables (except 26ai+)&lt;/li&gt;
&lt;li&gt;Index-Organized Tables (IOTs)&lt;/li&gt;
&lt;li&gt;Clusters and cluster tables&lt;/li&gt;
&lt;li&gt;Global temporary tables&lt;/li&gt;
&lt;li&gt;Sub-partitioning keys&lt;/li&gt;
&lt;li&gt;Primary keys, foreign keys, unique constraints&lt;/li&gt;
&lt;li&gt;Check constraints, default values&lt;/li&gt;
&lt;li&gt;Column modification (dimensions/format)&lt;/li&gt;
&lt;li&gt;MSSM tablespaces (non-SYS users)&lt;/li&gt;
&lt;li&gt;Non-vector indexes (B-tree, bitmap, etc.)&lt;/li&gt;
&lt;li&gt;Standard comparison operators (=, &amp;gt;, &amp;lt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding these operations and restrictions ensures you can effectively design and manage vector-enabled applications in Oracle Database 23ai, combining the power of AI embeddings with traditional relational data operations.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/12202/oracle-ai-vector-search-dml-and-ddl-operations-on-vector-columns</guid>
<pubDate>Thu, 26 Feb 2026 08:19:03 +0000</pubDate>
</item>
<item>
<title>Oracle AI Vector Search: Querying Vectors and Optimizing with Indexes</title>
<link>https://coderlegion.com/11750/oracle-ai-vector-search-querying-vectors-and-optimizing-with-indexes</link>
<description>&lt;p&gt;Oracle Database 23ai's AI Vector Search enables powerful semantic search capabilities, but to truly harness its potential, you need to understand how to query vector data efficiently and when to use vector indexes. This guide explores querying vectors and optimizing performance with specialized vector indexes.&lt;/p&gt;
&lt;h3 id=&quot;running-basic-queries-on-vectors&quot;&gt;Running Basic Queries on Vectors&lt;/h3&gt;
&lt;h4 id=&quot;combining-vector-and-relational-data&quot;&gt;Combining Vector and Relational Data&lt;/h4&gt;
&lt;p&gt;One of Oracle AI Vector Search's most powerful features is the ability to combine vector data with traditional relational data in a single query. This unified approach eliminates data fragmentation and allows you to perform semantic searches alongside business logic filters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Basic Query Pattern:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Create table with both relational and vector data
CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    product_name VARCHAR2(200),
    description CLOB,
    price NUMBER(10,2),
    category VARCHAR2(100),
    in_stock VARCHAR2(1),
    description_vector VECTOR(384, FLOAT32)
);

-- Insert sample data
INSERT INTO products VALUES (
    1001,
    'Wireless Headphones',
    'Premium noise-cancelling Bluetooth headphones with 30-hour battery life',
    299.99,
    'Electronics',
    'Y',
    VECTOR_EMBEDDING(doc_model USING 
        'Premium noise-cancelling Bluetooth headphones with 30-hour battery life' AS data)
);

-- Query combining vector similarity with relational filters
SELECT 
    product_name,
    price,
    category,
    VECTOR_DISTANCE(
        description_vector,
        VECTOR_EMBEDDING(doc_model USING 'wireless audio device' AS data),
        COSINE
    ) AS similarity_score
FROM products
WHERE price &amp;lt; 500
    AND in_stock = 'Y'
    AND category = 'Electronics'
ORDER BY similarity_score
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;selecting-vector-data&quot;&gt;Selecting Vector Data&lt;/h4&gt;
&lt;p&gt;You can select vector data using the asterisk (*) keyword just like any other column:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Select all columns including vectors
SELECT * FROM products;

-- Select specific columns including the vector
SELECT product_id, product_name, description_vector 
FROM products;

-- Vector dimensions can be extracted
SELECT 
    product_name,
    VECTOR_DIMENSION_COUNT(description_vector) AS dimensions,
    VECTOR_DIMENSION_FORMAT(description_vector) AS format
FROM products;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;important-restriction-no-comparison-operators-between-vectors&quot;&gt;Important Restriction: No Comparison Operators Between Vectors&lt;/h4&gt;
&lt;p&gt;Standard comparison operators (such as =, &amp;gt;, &amp;lt;, &amp;gt;=, &amp;lt;=, !=) are not allowed between vectors. You cannot directly compare vectors using these operators.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Invalid Operations:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- These will cause errors
SELECT * FROM products WHERE description_vector = other_vector;
SELECT * FROM products WHERE description_vector &amp;gt; other_vector;
SELECT * FROM products WHERE description_vector &amp;lt; other_vector;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt; Valid Operations:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Instead, use specialized vector distance functions:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Correct: Use VECTOR_DISTANCE function
SELECT 
    product_name,
    VECTOR_DISTANCE(description_vector, :query_vector, COSINE) AS distance
FROM products
ORDER BY distance
FETCH FIRST 5 ROWS ONLY;

-- Correct: Use shorthand operators
SELECT product_name
FROM products
ORDER BY description_vector &amp;lt;=&amp;gt; :query_vector  -- Cosine distance
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;understanding-vector-indexes&quot;&gt;Understanding Vector Indexes&lt;/h3&gt;
&lt;p&gt;Vector indexes are specialized data structures that dramatically improve query performance on vector data. Without indexes, every similarity search performs an exhaustive comparison against all vectors in the table—a process that becomes prohibitively slow as datasets grow.&lt;/p&gt;
&lt;h4 id=&quot;why-vector-indexes-matter&quot;&gt;Why Vector Indexes Matter&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Exhaustive Search&lt;/strong&gt;: Compares query vector against every vector in the table&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n) - grows linearly with dataset size&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Real Impact&lt;/strong&gt;: Searches that take seconds can become hours-long operations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt;&lt;br&gt;
Vector indexes use sophisticated techniques to reduce the search space:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Clustering&lt;/strong&gt;: Groups similar vectors together&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Partitioning&lt;/strong&gt;: Divides the vector space into manageable regions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Neighbor Graphs&lt;/strong&gt;: Creates efficient navigation paths through vector space&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The Result:&lt;/strong&gt;&lt;br&gt;
Vector indexes greatly reduce search space, making searches appear quick and extremely efficient, often reducing search time from hours to milliseconds.&lt;/p&gt;
&lt;h3 id=&quot;types-of-vector-indexes&quot;&gt;Types of Vector Indexes&lt;/h3&gt;
&lt;p&gt;Oracle AI Vector Search supports three types of vector indexes:&lt;/p&gt;
&lt;h4 id=&quot;1-in-memory-neighbor-graph-hnsw-index&quot;&gt;1. In-Memory Neighbor Graph (HNSW) Index&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;HNSW (Hierarchical Navigable Small World)&lt;/strong&gt; is a graph-based index that provides the fastest query performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In-memory only index that can require a lot of memory for large datasets&lt;/li&gt;
&lt;li&gt;Extremely fast query performance (milliseconds)&lt;/li&gt;
&lt;li&gt;Uses hierarchical layers for efficient navigation&lt;/li&gt;
&lt;li&gt;Best for datasets that fit in available memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Creating an HNSW Index:&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;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Memory Requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To roughly determine the memory size needed to store an HNSW index, use the following formula: 1.3 &lt;em&gt; number of vectors &lt;/em&gt; number of dimensions * size of your vector dimension type&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example Calculation:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1 million vectors × 384 dimensions × 4 bytes (FLOAT32) × 1.3 = ~2 GB
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-neighbor-partition-ivf-index&quot;&gt;2. Neighbor Partition (IVF) Index&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;IVF (Inverted File Flat)&lt;/strong&gt; is a storage-based index that balances search quality with reasonable speed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Storage-based index not constrained by memory like HNSW&lt;/li&gt;
&lt;li&gt;Uses buffer cache and disk storage&lt;/li&gt;
&lt;li&gt;Can be used for very large datasets and still provide excellent performance compared to exhaustive similarity search&lt;/li&gt;
&lt;li&gt;Supports global and local partitioning&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Creating an IVF Index:&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;When to Use IVF:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dataset is too large to fit in memory&lt;/li&gt;
&lt;li&gt;RAM is limited or constrained&lt;/li&gt;
&lt;li&gt;Need to support very large (billion-scale) datasets&lt;/li&gt;
&lt;li&gt;Working with partitioned tables&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-hybrid-vector-index&quot;&gt;3. Hybrid Vector Index&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Hybrid indexes&lt;/strong&gt; combine full-text search with semantic vector search in a single index.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Creating a Hybrid Index:&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;Benefits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Single index for both keyword and semantic searches&lt;/li&gt;
&lt;li&gt;Run textual queries, vector similarity queries, or hybrid queries&lt;/li&gt;
&lt;li&gt;Ideal for applications needing both search approaches&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;vector-pool-memory-configuration&quot;&gt;Vector Pool Memory Configuration&lt;/h3&gt;
&lt;p&gt;The Vector Pool is memory allocated in SGA to store Hierarchical Navigable Small World (HNSW) vector indexes and all associated metadata. Proper configuration is essential for HNSW index performance.&lt;/p&gt;
&lt;h4 id=&quot;configuring-vector-memory-size&quot;&gt;Configuring Vector Memory Size&lt;/h4&gt;
&lt;h5 id=&quot;at-cdb-container-database-level&quot;&gt;At CDB (Container Database) Level&lt;/h5&gt;
&lt;p&gt;At the CDB level, VECTOR_MEMORY_SIZE specifies the current size of the Vector Pool:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Set vector memory size at CDB level
ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 1G SCOPE=BOTH;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; A database restart is required to apply this parameter change.&lt;/p&gt;
&lt;h5 id=&quot;at-pdb-pluggable-database-level&quot;&gt;At PDB (Pluggable Database) Level&lt;/h5&gt;
&lt;p&gt;The maximum PDB VECTOR_MEMORY_SIZE value is limited to 70% of the PDB sga_target. PDBs inherit settings from the CDB but can specify their own maximum usage.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Check current SGA target
SELECT value FROM V$PARAMETER WHERE name='sga_target';

-- PDB inherits from CDB and can set maximum
-- Maximum = 70% of PDB's sga_target
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;automatic-vector-pool-growth&quot;&gt;Automatic Vector Pool Growth&lt;/h4&gt;
&lt;p&gt;Oracle 23ai supports automatic vector pool management:&lt;/p&gt;
&lt;p&gt;If VECTOR_MEMORY_SIZE is set to 1 and the sga_target is greater than 0 at CDB initialization, HNSW index creation will automatically grow the vector memory pool to satisfy the new index&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Enable automatic growth
ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 1 SCOPE=SPFILE;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;memory-considerations&quot;&gt;Memory Considerations&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Important Points:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vector indexes are stored in this pool along with vector metadata&lt;/li&gt;
&lt;li&gt;HNSW indexes require significant RAM&lt;/li&gt;
&lt;li&gt;RAM constrains the vector index size&lt;/li&gt;
&lt;li&gt;IVF indexes use buffer cache and disk, not heavily dependent on Vector Pool&lt;/li&gt;
&lt;li&gt;IVF indexes use memory either from the vector pool if defined or the shared pool to speed up index creation and during DML operations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Monitoring Vector Pool:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Check vector pool allocation and usage
SELECT 
    pool,
    alloc_bytes,
    used_bytes,
    populate_status
FROM V$VECTOR_MEMORY_POOL;

-- Check individual index memory usage
SELECT 
    owner,
    index_name,
    index_organization,
    allocated_bytes,
    used_bytes,
    num_vectors
FROM V$VECTOR_INDEX;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;choosing-the-right-index-type&quot;&gt;Choosing the Right Index Type&lt;/h3&gt;
&lt;h4 id=&quot;decision-matrix-1&quot;&gt;Decision Matrix&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Factor &lt;/th&gt;&lt;th&gt;HNSW &lt;/th&gt;&lt;th&gt;IVF &lt;/th&gt;&lt;th&gt;Hybrid&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Speed&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Fastest (milliseconds) &lt;/td&gt;&lt;td&gt;Fast (seconds) &lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Memory&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;High (in-memory) &lt;/td&gt;&lt;td&gt;Low (disk-based) &lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Accuracy&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Highest (95-99%+) &lt;/td&gt;&lt;td&gt;High (90-99%) &lt;/td&gt;&lt;td&gt;Variable&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Dataset Size&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Small to Medium &lt;/td&gt;&lt;td&gt;Large to Huge &lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Best For&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Speed-critical apps &lt;/td&gt;&lt;td&gt;Memory-constrained environments &lt;/td&gt;&lt;td&gt;Mixed query types&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;practical-guidelines&quot;&gt;Practical Guidelines&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Use HNSW When:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dataset fits comfortably in available memory&lt;/li&gt;
&lt;li&gt;Query speed is critical (real-time applications)&lt;/li&gt;
&lt;li&gt;You can allocate sufficient Vector Pool memory&lt;/li&gt;
&lt;li&gt;Working with up to millions of vectors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Use IVF When:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dataset is too large for available memory&lt;/li&gt;
&lt;li&gt;Working with billions of vectors&lt;/li&gt;
&lt;li&gt;RAM is limited or expensive&lt;/li&gt;
&lt;li&gt;Using partitioned tables for very large datasets&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Use Hybrid When:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Application needs both keyword and semantic search&lt;/li&gt;
&lt;li&gt;Users perform mixed query types&lt;/li&gt;
&lt;li&gt;Want to simplify index management&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;performance-optimization-tips&quot;&gt;Performance Optimization Tips&lt;/h3&gt;
&lt;h4 id=&quot;1-index-configuration&quot;&gt;1. Index Configuration&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Target Accuracy:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Higher accuracy = slower but more precise
WITH TARGET ACCURACY 99;  -- Very precise

-- Lower accuracy = faster but less precise  
WITH TARGET ACCURACY 90;  -- Still good for most cases
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Balance accuracy with performance needs. TARGET ACCURACY between 90-99% provides excellent results.&lt;/p&gt;
&lt;h4 id=&quot;2-memory-allocation&quot;&gt;2. Memory Allocation&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Allocate adequate memory for HNSW indexes
-- Use formula: 1.3 × vectors × dimensions × format_size

-- Example for 1M vectors, 384 dimensions, FLOAT32:
-- 1.3 × 1,000,000 × 384 × 4 = ~2 GB
ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 2G SCOPE=BOTH;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-query-optimization&quot;&gt;3. Query Optimization&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Use FETCH FIRST for better performance
SELECT product_name, similarity_score
FROM (
    SELECT 
        product_name,
        VECTOR_DISTANCE(description_vector, :query_vec, COSINE) AS similarity_score
    FROM products
    WHERE category = 'Electronics'  -- Apply filters early
)
ORDER BY similarity_score
FETCH FIRST 10 ROWS ONLY;  -- Limit results
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;4-approximate-vs-exact-search&quot;&gt;4. Approximate vs. Exact Search&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Approximate search (uses index, faster)
SELECT product_name
FROM products
ORDER BY VECTOR_DISTANCE(description_vector, :query_vec, COSINE)
FETCH FIRST 10 ROWS ONLY;

-- Exact search (no index, 100% accurate, slower)
SELECT product_name
FROM products
ORDER BY VECTOR_DISTANCE(description_vector, :query_vec, COSINE)
FETCH EXACT FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use approximate search for most queries; reserve exact search for critical accuracy requirements.&lt;/p&gt;
&lt;h3 id=&quot;real-world-example-e-commerce-product-search&quot;&gt;Real-World Example: E-commerce Product Search&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Step 1: Create table
CREATE TABLE products (
    product_id NUMBER PRIMARY KEY,
    name VARCHAR2(500),
    description CLOB,
    price NUMBER(10,2),
    category VARCHAR2(100),
    rating NUMBER(3,2),
    reviews_count NUMBER,
    desc_vector VECTOR(384, FLOAT32)
);

-- Step 2: Configure memory (1M products × 384 dims × 4 bytes × 1.3 = ~2GB)
ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 2G SCOPE=BOTH;

-- Step 3: Create HNSW index
CREATE VECTOR INDEX products_hnsw_idx ON products (desc_vector)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- Step 4: Query with combined filters
SELECT 
    name,
    price,
    rating,
    VECTOR_DISTANCE(
        desc_vector,
        VECTOR_EMBEDDING(model USING 'comfortable running shoes' AS data),
        COSINE
    ) AS relevance
FROM products
WHERE price BETWEEN 50 AND 200
    AND category = 'Footwear'
    AND rating &amp;gt;= 4.0
    AND reviews_count &amp;gt; 100
ORDER BY relevance
FETCH FIRST 10 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Queries can combine vector and relational data&lt;/strong&gt; in a single SQL statement, eliminating data fragmentation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standard comparison operators (=, &amp;gt;, &amp;lt;) cannot be used between vectors&lt;/strong&gt; - use VECTOR_DISTANCE functions instead&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vector indexes dramatically improve performance&lt;/strong&gt; by reducing search space through clustering, partitioning, and graphs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HNSW indexes&lt;/strong&gt; provide fastest queries but require significant memory (Formula: 1.3 × vectors × dimensions × format_size)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IVF indexes&lt;/strong&gt; work for very large datasets using disk storage, not constrained by RAM&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vector Pool memory must be configured&lt;/strong&gt; for HNSW indexes at CDB level with VECTOR_MEMORY_SIZE parameter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Database restart required&lt;/strong&gt; when changing VECTOR_MEMORY_SIZE (unless using automatic growth)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PDB maximum is 70% of sga_target&lt;/strong&gt;, inheriting from CDB configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choose index type based on dataset size and memory availability&lt;/strong&gt; - HNSW for speed, IVF for scale&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;By understanding these concepts and properly configuring vector indexes, you can build high-performance semantic search applications that seamlessly integrate AI capabilities with traditional relational database operations.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/11750/oracle-ai-vector-search-querying-vectors-and-optimizing-with-indexes</guid>
<pubDate>Mon, 16 Feb 2026 08:23:55 +0000</pubDate>
</item>
<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-2&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-1&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>Understanding Semantic Search: Vector Embeddings and Similarity Search</title>
<link>https://coderlegion.com/10918/understanding-semantic-search-vector-embeddings-and-similarity-search</link>
<description>&lt;p&gt;Semantic search represents a fundamental shift in how we retrieve information from databases and search engines. Unlike traditional keyword-based search that relies on exact text matches, semantic search understands the meaning and context behind queries, enabling more intuitive and accurate information retrieval.&lt;/p&gt;
&lt;h3 id=&quot;what-is-semantic-search-&quot;&gt;What is Semantic Search?&lt;/h3&gt;
&lt;p&gt;Semantic search goes beyond keyword matching to understand the intent and contextual meaning behind a query. Instead of looking for exact word matches, it retrieves results based on semantic similarity—finding content that means the same thing, even when different words are used.&lt;/p&gt;
&lt;p&gt;For example, searching for &quot;healthy dinner ideas&quot; could return results like &quot;nutritious meal prep for busy nights&quot; even though the exact keywords don't match. This is possible because semantic search operates on the underlying meaning of the content.&lt;/p&gt;
&lt;h3 id=&quot;understanding-vector-data-distribution&quot;&gt;Understanding Vector Data Distribution&lt;/h3&gt;
&lt;p&gt;Vector embeddings, which power semantic search, have unique characteristics:&lt;/p&gt;
&lt;h4 id=&quot;uneven-distribution&quot;&gt;Uneven Distribution&lt;/h4&gt;
&lt;p&gt;Vector data points are not uniformly distributed across vector space. Instead, they cluster around regions of semantic similarity, reflecting how related concepts group together in meaning.&lt;/p&gt;
&lt;h4 id=&quot;semantic-clustering&quot;&gt;Semantic Clustering&lt;/h4&gt;
&lt;p&gt;Vectors representing similar concepts naturally cluster together:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Words like &quot;king,&quot; &quot;queen,&quot; &quot;prince,&quot; and &quot;princess&quot; form a royalty cluster&lt;/li&gt;
&lt;li&gt;Technical terms like &quot;algorithm,&quot; &quot;function,&quot; and &quot;code&quot; cluster in programming regions&lt;/li&gt;
&lt;li&gt;Synonyms and semantically related phrases position close to each other&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This clustering property is fundamental to how semantic search works—we find related content by finding nearby vectors in this space.&lt;/p&gt;
&lt;h3 id=&quot;how-similarity-search-works-k-nn-principle&quot;&gt;How Similarity Search Works: k-NN Principle&lt;/h3&gt;
&lt;p&gt;At its core, semantic search relies on &lt;strong&gt;k-Nearest Neighbors (k-NN)&lt;/strong&gt; search. When you perform a similarity search:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Convert your query into a vector embedding&lt;/li&gt;
&lt;li&gt;Find the &lt;strong&gt;k nearest vectors&lt;/strong&gt; to your query vector in the vector space&lt;/li&gt;
&lt;li&gt;Retrieve the corresponding documents or data points&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The result is an &lt;strong&gt;ordered list ranked by similarity&lt;/strong&gt;, with the most semantically similar items appearing first.&lt;/p&gt;
&lt;h4 id=&quot;distance-metrics&quot;&gt;Distance Metrics&lt;/h4&gt;
&lt;p&gt;Similarity between vectors is measured using:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cosine Similarity&lt;/strong&gt;: Measures the angle between vectors (commonly used for text)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Euclidean Distance&lt;/strong&gt;: Straight-line distance between points&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dot Product&lt;/strong&gt;: Useful for normalized vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manhattan Distance&lt;/strong&gt;: Sum of absolute differences along each dimension&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;types-of-similarity-search&quot;&gt;Types of Similarity Search&lt;/h3&gt;
&lt;h4 id=&quot;1-exact-search-exhaustive-search-&quot;&gt;1. Exact Search (Exhaustive Search)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt; Compares the query vector against every single vector in the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Accuracy&lt;/strong&gt;: 100% accurate—guarantees finding actual nearest neighbors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Slow for large datasets (can take hours for millions of vectors)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Small datasets (&amp;lt; 10,000 documents) or when perfect accuracy is critical&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-approximate-search-ann-&quot;&gt;2. Approximate Search (ANN)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt; Uses specialized algorithms (like HNSW, IVF, or LSH) to efficiently search through large datasets by narrowing down the search space.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Accuracy&lt;/strong&gt;: High accuracy (typically 90-99%)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Dramatically faster—searches that take 65 hours with exact search complete in seconds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Large datasets (hundreds of thousands to billions of vectors)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Popular ANN Algorithms:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HNSW&lt;/strong&gt;: Graph-based, extremely fast for queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IVF&lt;/strong&gt;: Cluster-based, good for very large datasets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LSH&lt;/strong&gt;: Hash-based, excellent for high-dimensional data&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Aspect &lt;/th&gt;&lt;th&gt;Exact Search &lt;/th&gt;&lt;th&gt;Approximate Search&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Accuracy&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;100% &lt;/td&gt;&lt;td&gt;90-99%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Speed&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Slow (linear) &lt;/td&gt;&lt;td&gt;Fast (sub-linear)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Scalability&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Poor for large datasets &lt;/td&gt;&lt;td&gt;Excellent&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Best For&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;&amp;lt; 10K documents &lt;/td&gt;&lt;td&gt;&amp;gt; 10K documents&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;vector-embedding-models&quot;&gt;Vector Embedding Models&lt;/h3&gt;
&lt;p&gt;Vector embeddings are the &quot;translation layer&quot; that converts human-readable content into machine-understandable numerical representations.&lt;/p&gt;
&lt;h4 id=&quot;what-are-embedding-models-&quot;&gt;What Are Embedding Models?&lt;/h4&gt;
&lt;p&gt;Embedding models are machine learning models—typically based on &lt;strong&gt;transformer architectures&lt;/strong&gt;—that convert data into dense vector representations trained on massive datasets to understand semantic relationships.&lt;/p&gt;
&lt;h4 id=&quot;key-capabilities&quot;&gt;Key Capabilities&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Contextual Understanding:&lt;/strong&gt; Assign meaning based on context (e.g., &quot;bank&quot; in &quot;river bank&quot; vs. &quot;financial bank&quot; gets different embeddings)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Feature Extraction:&lt;/strong&gt; Identify and quantify relevant features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In text: semantic meaning, sentiment, topic&lt;/li&gt;
&lt;li&gt;In images: shapes, colors, textures, objects&lt;/li&gt;
&lt;li&gt;In audio: pitch, rhythm, timbre, speech patterns&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Transformer Architecture:&lt;/strong&gt; Excel at processing sequences, capturing long-range dependencies, and parallel processing for efficiency.&lt;/p&gt;
&lt;h4 id=&quot;popular-models&quot;&gt;Popular Models&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;For Text:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sentence Transformers&lt;/strong&gt; (all-MiniLM-L6-v2): 384 dimensions, fast and lightweight&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BERT&lt;/strong&gt;: 768 dimensions, general-purpose language understanding&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GPT Embeddings&lt;/strong&gt; (text-embedding-ada-002): 1536 dimensions, production-grade&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;For Images:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CLIP&lt;/strong&gt;: Jointly embeds images and text in the same space&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResNet&lt;/strong&gt;: Deep convolutional neural network for image features&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ViT&lt;/strong&gt;: Transformer-based image understanding&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;For Audio:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Wav2Vec 2.0&lt;/strong&gt;: Speech and audio embeddings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CLAP&lt;/strong&gt;: Contrastive Language-Audio Pre-training&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;types-of-embedding-models&quot;&gt;Types of Embedding Models&lt;/h3&gt;
&lt;h4 id=&quot;1-pre-trained-open-source-models&quot;&gt;1. Pre-trained Open Source Models&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Zero training cost, proven performance, large community support&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to Use:&lt;/strong&gt; General semantic search, quick prototyping, resource-constrained environments&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; Sentence Transformers library (15,000+ models), BERT variants, Universal Sentence Encoder&lt;/p&gt;
&lt;h4 id=&quot;2-custom-models-based-on-your-dataset&quot;&gt;2. Custom Models Based on Your Dataset&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Optimal performance for specific use cases, understands proprietary terminology&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt; Start with pre-trained model → Fine-tune on labeled data → Evaluate → Iterate&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt; Medical terminology, legal documents, e-commerce catalogs, scientific research&lt;/p&gt;
&lt;h3 id=&quot;generating-vector-embeddings&quot;&gt;Generating Vector Embeddings&lt;/h3&gt;
&lt;h4 id=&quot;1-outside-the-database&quot;&gt;1. Outside the Database&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Third-Party APIs:&lt;/strong&gt; OpenAI, Cohere, Google Vertex AI, Hugging Face&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Local Inference:&lt;/strong&gt; Python libraries (sentence-transformers, transformers), ONNX Runtime, TensorFlow/PyTorch&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
embeddings = model.encode([&quot;Semantic search is powerful&quot;])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Flexibility in model choice, control over pipeline&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; Requires additional infrastructure, data movement between systems&lt;/p&gt;
&lt;h4 id=&quot;2-within-the-database-onnx-&quot;&gt;2. Within the Database (ONNX)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;ONNX&lt;/strong&gt; (Open Neural Network Exchange) is an open format enabling models trained in one framework to be deployed in another.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Supported Databases:&lt;/strong&gt; Oracle Database 23ai, PostgreSQL (with extensions), Microsoft SQL Server, SingleStore&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example (Oracle):&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;BEGIN
  DBMS_VECTOR.LOAD_ONNX_MODEL(
    directory =&amp;gt; 'MODEL_DIR',
    file_name =&amp;gt; 'all-MiniLM-L6-v2.onnx',
    model_name =&amp;gt; 'text_embedding_model'
  );
END;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; No data movement, reduced latency, simplified architecture&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; Limited to ONNX-compatible models, database computational overhead&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Factor &lt;/th&gt;&lt;th&gt;External Generation &lt;/th&gt;&lt;th&gt;In-Database (ONNX)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Model Flexibility&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;High &lt;/td&gt;&lt;td&gt;Medium&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Latency&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Higher &lt;/td&gt;&lt;td&gt;Lower&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Data Security&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Requires data export &lt;/td&gt;&lt;td&gt;Data stays in DB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Best For&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Batch processing, custom models &lt;/td&gt;&lt;td&gt;Real-time apps, integrated systems&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;real-world-applications&quot;&gt;Real-World Applications&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Document Search&lt;/strong&gt;: Find relevant documents based on meaning rather than keywords&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recommendation Systems&lt;/strong&gt;: Suggest products/content based on similarity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Question Answering&lt;/strong&gt;: Match user questions to relevant answers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Content Moderation&lt;/strong&gt;: Identify similar or duplicate content&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Image Search&lt;/strong&gt;: Enable search by visual similarity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customer Support&lt;/strong&gt;: Route tickets and find similar past issues&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fraud Detection&lt;/strong&gt;: Identify unusual patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code Search&lt;/strong&gt;: Find similar code snippets or search by natural language&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;performance-optimization-tips-1&quot;&gt;Performance Optimization Tips&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Choose the Right Balance&lt;/strong&gt;: Use exact search for &amp;lt; 10K documents, approximate for &amp;gt; 100K&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tune Parameters&lt;/strong&gt;: Adjust &lt;code&gt;ef_search&lt;/code&gt; (HNSW) or &lt;code&gt;nprobe&lt;/code&gt; (IVF) for accuracy vs. speed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optimize Dimensions&lt;/strong&gt;: Choose appropriate dimension counts, consider quantization&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implement Caching&lt;/strong&gt;: Cache frequent embeddings, pre-compute for static content&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Batch Processing&lt;/strong&gt;: Generate embeddings in batches, leverage GPU acceleration&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;key-takeaways-1&quot;&gt;Key Takeaways&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Vector embeddings capture semantic meaning in numerical form&lt;/li&gt;
&lt;li&gt;Vector data naturally clusters by semantic similarity&lt;/li&gt;
&lt;li&gt;Choose between exact search (accurate, slow) and approximate search (fast, 90-99% accurate) based on your needs&lt;/li&gt;
&lt;li&gt;Transformer-based embedding models provide state-of-the-art semantic understanding&lt;/li&gt;
&lt;li&gt;Models can be pre-trained, custom-trained, or fine-tuned for specific domains&lt;/li&gt;
&lt;li&gt;Embeddings can be generated externally or within databases using ONNX&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whether you're building a search engine, recommendation system, or AI-powered application, understanding these concepts is crucial for leveraging the full power of modern semantic search technologies.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/10918/understanding-semantic-search-vector-embeddings-and-similarity-search</guid>
<pubDate>Mon, 02 Feb 2026 07:14:35 +0000</pubDate>
</item>
<item>
<title>Oracle AI Vector Search in Oracle Database 23ai</title>
<link>https://coderlegion.com/10510/oracle-ai-vector-search-in-oracle-database-23ai</link>
<description>&lt;p&gt;Oracle Database 23ai (formerly 23c) represents a significant leap forward in integrating artificial intelligence capabilities directly into the database. One of its most groundbreaking features is AI Vector Search, which enables the database to understand conceptual similarity between pieces of data. This powerful feature eliminates the need for separate vector databases and allows you to perform semantic searches alongside traditional business queries within a unified system.&lt;/p&gt;
&lt;h3 id=&quot;what-is-oracle-ai-vector-search-&quot;&gt;What is Oracle AI Vector Search?&lt;/h3&gt;
&lt;p&gt;Oracle AI Vector Search enables searching both structured and unstructured data by semantics or meaning, rather than just by values, fundamentally changing how we approach information retrieval. Instead of traditional keyword-based searches that match exact terms, vector search understands the context and meaning behind your queries.&lt;/p&gt;
&lt;h3 id=&quot;key-benefits-of-oracle-ai-vector-search&quot;&gt;Key Benefits of Oracle AI Vector Search&lt;/h3&gt;
&lt;h4 id=&quot;1-semantic-search-on-unstructured-data&quot;&gt;1. &lt;strong&gt;Semantic Search on Unstructured Data&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Vector search is considered better than keyword search because it's based on the meaning and context behind words, not the actual words themselves. This allows you to find relevant information even when the exact keywords don't match.&lt;/p&gt;
&lt;h4 id=&quot;2-unified-relational-and-semantic-search&quot;&gt;2. &lt;strong&gt;Unified Relational and Semantic Search&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;One of the biggest advantages is the ability to combine semantic search on unstructured data with relational search on business data in a single system. This allows search results based on meaning, not just text matching – a fundamental shift for information retrieval.&lt;/p&gt;
&lt;h4 id=&quot;3-eliminates-data-fragmentation&quot;&gt;3. &lt;strong&gt;Eliminates Data Fragmentation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;No need to maintain separate vector databases or move data between systems. Your vectors live alongside your business data, benefiting from Oracle's robust security, availability, and performance features.&lt;/p&gt;
&lt;h4 id=&quot;4-enhanced-security-and-governance&quot;&gt;4. &lt;strong&gt;Enhanced Security and Governance&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Oracle Database's security features (encryption, RBAC, auditing, Data Vault policies) extend automatically to vector data types. Vectors and graph data can be secured using the same roles and privileges as your tables.&lt;/p&gt;
&lt;h3 id=&quot;understanding-the-core-components&quot;&gt;Understanding the Core Components&lt;/h3&gt;
&lt;h4 id=&quot;the-vector-data-type-1&quot;&gt;The VECTOR Data Type&lt;/h4&gt;
&lt;p&gt;The VECTOR data type was introduced with Oracle Database 23ai, providing the foundation to store vector embeddings alongside business data. To use the VECTOR data type, the COMPATIBLE initialization parameter must be set to 23.4.0 or higher.&lt;/p&gt;
&lt;p&gt;Here's a basic example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE documents (
    doc_id INT,
    doc_text CLOB,
    doc_vector VECTOR
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The VECTOR data type can store vectors in different formats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;INT8&lt;/strong&gt; (8-bit integers)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT32&lt;/strong&gt; (32-bit floating-point numbers)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FLOAT64&lt;/strong&gt; (64-bit floating-point numbers)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can specify the number of dimensions and storage format when declaring a column:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE products (
    product_id NUMBER,
    description VARCHAR2(4000),
    embedding VECTOR(1536, FLOAT32)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;vector-embeddings-the-foundation&quot;&gt;Vector Embeddings: The Foundation&lt;/h4&gt;
&lt;p&gt;Vector embeddings are mathematical vector representations of data points that describe the semantic meaning behind content such as words, documents, audio tracks, or images. They translate semantic similarity, as perceived by humans, into proximity in a mathematical vector space.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How Vector Embeddings Work:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Unstructured data (text, images, audio) is converted into numerical vectors&lt;/li&gt;
&lt;li&gt;Semantically similar content has vectors that are close together in vector space&lt;/li&gt;
&lt;li&gt;Searching semantic similarity in a dataset is equivalent to searching nearest neighbors in a vector space&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Creating Vector Embeddings:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You have several options for generating embeddings:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;ONNX Embedding Models&lt;/strong&gt;: Import pre-trained models into Oracle Database using the ONNX (Open Neural Network Exchange) format&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Third-Party REST APIs&lt;/strong&gt;: Access external embedding services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Local Models&lt;/strong&gt;: Use models like all-MiniLM-L12-v2 for text embeddings or ResNet for image embeddings&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Example of loading an ONNX model:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;BEGIN
  DBMS_VECTOR.LOAD_ONNX_MODEL(
    directory =&amp;gt; 'DM_DUMP',
    file_name =&amp;gt; 'all-MiniLM-L6-v2.onnx',
    model_name =&amp;gt; 'doc_model'
  );
END;
/
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;vector-indexes-accelerating-similarity-search&quot;&gt;Vector Indexes: Accelerating Similarity Search&lt;/h3&gt;
&lt;p&gt;While exact similarity searches are accurate, they can be slow for large datasets. Oracle AI Vector Search supports three types of vector indexes that use Approximate Nearest Neighbor algorithms to reduce distance calculations:&lt;/p&gt;
&lt;h4 id=&quot;1-hnsw-hierarchical-navigable-small-world-index&quot;&gt;1. &lt;strong&gt;HNSW (Hierarchical Navigable Small World) Index&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;HNSW is an In-Memory Neighbor Graph vector index that's very efficient for approximate similarity search. It creates a layered graph structure that enables fast navigation through high-dimensional space.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In-memory only (stored in Vector Memory Pool in SGA)&lt;/li&gt;
&lt;li&gt;Extremely fast query performance&lt;/li&gt;
&lt;li&gt;Memory can be estimated as 1.3 times the product of vector format size, number of dimensions, and number of rows&lt;/li&gt;
&lt;li&gt;Best for datasets that fit in available memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example:&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 (embedding)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-ivf-inverted-file-flat-index&quot;&gt;2. &lt;strong&gt;IVF (Inverted File Flat) Index&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The IVF index is a storage-based Neighbor Partition vector index that enhances search efficiency by narrowing the search area through neighbor partitions or clusters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Storage-based (not constrained by memory like HNSW)&lt;/li&gt;
&lt;li&gt;Can be used for very large datasets and still provide excellent performance compared to exhaustive similarity search&lt;/li&gt;
&lt;li&gt;Supports both global and local partitioning on partitioned tables&lt;/li&gt;
&lt;li&gt;Ideal for large datasets where HNSW won't fit in memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example:&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 (embedding)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;3-hybrid-vector-index-1&quot;&gt;3. &lt;strong&gt;Hybrid Vector Index&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Hybrid Vector Index combines full text and semantic search in one index, allowing users to run textual queries, vector similarity queries, or hybrid queries. This is particularly useful when you need both keyword matching and semantic understanding.&lt;/p&gt;
&lt;h3 id=&quot;practical-implementation-example&quot;&gt;Practical Implementation Example&lt;/h3&gt;
&lt;p&gt;Here's a complete example of using vector search:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Step 1: Create table with vector column
CREATE TABLE knowledge_base (
    id NUMBER PRIMARY KEY,
    content CLOB,
    content_vector VECTOR(384, FLOAT32)
);

-- Step 2: Insert data and generate embeddings
INSERT INTO knowledge_base VALUES (
    1,
    'Oracle Database 23ai introduces AI Vector Search',
    NULL
);

-- Step 3: Update vectors using embedding model
UPDATE knowledge_base
SET content_vector = VECTOR_EMBEDDING(doc_model USING content AS DATA);

-- Step 4: Create vector index for performance
CREATE VECTOR INDEX kb_vector_idx ON knowledge_base (content_vector)
ORGANIZATION INMEMORY NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;

-- Step 5: Perform similarity search
SELECT id, content
FROM knowledge_base
ORDER BY VECTOR_DISTANCE(
    content_vector,
    VECTOR_EMBEDDING(doc_model USING 'AI features in databases' AS DATA),
    COSINE
)
FETCH FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;distance-metrics-1&quot;&gt;Distance Metrics&lt;/h3&gt;
&lt;p&gt;Oracle supports multiple distance metrics for vector comparisons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;COSINE&lt;/strong&gt;: Measures angular distance (best for text embeddings)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;EUCLIDEAN&lt;/strong&gt;: Measures straight-line distance&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DOT_PRODUCT&lt;/strong&gt;: Useful for normalized vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MANHATTAN&lt;/strong&gt;: Sum of absolute differences&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;use-cases-1&quot;&gt;Use Cases&lt;/h3&gt;
&lt;p&gt;Oracle AI Vector Search enables powerful applications:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Semantic Document Search&lt;/strong&gt;: Find documents by meaning, not just keywords&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recommendation Systems&lt;/strong&gt;: Suggest products based on similarity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Image Similarity Search&lt;/strong&gt;: Find visually similar images&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chatbots and Q&amp;amp;A Systems&lt;/strong&gt;: Build context-aware conversational AI&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anomaly Detection&lt;/strong&gt;: Identify outliers in high-dimensional data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Natural Language Processing&lt;/strong&gt;: Power advanced text analysis applications&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;performance-considerations-2&quot;&gt;Performance Considerations&lt;/h3&gt;
&lt;h4 id=&quot;vector-pool-sizing&quot;&gt;Vector Pool Sizing&lt;/h4&gt;
&lt;p&gt;For HNSW indexes, you need to configure the Vector Memory Pool:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER SYSTEM SET VECTOR_MEMORY_SIZE = 2G SCOPE=BOTH;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;choosing-the-right-index&quot;&gt;Choosing the Right Index&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use HNSW&lt;/strong&gt; when: Dataset fits in memory and you need maximum speed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use IVF&lt;/strong&gt; when: Dataset is very large or memory is limited&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Hybrid&lt;/strong&gt; when: You need both keyword and semantic search&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;target-accuracy&quot;&gt;Target Accuracy&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;TARGET ACCURACY&lt;/code&gt; parameter balances speed vs. precision. Higher accuracy (e.g., 95-99) returns more precise results but requires more computation.&lt;/p&gt;
&lt;h3 id=&quot;integration-with-existing-features&quot;&gt;Integration with Existing Features&lt;/h3&gt;
&lt;p&gt;One of the most powerful aspects of Oracle AI Vector Search is its deep integration with existing Oracle Database features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Oracle RAC&lt;/strong&gt;: Full support for clustered environments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Guard&lt;/strong&gt;: Vector data replicates alongside business data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Partitioning&lt;/strong&gt;: IVF indexes support local partitioning&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: All Oracle security features apply to vectors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ORDS&lt;/strong&gt;: Expose vector search through REST APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Oracle APEX&lt;/strong&gt;: Build AI-powered applications with minimal code&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;Oracle AI Vector Search is available in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Oracle Autonomous Database (Always Free tier available)&lt;/li&gt;
&lt;li&gt;Oracle Database 23ai Free (Developer edition)&lt;/li&gt;
&lt;li&gt;Oracle Exadata Database Service&lt;/li&gt;
&lt;li&gt;Oracle Base Database Service&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To start experimenting:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Download Oracle Database 23ai Free from Oracle Container Registry&lt;/li&gt;
&lt;li&gt;Set COMPATIBLE parameter to 23.4.0 or higher&lt;/li&gt;
&lt;li&gt;Configure Vector Memory Pool for HNSW indexes&lt;/li&gt;
&lt;li&gt;Load an ONNX embedding model&lt;/li&gt;
&lt;li&gt;Create tables with VECTOR columns&lt;/li&gt;
&lt;li&gt;Start building AI-powered applications!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Oracle Database 23ai brings AI algorithms to where the data lives, instead of having to move the data to where the AI algorithm lives. This architectural approach provides significant advantages in terms of security, performance, and simplicity.&lt;/p&gt;
&lt;p&gt;By combining semantic search capabilities with traditional relational data operations in a single, converged database, Oracle AI Vector Search represents a fundamental shift in how we build AI-powered applications. Whether you're implementing RAG-based chatbots, recommendation engines, or advanced search systems, Oracle Database 23ai provides the foundation for secure, scalable, and high-performance AI applications.&lt;/p&gt;
&lt;p&gt;The elimination of data fragmentation, coupled with enterprise-grade security and proven Oracle reliability, makes Oracle AI Vector Search an compelling choice for organizations looking to integrate AI capabilities into their data infrastructure.&lt;/p&gt;
&lt;h3 id=&quot;additional-resources&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/&quot;&gt;Oracle AI Vector Search Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.oracle.com/database/free/&quot;&gt;Oracle Database 23ai Free Download&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://apexapps.oracle.com/pls/apex/dbpm/r/livelabs/home&quot;&gt;Oracle LiveLabs: AI Vector Search Workshops&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://blogs.oracle.com/database/&quot;&gt;Oracle AI Vector Search Blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/10510/oracle-ai-vector-search-in-oracle-database-23ai</guid>
<pubDate>Mon, 26 Jan 2026 15:52:40 +0000</pubDate>
</item>
<item>
<title>RAG Pipeline Deep Dive: Ingestion, Chunking, Embedding, and Vector Search</title>
<link>https://coderlegion.com/10137/rag-pipeline-deep-dive-ingestion-chunking-embedding-and-vector-search</link>
<description>&lt;p&gt;Retrieval-Augmented Generation (RAG) has become the default approach for providing context and memory to AI applications. Understanding the RAG pipeline—from document ingestion to final response generation—is essential for building high-performance AI systems. This comprehensive guide explores each stage of the RAG workflow, with special focus on Oracle Database 23ai's native vector capabilities.&lt;/p&gt;
&lt;h3 id=&quot;the-rag-pipeline-an-overview&quot;&gt;The RAG Pipeline: An Overview&lt;/h3&gt;
&lt;p&gt;A complete RAG pipeline consists of two main phases:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ingestion Phase (Offline):&lt;/strong&gt;&lt;br&gt;
Documents → Chunking → Embedding → Index/Store in Vector Database&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Retrieval Phase (Runtime):&lt;/strong&gt;&lt;br&gt;
User Query → Embed Query → Similarity Search → Top-K Results → LLM Generation → Response&lt;/p&gt;
&lt;p&gt;The RAG pipeline connects the model to the information it needs at query time. When a user asks a question, the pipeline retrieves the most relevant documents, prepares that text as context, and includes it in the prompt so the model can generate an answer grounded in retrieved material rather than training data alone.&lt;/p&gt;
&lt;h3 id=&quot;phase-1-document-ingestion&quot;&gt;Phase 1: Document Ingestion&lt;/h3&gt;
&lt;p&gt;Ingestion is the process of loading documents from multiple sources and in multiple formats, transforming them into a structured form suitable for embedding and retrieval.&lt;/p&gt;
&lt;h4 id=&quot;document-loading&quot;&gt;Document Loading&lt;/h4&gt;
&lt;p&gt;Raw documents—whether PDFs, Word documents, web pages, or database records—must be transformed into manageable chunks suitable for retrieval.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Common Sources:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Local files (PDF, DOCX, TXT, CSV)&lt;/li&gt;
&lt;li&gt;Web pages and APIs&lt;/li&gt;
&lt;li&gt;Databases and data warehouses&lt;/li&gt;
&lt;li&gt;Cloud storage (S3, GCS, Azure Blob)&lt;/li&gt;
&lt;li&gt;Enterprise systems (SharePoint, Confluence, Notion)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Loading Libraries:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;PyPDF2&lt;/strong&gt;: For PDF documents&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;python-docx&lt;/strong&gt;: For Word documents&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LangChain Document Loaders&lt;/strong&gt;: Unified interface for multiple formats&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LlamaIndex Data Connectors&lt;/strong&gt;: Specialized loaders for various sources&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Oracle OracleDocLoader&lt;/strong&gt;: Native loader for Oracle Database 23ai&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;text-extraction-and-cleaning&quot;&gt;Text Extraction and Cleaning&lt;/h4&gt;
&lt;p&gt;A clean corpus improves both retrieval accuracy and embedding quality. Use parsing libraries to extract only the primary content from web pages or PDFs, and remove boilerplate, navigation links, and disclaimers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cleaning Steps:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Remove Noise&lt;/strong&gt;: Headers, footers, navigation, ads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Normalize Structure&lt;/strong&gt;: Convert to consistent format (JSONL, Parquet)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preserve Metadata&lt;/strong&gt;: Source, timestamp, author, document type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handle Special Characters&lt;/strong&gt;: Normalize encoding (UTF-8)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintain Logical Structure&lt;/strong&gt;: Keep headings, lists, tables&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;metadata-enrichment&quot;&gt;Metadata Enrichment&lt;/h4&gt;
&lt;p&gt;Each chunk should carry metadata such as topic, date, and source, so that retrieval can filter and rank results more effectively.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Metadata Fields:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;source_id&lt;/strong&gt;: Unique document identifier&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;title&lt;/strong&gt;: Document title&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;created_date&lt;/strong&gt;: Document creation timestamp&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;author&lt;/strong&gt;: Document creator&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;document_type&lt;/strong&gt;: PDF, email, webpage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;topic/category&lt;/strong&gt;: For domain filtering&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;page_number&lt;/strong&gt;: For PDF sources&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;chunk_id&lt;/strong&gt;: Unique identifier for the chunk&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;phase-2-chunking---the-critical-step&quot;&gt;Phase 2: Chunking - The Critical Step&lt;/h3&gt;
&lt;p&gt;Chunking is simply the act of splitting larger documents into smaller units (&quot;chunks&quot;). Each chunk can be individually indexed, embedded, and retrieved.&lt;/p&gt;
&lt;h4 id=&quot;why-chunking-matters&quot;&gt;Why Chunking Matters&lt;/h4&gt;
&lt;p&gt;The chunking process directly feeds into the embedding step, where each chunk is converted into vector representations that capture semantic meaning.&lt;/p&gt;
&lt;p&gt;A common source of inaccurate or unstable answers lies in a structural conflict within the traditional &quot;chunk-embed-retrieve&quot; pipeline: using a single-granularity, fixed-size text chunk to perform two inherently conflicting tasks:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Semantic matching (recall)&lt;/strong&gt;: Smaller chunks (100-256 tokens) needed for precise similarity search&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Context understanding (utilization)&lt;/strong&gt;: Larger chunks (1024+ tokens) needed for coherent LLM generation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This creates a difficult trade-off between &quot;precise but fragmented&quot; and &quot;complete but vague.&quot;&lt;/p&gt;
&lt;h4 id=&quot;pre-chunking-vs-post-chunking&quot;&gt;Pre-Chunking vs Post-Chunking&lt;/h4&gt;
&lt;p&gt;Pre-chunking is the most common method. It processes documents asynchronously by breaking them into smaller pieces before embedding and storing them in the vector database. This enables fast retrieval at query time since all chunks are pre-computed.&lt;/p&gt;
&lt;p&gt;Post-chunking takes a different approach by embedding entire documents first, then performing chunking at query time only on the documents that are actually retrieved. The chunked results can be cached, so the system becomes faster over time.&lt;/p&gt;
&lt;h4 id=&quot;chunking-strategies&quot;&gt;Chunking Strategies&lt;/h4&gt;
&lt;p&gt;Fixed-Length Chunking: This is the simplest approach, segmenting text into equally sized pieces using character, token, or word counts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Common Chunk Sizes:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;300-500 tokens&lt;/strong&gt;: Typical chunks for most use cases, depending on the model and content type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;100-256 tokens&lt;/strong&gt;: For high-precision recall in semantic search&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;1024+ tokens&lt;/strong&gt;: For providing complete context to LLMs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Adopt recursive/semantic chunkers with 10-20% overlap to maintain context across boundaries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Advanced Chunking Approaches:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Recursive Chunking: This method is a bit smarter. It splits text hierarchically based on cues like paragraphs, line breaks, or sentences. If a section is too long, it recursively divides it further.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Semantic Chunking&lt;/strong&gt;: Instead of letting token limits decide where ideas get chopped, it uses embeddings to detect where the meaning actually shifts—grouping semantically related sentences together.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Document-Aware Chunking&lt;/strong&gt;: Preserves document structure (sections, paragraphs, tables) while chunking.&lt;/p&gt;
&lt;h4 id=&quot;chunk-overlap&quot;&gt;Chunk Overlap&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Chunk overlap is the number of overlapping characters (or tokens) between adjacent chunks&lt;/strong&gt;. This ensures that context isn't lost when information spans chunk boundaries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Recommended Overlap:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;10-20% overlap is standard practice&lt;/li&gt;
&lt;li&gt;For 500-token chunks, use 50-100 token overlap&lt;/li&gt;
&lt;li&gt;Maintains continuity without excessive redundancy&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Chunk 1: [Tokens 0-500]
Chunk 2: [Tokens 450-950]  ← 50 token overlap
Chunk 3: [Tokens 900-1400] ← 50 token overlap
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;splitting-process&quot;&gt;Splitting Process&lt;/h4&gt;
&lt;p&gt;Documents are split recursively until the chunks are small enough, using text splitters that respect:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sentence boundaries (don't break mid-sentence)&lt;/li&gt;
&lt;li&gt;Paragraph boundaries (maintain logical grouping)&lt;/li&gt;
&lt;li&gt;Section boundaries (preserve document structure)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Popular Chunking Libraries:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The LLM community often turns to two powerful open-source libraries: LangChain and LlamaIndex:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;LangChain&lt;/strong&gt;: Broad framework with flexible chunking strategies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LlamaIndex&lt;/strong&gt;: Designed specifically for RAG pipelines with sophisticated NodeParsers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chonkie&lt;/strong&gt;: Lightweight, dedicated chunking library focusing solely on text splitting&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;phase-3-embedding-and-storage&quot;&gt;Phase 3: Embedding and Storage&lt;/h3&gt;
&lt;p&gt;Chunking makes information retrievable; embeddings make it searchable by meaning rather than keywords.&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 that capture semantic relationships&lt;/strong&gt; between text. A piece of text—whether a word, phrase, sentence, or paragraph—is converted to a vector of numbers (typically 384-1536 dimensions).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Semantic similarity&lt;/strong&gt;: Embeddings that are numerically similar are also semantically similar&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dense representation&lt;/strong&gt;: High-dimensional vectors capture nuanced meaning&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Model-specific&lt;/strong&gt;: Different embedding models produce different vector spaces&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;embedding-models&quot;&gt;Embedding Models&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Popular Options:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;OpenAI text-embedding-3-large&lt;/strong&gt;: 3072 dimensions, high quality&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohere embed-v4.0&lt;/strong&gt;: 1024 dimensions, multimodal (text + images)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sentence-BERT (SBERT)&lt;/strong&gt;: 768 dimensions, open-source&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;all-MiniLM-L6-v2&lt;/strong&gt;: 384 dimensions, lightweight and fast&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Choose MiniLM/SBERT/Instruct/E5 for text, CLIP for images. Normalize embeddings for consistent similarity calculations.&lt;/p&gt;
&lt;h4 id=&quot;embedding-generation-outside-vs-inside-the-database&quot;&gt;Embedding Generation: Outside vs Inside the Database&lt;/h4&gt;
&lt;h5 id=&quot;option-1-generate-embeddings-outside-oracle-database-23ai&quot;&gt;Option 1: Generate Embeddings Outside Oracle Database 23ai&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;Vector embeddings can be generated outside Oracle Database 23ai using third-party embedding models&lt;/strong&gt;, then imported into the database for storage and search.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Workflow:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from sentence_transformers import SentenceTransformer

# Load embedding model
model = SentenceTransformer('all-MiniLM-L6-v2')

# Generate embeddings
chunks = [&quot;First chunk text&quot;, &quot;Second chunk text&quot;]
embeddings = model.encode(chunks)

# Store in Oracle Database 23ai
# INSERT INTO documents (text, embedding) VALUES (?, ?)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Flexibility in choosing any embedding model&lt;/li&gt;
&lt;li&gt;Can use cloud-based embedding services&lt;/li&gt;
&lt;li&gt;Easy integration with existing ML pipelines&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;option-2-generate-embeddings-inside-oracle-database-23ai&quot;&gt;Option 2: Generate Embeddings Inside Oracle Database 23ai&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;Embeddings can also be generated inside Oracle Database 23ai by downloading pretrained embedding models, converting them to ONNX format, and importing the ONNX format models into Database 23ai&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;ONNX (Open Neural Network Exchange) is an open-source format designed to represent deep learning models. It aims to provide interoperability between different deep learning frameworks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Download Pretrained Model&lt;/strong&gt; from Hugging Face or similar source&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Convert to ONNX Format&lt;/strong&gt; using Oracle OML4Py utility&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Import into Database 23ai&lt;/strong&gt; using DBMS_VECTOR package&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The command can be run to import the ONNX file into the database:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;EXEC dbms_vector.load_onnx_model(
  'DM_DUMP',
  'all_MiniLM_L12_v2.onnx',
  'minilm_l12_v2',
  JSON('{&quot;function&quot;: &quot;embedding&quot;, &quot;embeddingOutput&quot;: &quot;embedding&quot;, &quot;input&quot;: {&quot;input&quot;: [&quot;DATA&quot;]}}')
);
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Generate Embeddings in SQL&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT VECTOR_EMBEDDING(minilm_l12_v2 USING 'Your text here' AS data) AS embedding
FROM DUAL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Oracle Database implements an ONNX runtime directly within the database. This allows you to generate vector embeddings directly within Oracle Database using SQL&lt;/li&gt;
&lt;li&gt;Eliminates data movement between systems&lt;/li&gt;
&lt;li&gt;Simplified architecture and security&lt;/li&gt;
&lt;li&gt;Native integration with Oracle's vector capabilities&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;phase-4-vector-indexes-for-fast-search&quot;&gt;Phase 4: Vector Indexes for Fast Search&lt;/h3&gt;
&lt;p&gt;Once embeddings are generated and stored, &lt;strong&gt;vector indexes are specialized data structures designed for similarity searches in high-dimensional vector spaces&lt;/strong&gt;. They help accelerate vector similarity searches by reducing the number of distance calculations needed.&lt;/p&gt;
&lt;h4 id=&quot;why-vector-indexes-&quot;&gt;Why Vector Indexes?&lt;/h4&gt;
&lt;p&gt;Exact search to find the closest matches for a given vector are accurate but can be slow, since costly vector distance computations are needed for all vectors in a column.&lt;/p&gt;
&lt;p&gt;Vector indexes use techniques like clustering, partitioning, and neighbor graphs to group similar vectors together, reducing the search space dramatically.&lt;/p&gt;
&lt;h4 id=&quot;oracle-ai-vector-search-supported-index-types&quot;&gt;Oracle AI Vector Search: Supported Index Types&lt;/h4&gt;
&lt;p&gt;Oracle AI Vector Search supports Hierarchical Navigable Small World (HNSW) indexes and Inverted File (IVF) indexes.&lt;/p&gt;
&lt;h5 id=&quot;1-hnsw-in-memory-neighbor-graph&quot;&gt;1. HNSW: In-Memory Neighbor Graph&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;Hierarchical Navigable Small World (HNSW)&lt;/strong&gt; creates a navigable graph structure to locate similar vectors with exceptional speed and accuracy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;HNSW is an In-Memory Neighbor Graph Vector Index fully built in-memory. You need to setup a new memory pool with VECTOR_MEMORY_SIZE in the SGA to accommodate it.&lt;/p&gt;
&lt;p&gt;Since the HNSW index consumes a lot of memory, Oracle Database 23ai makes this index available by allocating a memory area called Vector Pool.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Memory Calculation:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To roughly determine the memory size needed to store an HNSW index, use the following formula: 1.3 × number of vectors × number of dimensions × size of your vector dimension type (for example, a FLOAT32 is 4 bytes).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Creating HNSW Index:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Configure vector pool
ALTER SYSTEM SET vector_memory_size=800M SCOPE=SPFILE;
-- Restart required

-- Create HNSW index
CREATE VECTOR INDEX documents_hnsw_idx 
ON documents (embedding)
ORGANIZATION NEIGHBOR GRAPH
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;HNSW enables sub-100ms retrieval at 95%+ recall—extremely fast for real-time applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;DML operations (insert, update, delete) are not allowed after creating an HNSW index—designed for read-heavy workloads.&lt;/p&gt;
&lt;p&gt;HNSW indexes are not available in RAC environments.&lt;/p&gt;
&lt;h5 id=&quot;2-ivf-neighbor-partition-index&quot;&gt;2. IVF: Neighbor Partition Index&lt;/h5&gt;
&lt;p&gt;&lt;strong&gt;Inverted File Flat (IVF)&lt;/strong&gt; indexes partition data points into clusters, enabling efficient searching within relevant clusters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;IVF Flat index is a Neighbor Partition Vector index built on disk, and its blocks are cached in the regular buffer cache.&lt;/p&gt;
&lt;p&gt;A significant advantage of an IVF vector index is that it is not constrained by the amount of memory available in the vector pool like an HNSW vector index is.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How IVF Works:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It is designed to enhance search efficiency by narrowing the search area through the use of neighbor partitions or clusters. The center of each partition, or the centroid, represents the average vector for each partition. By default, the number of partitions and their corresponding centroids is set to the square root of the dataset's size.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Creating IVF Index:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE VECTOR INDEX documents_ivf_idx 
ON documents (embedding)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Works with massive datasets&lt;/li&gt;
&lt;li&gt;Supports global and local indexes on partitioned tables&lt;/li&gt;
&lt;li&gt;DML operations can degrade accuracy over time. Periodically rebuilding the index may be necessary&lt;/li&gt;
&lt;li&gt;More memory-efficient than HNSW&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Although an IVF index won't be as fast as an equivalent HNSW index, it can be used for very large data sets and still provide excellent performance when compared to an exhaustive similarity search.&lt;/p&gt;
&lt;h5 id=&quot;3-hybrid-vector-indexes&quot;&gt;3. Hybrid Vector Indexes&lt;/h5&gt;
&lt;p&gt;Hybrid vector index combines full text and semantic search in one index, allowing users to easily index and query their documents using a combination of full text search and semantic vector search.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;br&gt;
When you need to match both semantic meaning AND specific keywords/terms in a single query.&lt;/p&gt;
&lt;h4 id=&quot;gpu-acceleration&quot;&gt;GPU Acceleration&lt;/h4&gt;
&lt;p&gt;At Oracle CloudWorld 2024, Oracle demonstrated GPU-accelerated creation of vector embeddings and HNSW index creation using NVIDIA GPUs.&lt;/p&gt;
&lt;p&gt;When a user sends a request to create an HNSW vector index to Oracle Database, the database intelligently compiles and redirects the task to a Compute Offload Server process that leverages GPUs and the CAGRA algorithm from NVIDIA cuVS library to rapidly generate a graph index.&lt;/p&gt;
&lt;h3 id=&quot;phase-5-retrieval---finding-relevant-context&quot;&gt;Phase 5: Retrieval - Finding Relevant Context&lt;/h3&gt;
&lt;p&gt;At runtime, when a user submits a query, the retrieval phase locates the most relevant chunks to provide as context to the LLM.&lt;/p&gt;
&lt;h4 id=&quot;query-embedding&quot;&gt;Query Embedding&lt;/h4&gt;
&lt;p&gt;The system encodes the user's query with the same model used to embed documents during ingestion.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Generate query embedding
SELECT VECTOR_EMBEDDING(minilm_l12_v2 USING 'What is RAG?' AS data) AS query_vector
FROM DUAL;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;similarity-search&quot;&gt;Similarity Search&lt;/h4&gt;
&lt;p&gt;The query vector is compared against all document vectors in the database using a distance metric.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Distance Metrics:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Common options include EUCLIDEAN, L2_SQUARED, COSINE, DOT, MANHATTAN, and HAMMING. You can specify the metric during index creation or within the search query itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cosine Similarity&lt;/strong&gt;: Most common for text (measures angle between vectors)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Euclidean Distance&lt;/strong&gt;: Straight-line distance in vector space&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dot Product&lt;/strong&gt;: Efficient for normalized vectors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Performing Similarity Search:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 
  text,
  VECTOR_DISTANCE(embedding, :query_vector, COSINE) AS distance
FROM documents
ORDER BY distance
FETCH APPROX FIRST 5 ROWS ONLY;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;top-k-results&quot;&gt;Top-K Results&lt;/h4&gt;
&lt;p&gt;The system searches the index for the nearest vectors, retrieves the top-k chunks, and includes those chunks with the query in the prompt.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Choosing K:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;K=3-5&lt;/strong&gt;: For focused, specific queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;K=10-20&lt;/strong&gt;: For broader research queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;K=50+&lt;/strong&gt;: For comprehensive document analysis&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Top-k returns near duplicates or shallow snippets, so the prompt lacks diversity. Retrieval misses proper nouns, IDs, or acronyms because they occur rarely.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reranking&lt;/strong&gt;: Rerank with cross-encoders (Cohere ReRank, ColBERT) when precision matters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid Search&lt;/strong&gt;: Combine BM25 (keyword) with dense vectors to boost tail recall&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metadata Filtering&lt;/strong&gt;: Filter by date, source, document type before retrieval&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;monitoring-index-accuracy&quot;&gt;Monitoring Index Accuracy&lt;/h4&gt;
&lt;p&gt;A valuable feature is Oracle's provision of functions to report index accuracy based on query vectors used in approximate searches. This allows you to continuously monitor and optimize the accuracy of your vector search implementation.&lt;/p&gt;
&lt;h3 id=&quot;phase-6-generation---creating-the-final-response&quot;&gt;Phase 6: Generation - Creating the Final Response&lt;/h3&gt;
&lt;p&gt;Once relevant chunks are retrieved, they're combined with the user's query and sent to an LLM for response generation.&lt;/p&gt;
&lt;h4 id=&quot;prompt-assembly&quot;&gt;Prompt Assembly&lt;/h4&gt;
&lt;p&gt;Retrieved chunks are formatted into a coherent context block:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Context:
[Chunk 1 text]
[Chunk 2 text]
[Chunk 3 text]

Question: [User query]

Answer based on the provided context:
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;llm-generation&quot;&gt;LLM Generation&lt;/h4&gt;
&lt;p&gt;The complete prompt (context + query) is sent to the LLM, which generates a response grounded in the retrieved information rather than relying solely on parametric knowledge.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reduces hallucinations&lt;/li&gt;
&lt;li&gt;Provides traceable sources&lt;/li&gt;
&lt;li&gt;Enables up-to-date information&lt;/li&gt;
&lt;li&gt;Maintains factual accuracy&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;best-practices-for-production-rag-pipelines&quot;&gt;Best Practices for Production RAG Pipelines&lt;/h3&gt;
&lt;h4 id=&quot;1-optimize-chunking-strategy&quot;&gt;1. Optimize Chunking Strategy&lt;/h4&gt;
&lt;p&gt;Align chunk size with context windows, use task-specific sentence transformers, and default to HNSW + metadata filtering for sub-100ms retrieval at 95%+ recall.&lt;/p&gt;
&lt;h4 id=&quot;2-choose-appropriate-embedding-models&quot;&gt;2. Choose Appropriate Embedding Models&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Match embedding dimensions to your dataset size&lt;/li&gt;
&lt;li&gt;Consider domain-specific models for specialized content&lt;/li&gt;
&lt;li&gt;Test multiple models and measure retrieval quality&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-implement-proper-indexing&quot;&gt;3. Implement Proper Indexing&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Small-Medium datasets (&amp;lt; 1M vectors)&lt;/strong&gt;: HNSW for maximum speed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Large datasets (1M+ vectors)&lt;/strong&gt;: IVF for scalability&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keyword + Semantic&lt;/strong&gt;: Hybrid vector indexes&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;4-monitor-and-iterate&quot;&gt;4. Monitor and Iterate&lt;/h4&gt;
&lt;p&gt;Monitor recall@k, latency, and index memory; re-embed on model upgrades.&lt;/p&gt;
&lt;p&gt;Track metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Retrieval accuracy (precision@k, recall@k)&lt;/li&gt;
&lt;li&gt;Query latency (p50, p95, p99)&lt;/li&gt;
&lt;li&gt;Index build time&lt;/li&gt;
&lt;li&gt;Storage requirements&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;5-handle-edge-cases&quot;&gt;5. Handle Edge Cases&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Query reformulation for better retrieval&lt;/li&gt;
&lt;li&gt;Fallback strategies when retrieval fails&lt;/li&gt;
&lt;li&gt;Confidence thresholds for generated responses&lt;/li&gt;
&lt;li&gt;Citation and source tracking&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;advanced-rag-techniques&quot;&gt;Advanced RAG Techniques&lt;/h3&gt;
&lt;h4 id=&quot;1-self-correction-crag-&quot;&gt;1. Self-Correction (CRAG)&lt;/h4&gt;
&lt;p&gt;When strong retrieval pipelines return incomplete or irrelevant context, CRAG adds a lightweight feedback loop: before generating, the system checks whether the retrieved set is good enough. If it looks weak, the system triggers another retrieval pass.&lt;/p&gt;
&lt;h4 id=&quot;2-agentic-rag&quot;&gt;2. Agentic RAG&lt;/h4&gt;
&lt;p&gt;Agentic RAG systems plan retrieval strategies and iterate based on partial results—dynamically deciding what to retrieve next.&lt;/p&gt;
&lt;h4 id=&quot;3-graphrag&quot;&gt;3. GraphRAG&lt;/h4&gt;
&lt;p&gt;Build an advanced RAG system by first structuring data into a knowledge graph, then layering graph-aware retrieval to capture entity relationships.&lt;/p&gt;
&lt;h4 id=&quot;4-multimodal-rag&quot;&gt;4. Multimodal RAG&lt;/h4&gt;
&lt;p&gt;Combining text, images, audio, and video retrieval for richer context.&lt;/p&gt;
&lt;p&gt;A robust RAG pipeline requires careful attention to every stage:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ingestion&lt;/strong&gt;: Clean, structured data with rich metadata&lt;br&gt;
&lt;strong&gt;Chunking&lt;/strong&gt;: Balanced chunk sizes with appropriate overlap (10-20%)&lt;br&gt;
&lt;strong&gt;Embedding&lt;/strong&gt;: Semantic representations using appropriate models&lt;br&gt;
&lt;strong&gt;Indexing&lt;/strong&gt;: Fast similarity search with HNSW or IVF indexes&lt;br&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt;: Accurate top-K results with metadata filtering&lt;br&gt;
&lt;strong&gt;Generation&lt;/strong&gt;: Grounded responses with proper citations&lt;/p&gt;
&lt;p&gt;Oracle Database 23ai provides a complete, integrated platform for RAG with native vector support, ONNX model runtime, advanced indexing (HNSW, IVF, Hybrid), and SQL-native operations—eliminating the need for separate vector databases.&lt;/p&gt;
&lt;p&gt;By mastering these components and following best practices, you can build production-grade RAG systems that deliver accurate, relevant, and trustworthy AI-powered experiences.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/10137/rag-pipeline-deep-dive-ingestion-chunking-embedding-and-vector-search</guid>
<pubDate>Wed, 21 Jan 2026 06:23:00 +0000</pubDate>
</item>
<item>
<title>Why a Vector Database Is Critical for Real AI Implementation</title>
<link>https://coderlegion.com/8481/why-a-vector-database-is-critical-for-real-ai-implementation</link>
<description>&lt;p&gt;AI is only useful when it answers with the right information.&lt;br&gt;
A vector database makes that possible.&lt;/p&gt;
&lt;p&gt;Instead of searching by keywords, it searches by meaning.&lt;br&gt;
That’s how AI finds the most relevant data from your docs, pages, chats, and files.&lt;/p&gt;
&lt;p&gt;Without a vector database:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AI guesses&lt;/li&gt;
&lt;li&gt;answers feel random&lt;/li&gt;
&lt;li&gt;hallucinations increase&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With a vector database:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;answers stay accurate&lt;/li&gt;
&lt;li&gt;context is preserved&lt;/li&gt;
&lt;li&gt;responses feel reliable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At byteoniclabs.com every serious AI system we build starts with a proper vector database, because that’s what turns AI from a chatbot into a business tool.&lt;/p&gt;
&lt;p&gt;If your AI gives mixed answers, your data layer is the first thing to fix.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/8481/why-a-vector-database-is-critical-for-real-ai-implementation</guid>
<pubDate>Mon, 15 Dec 2025 17:11:17 +0000</pubDate>
</item>
<item>
<title>OCI Introduction to AI: Transforming Enterprise Intelligence</title>
<link>https://coderlegion.com/5094/oci-introduction-to-ai-transforming-enterprise-intelligence</link>
<description>&lt;p&gt;Oracle Cloud Infrastructure (OCI) is revolutionizing how enterprises approach artificial intelligence, providing comprehensive AI services that integrate seamlessly with existing business processes. This introduction explores the fundamental concepts of AI, Oracle's AI ecosystem, and practical applications that are transforming modern enterprises.&lt;/p&gt;
&lt;h3 id=&quot;understanding-artificial-intelligence&quot;&gt;Understanding Artificial Intelligence&lt;/h3&gt;
&lt;p&gt;Artificial Intelligence represents the &lt;strong&gt;ability of machines to mimic cognitive abilities and problem-solving capabilities of humans&lt;/strong&gt;. This transformative technology has evolved from simple automation to sophisticated systems that can understand context, make decisions, and continuously improve their performance.&lt;/p&gt;
&lt;h4 id=&quot;how-ai-systems-learn&quot;&gt;How AI Systems Learn&lt;/h4&gt;
&lt;p&gt;AI systems demonstrate remarkable adaptability by &lt;strong&gt;learning new skills through observation&lt;/strong&gt;. This learning process involves:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pattern recognition&lt;/strong&gt; from large datasets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Algorithmic adaptation&lt;/strong&gt; based on feedback&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Continuous improvement&lt;/strong&gt; through iterative training&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Knowledge transfer&lt;/strong&gt; across different domains&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;artificial-general-intelligence-agi-&quot;&gt;Artificial General Intelligence (AGI)&lt;/h4&gt;
&lt;p&gt;While current AI is specialized, &lt;strong&gt;Artificial General Intelligence can mimic human skills, sensory and motor skills, and use these skills to carry out tasks without human interruption&lt;/strong&gt;. AGI represents the future where AI systems can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Understand context&lt;/strong&gt; across multiple domains&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perform complex reasoning&lt;/strong&gt; similar to human thought processes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adapt to new situations&lt;/strong&gt; without explicit programming&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrate multiple capabilities&lt;/strong&gt; for comprehensive problem-solving&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-modern-ai-revolution&quot;&gt;The Modern AI Revolution&lt;/h3&gt;
&lt;p&gt;Today's enterprises leverage AI for automation, decision-making, and creative support across numerous applications. The technology has moved beyond experimental phases to become essential for competitive advantage.&lt;/p&gt;
&lt;h4 id=&quot;ai-applications-across-industries&quot;&gt;AI Applications Across Industries&lt;/h4&gt;
&lt;p&gt;AI domains span a wide range of practical applications:&lt;/p&gt;
&lt;h5 id=&quot;communication-and-language&quot;&gt;Communication and Language&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Language translation&lt;/strong&gt;: Breaking down global communication barriers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text-to-speech&lt;/strong&gt;: Converting written content to natural-sounding audio&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Natural language processing&lt;/strong&gt;: Understanding and generating human-like text&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sentiment analysis&lt;/strong&gt;: Interpreting emotional context in communications&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;visual-intelligence&quot;&gt;Visual Intelligence&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Image classification&lt;/strong&gt;: Automatically categorizing and tagging visual content&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Computer vision&lt;/strong&gt;: Understanding and interpreting visual information&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Object detection&lt;/strong&gt;: Identifying specific items within images or video&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Facial recognition&lt;/strong&gt;: Secure identification and authentication systems&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;business-intelligence&quot;&gt;Business Intelligence&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Product recommendations&lt;/strong&gt;: Personalized suggestions based on behavior patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fraud detection&lt;/strong&gt;: Real-time identification of suspicious transactions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Predictive analytics&lt;/strong&gt;: Forecasting trends and outcomes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customer behavior analysis&lt;/strong&gt;: Understanding user preferences and patterns&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;autonomous-systems&quot;&gt;Autonomous Systems&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Self-driving cars&lt;/strong&gt;: Autonomous navigation and decision-making&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Robotic automation&lt;/strong&gt;: Intelligent manufacturing and logistics&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smart infrastructure&lt;/strong&gt;: Adaptive city and building management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Predictive maintenance&lt;/strong&gt;: Anticipating equipment failures before they occur&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;oracle-cloud-infrastructure-ai-services&quot;&gt;Oracle Cloud Infrastructure AI Services&lt;/h3&gt;
&lt;p&gt;OCI provides a comprehensive suite of AI services designed to accelerate enterprise AI adoption without requiring deep machine learning expertise.&lt;/p&gt;
&lt;h4 id=&quot;oci-generative-ai&quot;&gt;OCI Generative AI&lt;/h4&gt;
&lt;p&gt;OCI Generative AI service is a fully managed service that seamlessly integrates large language models (LLMs) from Cohere and Meta Llama 2 to address diverse business use cases. Key capabilities include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multilingual support&lt;/strong&gt;: Supporting over 100 languages&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text generation&lt;/strong&gt;: Creating human-like content for various purposes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Summarization&lt;/strong&gt;: Condensing large documents into key insights&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code generation&lt;/strong&gt;: Assisting developers with automated code creation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chat interfaces&lt;/strong&gt;: Building intelligent conversational experiences&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;oci-ai-agents&quot;&gt;OCI AI Agents&lt;/h4&gt;
&lt;p&gt;Oracle has expanded its AI offerings significantly, with over 50 AI agents and a new generative AI RAG Agent in OCI announced at CloudWorld 2024. These agents provide:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Specialized functionality&lt;/strong&gt; for specific business domains&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pre-built solutions&lt;/strong&gt; reducing development time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration capabilities&lt;/strong&gt; with existing enterprise systems&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customization options&lt;/strong&gt; for unique business requirements&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;machine-learning-services&quot;&gt;Machine Learning Services&lt;/h4&gt;
&lt;p&gt;Build, train, and deploy machine learning models. Or use AI services to add prebuilt chatbot, anomaly detection, NLP, and speech capabilities to applications and operations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AutoML&lt;/strong&gt;: Automated model building and optimization&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom model training&lt;/strong&gt;: Bring your own algorithms and data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Model deployment&lt;/strong&gt;: Scalable inference endpoints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MLOps integration&lt;/strong&gt;: Complete machine learning lifecycle management&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;select-ai-in-autonomous-database&quot;&gt;Select AI in Autonomous Database&lt;/h3&gt;
&lt;p&gt;Oracle Autonomous Database's Select AI feature represents a breakthrough in data accessibility, enabling business users to interact with their data using natural language.&lt;/p&gt;
&lt;h4 id=&quot;natural-language-query-interface&quot;&gt;Natural Language Query Interface&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Select AI uses your language to query data&lt;/strong&gt;, revolutionizing how users interact with databases. The DBMS_CLOUD_AI package, with Select AI, facilitates and configures the translation of natural language prompts to generate, run, explain SQL statements.&lt;/p&gt;
&lt;h4 id=&quot;how-select-ai-works&quot;&gt;How Select AI Works&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Select AI takes a question in natural language and translates it into SQL&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Natural language input&lt;/strong&gt;: Users ask questions in plain English&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intent interpretation&lt;/strong&gt;: AI understands the query requirements&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL generation&lt;/strong&gt;: Automatic creation of optimized database queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Result presentation&lt;/strong&gt;: Data returned in user-friendly formats&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query refinement&lt;/strong&gt;: &lt;strong&gt;You can keep refining your questions&lt;/strong&gt; for better results&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;interactive-learning&quot;&gt;Interactive Learning&lt;/h4&gt;
&lt;p&gt;Select AI combines the capabilities of Large Language Models (LLM) with metadata from your ADB schemas to enable database-specific SQL to be generated. This approach ensures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Context-aware queries&lt;/strong&gt; based on your specific database schema&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accurate results&lt;/strong&gt; tailored to your data structure&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Learning from interactions&lt;/strong&gt; to improve future responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domain-specific understanding&lt;/strong&gt; of your business terminology&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;vector-search-and-ai-integration&quot;&gt;Vector Search and AI Integration&lt;/h3&gt;
&lt;p&gt;Oracle Database 23ai introduces powerful vector capabilities that form the foundation of modern AI applications.&lt;/p&gt;
&lt;h4 id=&quot;vector-database-capabilities&quot;&gt;Vector Database Capabilities&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;SQL support for vector generation&lt;/strong&gt; enables developers to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Store vector embeddings&lt;/strong&gt; alongside traditional relational data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Perform similarity searches&lt;/strong&gt; using SQL syntax&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrate with machine learning pipelines&lt;/strong&gt; seamlessly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scale vector operations&lt;/strong&gt; using Oracle's proven database technology&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;supported-vector-data-types&quot;&gt;Supported Vector Data Types&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Vector data types are supported&lt;/strong&gt; natively in Oracle Database, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dense vectors&lt;/strong&gt;: Optimized for machine learning embeddings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sparse vectors&lt;/strong&gt;: Efficient storage for high-dimensional data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Binary vectors&lt;/strong&gt;: Specialized for specific AI applications&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexible dimensions&lt;/strong&gt;: Supporting various embedding models&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;approximate-search-indexes&quot;&gt;Approximate Search Indexes&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Approximate search indexes&lt;/strong&gt; provide fast similarity search capabilities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;High-performance queries&lt;/strong&gt; on large vector datasets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configurable accuracy&lt;/strong&gt;: Balance between speed and precision&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallel processing&lt;/strong&gt;: Leveraging Oracle's parallel query capabilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory optimization&lt;/strong&gt;: Efficient use of system resources&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;generative-ai-pipeline-integration&quot;&gt;Generative AI Pipeline Integration&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;AI Vector Search powers generative AI pipelines&lt;/strong&gt; by enabling:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt;: Implementing a complete Retrieval-Augmented Generation (RAG) pipeline&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contextual responses&lt;/strong&gt;: Grounding AI responses in your enterprise data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Real-time search&lt;/strong&gt;: Finding relevant information during conversations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-modal search&lt;/strong&gt;: Combining text, image, and structured data&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;advanced-ai-features-in-oracle-database-23ai&quot;&gt;Advanced AI Features in Oracle Database 23ai&lt;/h3&gt;
&lt;h4 id=&quot;comprehensive-ai-toolkit&quot;&gt;Comprehensive AI Toolkit&lt;/h4&gt;
&lt;p&gt;Leveraging Oracle Database 23ai technologies and assisted by AI, developers can focus on building app functionality instead of data infrastructure needs. The platform includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Integrated vector database&lt;/strong&gt;: Native support for AI workloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Machine learning algorithms&lt;/strong&gt;: Built-in ML capabilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Graph analytics&lt;/strong&gt;: Advanced relationship analysis&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JSON document support&lt;/strong&gt;: Flexible data modeling for AI applications&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;enterprise-grade-ai-infrastructure&quot;&gt;Enterprise-Grade AI Infrastructure&lt;/h4&gt;
&lt;p&gt;Oracle Database 23ai is available in Oracle Cloud Infrastructure (OCI) on Oracle Exadata Database Service, Oracle Exadata Cloud@Customer and Oracle Base Database Service, as well as on Oracle Database@Azure, ensuring:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;High availability&lt;/strong&gt;: Enterprise-grade reliability for AI workloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Handle growing AI data requirements&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: Protect sensitive AI models and training data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Optimized infrastructure for AI computations&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;real-world-ai-implementation-strategies&quot;&gt;Real-World AI Implementation Strategies&lt;/h3&gt;
&lt;h4 id=&quot;starting-your-ai-journey&quot;&gt;Starting Your AI Journey&lt;/h4&gt;
&lt;h5 id=&quot;identify-use-cases&quot;&gt;Identify Use Cases&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Process automation&lt;/strong&gt;: Streamline repetitive tasks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customer experience&lt;/strong&gt;: Enhance user interactions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data insights&lt;/strong&gt;: Extract value from existing data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operational efficiency&lt;/strong&gt;: Optimize resource utilization&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;build-ai-capabilities&quot;&gt;Build AI Capabilities&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Start with pre-built services&lt;/strong&gt;: Leverage Oracle's AI services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Develop custom models&lt;/strong&gt;: Build specialized solutions for unique needs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrate existing systems&lt;/strong&gt;: Connect AI with current business processes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Train your team&lt;/strong&gt;: Develop internal AI expertise&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;best-practices-for-enterprise-ai&quot;&gt;Best Practices for Enterprise AI&lt;/h4&gt;
&lt;h5 id=&quot;data-strategy&quot;&gt;Data Strategy&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data quality&lt;/strong&gt;: Ensure clean, well-organized training data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data governance&lt;/strong&gt;: Implement proper data management policies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Privacy compliance&lt;/strong&gt;: Maintain regulatory compliance for AI systems&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data integration&lt;/strong&gt;: Connect disparate data sources effectively&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;infrastructure-planning&quot;&gt;Infrastructure Planning&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scalable architecture&lt;/strong&gt;: Design for growing AI workloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security framework&lt;/strong&gt;: Protect AI models and data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance monitoring&lt;/strong&gt;: Track AI system effectiveness&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cost optimization&lt;/strong&gt;: Manage AI infrastructure expenses&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;oracle-s-ai-ecosystem-advantages&quot;&gt;Oracle's AI Ecosystem Advantages&lt;/h3&gt;
&lt;h4 id=&quot;integrated-platform&quot;&gt;Integrated Platform&lt;/h4&gt;
&lt;p&gt;Oracle provides a complete AI ecosystem that eliminates the complexity of managing multiple vendors and integration points:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Single vendor solution&lt;/strong&gt;: Unified support and accountability&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Seamless integration&lt;/strong&gt;: Built-in connectivity between AI services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistent security&lt;/strong&gt;: Unified security model across all components&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplified management&lt;/strong&gt;: Single control plane for AI operations&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;enterprise-focus&quot;&gt;Enterprise Focus&lt;/h4&gt;
&lt;p&gt;Oracle's AI solutions are designed specifically for enterprise requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Regulatory compliance&lt;/strong&gt;: Built-in features for industry regulations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High availability&lt;/strong&gt;: Enterprise-grade uptime guarantees&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalable architecture&lt;/strong&gt;: Handle enterprise-scale workloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Professional support&lt;/strong&gt;: Dedicated support for mission-critical AI applications&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-future-of-ai-in-enterprise&quot;&gt;The Future of AI in Enterprise&lt;/h3&gt;
&lt;h4 id=&quot;emerging-trends&quot;&gt;Emerging Trends&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multimodal AI&lt;/strong&gt;: Systems that process text, images, and audio simultaneously&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Autonomous operations&lt;/strong&gt;: Self-managing AI systems requiring minimal human intervention&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ethical AI&lt;/strong&gt;: Responsible AI development with built-in bias detection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Edge AI&lt;/strong&gt;: Bringing AI capabilities closer to data sources&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;oracle-s-ai-roadmap&quot;&gt;Oracle's AI Roadmap&lt;/h4&gt;
&lt;p&gt;Oracle continues to invest heavily in AI innovation, with recent developments including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Enhanced vector search&lt;/strong&gt;: More sophisticated similarity algorithms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Expanded language models&lt;/strong&gt;: Additional LLM options and capabilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Improved automation&lt;/strong&gt;: Reduced complexity for AI implementation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Industry-specific solutions&lt;/strong&gt;: Tailored AI applications for vertical markets&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;conclusion-1&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Oracle Cloud Infrastructure's approach to AI combines cutting-edge technology with enterprise-grade reliability and security. From Select AI's natural language database queries to comprehensive vector search capabilities, OCI provides the tools enterprises need to harness artificial intelligence effectively.&lt;/p&gt;
&lt;p&gt;The integration of AI capabilities directly into Oracle Database 23ai, combined with powerful cloud-native AI services, creates an ecosystem where organizations can build sophisticated AI applications without the complexity traditionally associated with artificial intelligence implementations.&lt;/p&gt;
&lt;p&gt;Whether you're just beginning your AI journey or looking to scale existing AI initiatives, Oracle's comprehensive AI platform provides the foundation for transforming your business through intelligent automation, enhanced decision-making, and innovative customer experiences.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ready to explore AI capabilities in your organization? Start with Oracle's pre-built AI services to gain immediate value, then expand into custom AI solutions as your team develops expertise with the platform.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://coderlegion.com/5094/oci-introduction-to-ai-transforming-enterprise-intelligence</guid>
<pubDate>Fri, 29 Aug 2025 14:52:46 +0000</pubDate>
</item>
<item>
<title>The Future of Search: How AI is Revolutionizing Online Discovery</title>
<link>https://coderlegion.com/954/the-future-of-search-how-ai-is-revolutionizing-online-discovery</link>
<description>&lt;p&gt;Have you ever wondered how search engines like Google are changing with the rise of artificial intelligence (AI)? Platforms like ChatGPT and Perplexity are leading the way in this new era of search. For SEO experts, this shift presents a huge opportunity to adapt and thrive.&lt;/p&gt;
&lt;p&gt;The impact of AI-powered search tools is already evident. We experienced a significant increase in website traffic from ChatGPT at the end of 2024.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5646696660236237374&quot; alt=&quot;AI powered search tools&quot;&gt;&lt;/p&gt;
&lt;p&gt;But standing out in this new search landscape requires more than just traditional SEO tactics. AI search operates differently, prioritizing conversational queries and delivering more dynamic results.&lt;/p&gt;
&lt;p&gt;So, how can you ensure your website gets noticed and attracts traffic in this AI-driven age? In this article, I'll break down the different types of AI search platforms, provide tips for optimizing your content for search engines and large language models (LLMs), and equip you with the tools you need to succeed. Let's get started!&lt;/p&gt;
&lt;h2&gt;How AI search differs from conventional search engines&lt;/h2&gt;
&lt;p&gt;AI-powered search tools like ChatGPT function in a unique way compared to traditional search engines such as Google. These platforms rely on large language models (LLMs) to process queries and generate results. Here's a simple explanation:&lt;/p&gt;
&lt;h3&gt;Query processing&lt;/h3&gt;
&lt;p&gt;While search engines rank web pages based on relevance, AI tools like ChatGPT use pre-trained LLMs to understand user intent and provide answers. Instead of fetching real-time results from the web, LLMs predict responses based on their extensive training data, resulting in highly contextual and conversational outputs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8377164363585723690&quot; alt=&quot;How AI works&quot;&gt;&lt;/p&gt;
&lt;h3&gt;Results format&lt;/h3&gt;
&lt;p&gt;Google displays a list of links, snippets, and rich results for users to explore. AI tools, on the other hand, offer direct, conversational answers that save time but may reduce the need for multiple clicks.&lt;/p&gt;
&lt;h3&gt;Freshness of information&lt;/h3&gt;
&lt;p&gt;Search engines constantly update their index to reflect the latest content. AI search tools, unless connected to live updates, rely on the data within their LLMs, which can sometimes lead to outdated information.&lt;/p&gt;
&lt;h3&gt;Transparency&lt;/h3&gt;
&lt;p&gt;Google provides links to original sources for verification. Similarly, ChatGPT Search, when linked to browsing capabilities, includes source links for the information it provides. This helps users trace the origin of the answers. However, when ChatGPT operates without live browsing, it does not directly cite sources.&lt;/p&gt;
&lt;p&gt;To optimize for both traditional search engines and AI platforms, you need to create content that is clear, authoritative, and rich in context. This type of content is easily processed by AI and can be incorporated into search results effectively.&lt;/p&gt;
&lt;h2&gt;Understanding different types of AI search&lt;/h2&gt;
&lt;p&gt;Various AI-powered search platforms have emerged, each with its unique strengths and approaches, driven by major tech companies. Let's take a closer look at some of the key players in the market.&lt;/p&gt;
&lt;h3&gt;ChatGPT search&lt;/h3&gt;
&lt;p&gt;Developed by OpenAI, ChatGPT revolutionizes the search experience by providing direct, conversational responses to user queries. Users can refine their questions in real-time, turning a single query into an ongoing conversation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1197255425518274978&quot; alt=&quot;chatGPT&quot;&gt;&lt;/p&gt;
&lt;p&gt;ChatGPT quickly gained popularity, reaching over 100 million users within two months of its launch in November 2022. By late 2024, it had over 300 million weekly active users, generating over 1 billion messages daily.&lt;/p&gt;
&lt;p&gt;How it delivers search results: ChatGPT is powered by OpenAI's GPT-4 model, an LLM trained on vast text datasets. It doesn't crawl the web in real-time but relies on its pre-trained knowledge, periodically updated. When connected to live search capabilities, it provides real-time results and cites sources, offering a hybrid search experience.&lt;/p&gt;
&lt;h3&gt;Google's AI Overviews&lt;/h3&gt;
&lt;p&gt;Google AI Overviews integrate AI-powered summaries directly into search results, offering users quick insights by consolidating information from reliable sources. These summaries appear above traditional search listings, providing concise answers to help users find information efficiently.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=18355561474821714645&quot; alt=&quot;Google AI summaries&quot;&gt;&lt;/p&gt;
&lt;p&gt;How it works: Google AI Overviews utilize the advanced Gemini AI model, previously known as Bard, along with Google's Knowledge Graph. By analyzing content from authoritative sources, it generates precise summaries based on factors like search intent, semantic relevance, and content credibility.&lt;/p&gt;
&lt;h3&gt;Google Gemini&lt;/h3&gt;
&lt;p&gt;Gemini, developed by Google, is a generative AI chatbot that aims to compete with platforms like ChatGPT. Google plans to integrate Gemini more deeply into its products by 2025, leveraging its capabilities in language and visual processing.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=4984641558178014398&quot; alt=&quot;Google Gemini&quot;&gt;&lt;/p&gt;
&lt;p&gt;How it delivers search results: Gemini combines Google's search algorithms with AI-powered technology to provide interactive, multimedia-rich answers, going beyond text-based responses.&lt;/p&gt;
&lt;h3&gt;Bing AI search&lt;/h3&gt;
&lt;p&gt;Microsoft's Bing has positioned itself as an AI-powered alternative to Google, incorporating OpenAI's GPT technology. Bing offers conversational AI features alongside traditional search results, emphasizing its commitment to AI-driven search.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11653810669282923461&quot; alt=&quot;Bing AI&quot;&gt;&lt;/p&gt;
&lt;p&gt;How it delivers search results: Bing AI utilizes OpenAI's GPT-4 model to provide conversational answers and real-time web results. Unlike ChatGPT, Bing actively retrieves and ranks web pages while offering AI-generated summaries.&lt;/p&gt;
&lt;h3&gt;Other major players&lt;/h3&gt;
&lt;p&gt;Apple's AI-driven Spotlight offers web search capabilities directly on devices, personalizing results based on user behavior within the Apple ecosystem. Meta's AI-powered search focuses on personalized content discovery within its social platforms, while Amazon's AI search enhances eCommerce with personalized product recommendations.&lt;/p&gt;
&lt;p&gt;In China and Russia, Baidu and Yandex lead AI searches, catering to region-specific results and integrating localized content and cultural nuances.&lt;/p&gt;
&lt;h2&gt;AI search optimization strategies: keyword research, content, and beyond&lt;/h2&gt;
&lt;p&gt;Now that we've covered the major AI search platforms, let's discuss practical strategies for optimizing your website to attract traffic in this evolving landscape.&lt;/p&gt;
&lt;p&gt;To stay ahead in the AI-driven search environment, focus on mastering key strategies such as keyword research, creating high-quality content, and adapting to the changing search landscape.&lt;/p&gt;
&lt;h4 id=&quot;1-master-keyword-research-for-conversational-queries&quot;&gt;&lt;strong&gt;1. Master Keyword Research for Conversational Queries&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;AI search platforms are designed to understand natural, conversational language, which makes traditional keyword tactics less effective. Instead of focusing solely on high-volume, generic terms, adapt your approach to match how users naturally phrase their queries.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Focus on Questions and Long-Tail Keywords&lt;/strong&gt;&lt;br&gt;
AI tools can handle more specific and detailed queries. Use tools like Rank Tracker to find question-based and long-tail keywords. Start with the Related Questions tool, then gather more ideas from ranking keywords and autocomplete suggestions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13094608586737514947&quot; alt=&quot;long-tail keywords&quot;&gt;  &lt;/p&gt;
&lt;p&gt;If you already have a large list of keywords in your project and want to view only the long-tail phrases, you can apply the keyword length filter and then sort them by search volume or keyword difficulty.  &lt;/p&gt;
&lt;div class=&quot;div-green&quot;&gt;
&lt;span class=&quot;alert-header&quot;&gt;Tip: Think Like Your Audience &lt;/span&gt; 
&lt;span class=&quot;alert-body&quot;&gt;AI queries mimic how people speak. Explore “how-to” questions, comparisons, and specific needs to align with user intent. &lt;/span&gt;
&lt;/div&gt; 
&lt;h4 id=&quot;2-optimize-content-for-ai-friendliness&quot;&gt;&lt;strong&gt;2. Optimize Content for AI Friendliness&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Producing well-researched, insightful content that establishes authority increases your chances of being referenced by AI-powered search engines. A strong foundation is aligning your content strategy with Google’s E-E-A-T principles: Experience, Expertise, Authoritativeness, and Trustworthiness. These guidelines emphasize the importance of creating content that both informs and builds credibility with users and search algorithms.  &lt;/p&gt;
&lt;p&gt;Once you have E-E-A-T in mind, shift your focus to crafting valuable, actionable content that resonates with your audience. Your content should go beyond surface-level information and include elements that enhance its credibility, such as: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Expert Insights:&lt;/strong&gt; Incorporate quotes or perspectives from industry professionals to lend credibility and context.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Citations from Authoritative Sources:&lt;/strong&gt; Reference reliable studies and reports to strengthen your claims.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Balanced Viewpoints (Pros and Cons):&lt;/strong&gt; Presenting a well-rounded discussion makes your content more comprehensive and trustworthy.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data-Backed Analysis:&lt;/strong&gt; Use statistics and case studies to provide tangible evidence supporting key arguments.  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, align your content with search intent—the underlying reason behind a user's query. Whether someone is looking for information, a product, or a solution to a problem, your content should anticipate and fulfill their needs. Failing to match search intent can result in high bounce rates and lost opportunities.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Work on Your Content Format and Structure:&lt;/strong&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use a Question-Answer Format:&lt;/strong&gt; Write headings and subheadings as questions to match AI-generated responses. &lt;br&gt;
For example, use “How does AI search work?” instead of “AI Search Overview.” &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8674181457790597450&quot; alt=&quot;Brand monitoring&quot;&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Be Concise and Direct:&lt;/strong&gt; AI platforms summarize content, so lead with short, valuable answers and follow up with more details. For instance, start with a 2-3 sentence summary, then expand with supporting information.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Structure Content Clearly:&lt;/strong&gt; Use bullet points, numbered lists, and clear subheadings. AI favors well-organized content that’s easy to extract and present.  &lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-optimize-for-featured-snippets&quot;&gt;&lt;strong&gt;3. Optimize for Featured Snippets&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Featured snippets are a key entry point for AI platforms like Google AIO. To increase your chances of being featured:  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=3985316266625855386&quot; alt=&quot;Featured Snippets&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Answer Questions Clearly and Succinctly:&lt;/strong&gt; Provide a direct, concise response at the start of your content, followed by supporting details.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Structured Data:&lt;/strong&gt; Mark up your content with FAQ schema to make it more snippet-friendly.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write Snippable Paragraphs and Lists:&lt;/strong&gt; Ensure to include lists and short paragraphs that Google could use to generate a featured snippet. For example, instead of burying the answer in paragraphs, you could start with: “The best laptops for video editing in 2025 are [Brand A] and [Brand B].” Then expand with features and comparisons.  &lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;4-focus-on-entities-and-topics-for-google-s-knowledge-graph&quot;&gt;&lt;strong&gt;4. Focus on Entities and Topics for Google’s Knowledge Graph&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Google’s Knowledge Graph plays a significant role in AI search, helping to connect entities like people, brands, and locations with related concepts. Optimizing for entities ensures Google understands your content in context.  &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5518707262929031021&quot; alt=&quot;Google Knowledge Graph&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How to Align with the Knowledge Graph:&lt;/strong&gt;  &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use Precise Terminology:&lt;/strong&gt; Clearly define and mention entities (brand names, product categories, locations) in your content to enhance relevance.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Develop Content Clusters:&lt;/strong&gt; Build comprehensive, interlinked content around core topics to signal topical authority.  &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Leverage Structured Data:&lt;/strong&gt; As mentioned earlier, use schema markup (such as Organization, Product, and Event schema) to provide additional context about your content.  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Focusing on entities improves your chances of appearing in AI-generated summaries and carousel-style search results.&lt;/p&gt;
&lt;h4 id=&quot;5-gain-mentions-and-reviews&quot;&gt;&lt;strong&gt;5. Gain Mentions and Reviews&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;AI search engines consider brand mentions and user-generated content as credibility signals. Building a strong digital presence through mentions and reviews can boost your search visibility. Here’s how to do it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Monitor Mentions:&lt;/strong&gt; Use tools like Awario to create alerts for your brand name and target keywords to discover what people are saying about you.  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5112906561699319678&quot; alt=&quot;Monitor mentions&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;6-leverage-content-diversity&quot;&gt;&lt;strong&gt;6. Leverage content diversity&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;AI search engines prioritize multimedia-rich content, which enhances engagement and provides more comprehensive answers. Expanding beyond text can improve visibility and reach.&lt;br&gt;
Content formats to consider:&lt;br&gt;
Video tutorials, explainers, and interviews can rank in AI-generated results.&lt;br&gt;
Infographics and visuals: simplify complex topics with engaging visual content.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8656735664460563630&quot; alt=&quot;infographics&quot;&gt;&lt;/p&gt;
&lt;p&gt;Audio content: Podcasts and audio summaries resonate with voice search users and multitaskers.&lt;br&gt;
Diversifying your content portfolio ensures your information is accessible across different AI search formats.&lt;/p&gt;
&lt;h4 id=&quot;7-optimize-for-technical-seo&quot;&gt;&lt;strong&gt;7. Optimize for technical SEO&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Even in the AI era, a strong technical SEO foundation remains crucial. Ensuring your site is technically sound allows AI-powered search engines to crawl and interpret your content efficiently.&lt;br&gt;
Here’s what you can do to improve your technical SEO:&lt;br&gt;
Fix crawl errors: regular audits with WebSite Auditor can help you identify and resolve crawl and indexing issues.&lt;br&gt;
Enhance page speed: use tools like PageSpeed Insights to identify and fix slow-loading elements.&lt;br&gt;
Ensure mobile-friendliness: responsive design is critical, as AI search is heavily used on mobile devices.&lt;br&gt;
Make sure your content is interconnected through strategic internal linking, guiding AI models to understand content hierarchies and topical relevance.&lt;br&gt;
A technically optimized site enhances your chances of appearing in AI-powered search results and improves user experience.&lt;/p&gt;
&lt;h3 id=&quot;conclusion-2&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;AI-powered search engines are reshaping the SEO landscape, favoring conversational queries, multimedia content, and well-structured answers. Whether you’re optimizing for ChatGPT’s conversational responses, Google AIO’s featured snippets, or Google’s Knowledge Graph entities, the strategies remain rooted in creating user-focused, authoritative, and technically sound content.&lt;br&gt;
By adopting these best practices, you’ll position your website to succeed not just in traditional search engines but also in the evolving world of AI-driven platforms. The key is to stay adaptable, keep your content valuable, and always think ahead to meet the needs of AI-powered search users.&lt;/p&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/954/the-future-of-search-how-ai-is-revolutionizing-online-discovery</guid>
<pubDate>Tue, 28 Jan 2025 07:56:13 +0000</pubDate>
</item>
<item>
<title>Beyond Elasticsearch: The Rise of Unified Vector and Keyword Search</title>
<link>https://coderlegion.com/887/beyond-elasticsearch-the-rise-of-unified-vector-and-keyword-search</link>
<description>&lt;p&gt;This post was written by &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.linkedin.com/in/xiaofan-james-luan-37012872/&quot;&gt;James Luan&lt;/a&gt;, VP of Engineering at &lt;a rel=&quot;nofollow&quot; href=&quot;https://zilliz.com/&quot;&gt;Zilliz&lt;/a&gt; and key maintainer of the Milvus open source project.&lt;/p&gt;
&lt;h2 id=&quot;the-evolution-of-modern-search-architecture&quot;&gt;The Evolution of Modern Search Architecture&lt;/h2&gt;
&lt;p&gt;You're debugging a critical production issue, and you know the solution exists in your documentation. Your vector search returns semantically relevant results about error handling and system recovery but somehow misses that one crucial Stack Overflow answer you saved last month with the exact error code. Sound familiar?&lt;/p&gt;
&lt;p&gt;This common frustration highlights a fundamental challenge in modern search technology: the need to balance semantic understanding with precise term matching. The rise of AI and large language models has brought powerful semantic search capabilities through vector embeddings while revealing the continued importance of traditional keyword matching. When supporting customers, for instance, vector search brilliantly handles natural language queries like &quot;my payment isn't going through&quot; by understanding user intent. Still, keyword search remains essential for matching specific product codes and error messages.&lt;/p&gt;
&lt;p&gt;Recent experiences with &lt;a rel=&quot;nofollow&quot; href=&quot;https://zilliz.com/learn/Retrieval-Augmented-Generation&quot;&gt;RAG&lt;/a&gt; implementations across the industry have revealed interesting insights about search technology. While dense vector embeddings excel at capturing semantic relationships and contextual understanding, traditional &lt;a rel=&quot;nofollow&quot; href=&quot;https://zilliz.com/learn/mastering-bm25-a-deep-dive-into-the-algorithm-and-application-in-milvus&quot;&gt;BM25&lt;/a&gt; keyword matching still proves superior in certain scenarios, particularly with domain-specific queries and rare terms. This complementary strength of different search approaches has pushed the community toward exploring unified solutions.&lt;/p&gt;
&lt;p&gt;However, implementing hybrid search at scale presents its own set of challenges. While frameworks like LangChain or LlamaIndex have made proof-of-concept implementations straightforward, scaling these solutions to production reveals significant architectural complexities. The conventional approach requires maintaining separate vector databases and search engines, resulting in the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Data redundancy across multiple storage systems&lt;/li&gt;
&lt;li&gt;Complex consistency management between separate indices&lt;/li&gt;
&lt;li&gt;Fragmented security controls and access patterns&lt;/li&gt;
&lt;li&gt;Increased latency due to cross-system synchronization&lt;/li&gt;
&lt;li&gt;Higher operational complexity in high-throughput environments&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15354306068231238477&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;An Example of Complex Architectures of Hybrid Search&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;elasticsearch-s-technical-limitations&quot;&gt;Elasticsearch's Technical Limitations&lt;/h2&gt;
&lt;p&gt;As the long-standing leader in enterprise search, Elasticsearch has powered everything from e-commerce platforms to logging systems for over a decade. Their dominance in keyword-based search and their extensive enterprise feature set, made them an obvious candidate for bridging the gap between traditional and AI-powered search. Recognizing this opportunity, Elasticsearch made a significant move by introducing vector search capabilities in version 8.0, aiming to unify traditional keyword search with modern vector operations under a single platform.&lt;/p&gt;
&lt;p&gt;However, despite its market leadership and ambitious steps toward vector search capabilities, Elasticsearch faces several fundamental constraints that impact its effectiveness in modern search architectures:&lt;/p&gt;
&lt;h4 id=&quot;performance-and-resource-management&quot;&gt;Performance and Resource Management&lt;/h4&gt;
&lt;p&gt;The tight coupling between write operations, index construction, and query processing creates substantial overhead during data ingestion and indexing. This architectural decision leads to CPU and I/O contention, particularly during bulk updates. The &quot;near real-time&quot; search design introduces latency that can impair AI applications requiring rapid interactions or dynamic decision-making.&lt;/p&gt;
&lt;h4 id=&quot;architectural-constraints&quot;&gt;Architectural Constraints&lt;/h4&gt;
&lt;p&gt;The JVM-based architecture introduces additional complexity through memory management overhead and garbage collection pauses. Organizations often find themselves over-provisioning resources to maintain stable performance as data volumes grow. The non-cloud-native design, with tightly coupled storage and compute, requires simultaneous scaling of both resources, reducing deployment flexibility.&lt;/p&gt;
&lt;h4 id=&quot;scaling-limitations&quot;&gt;Scaling Limitations&lt;/h4&gt;
&lt;p&gt;The shard management system presents a fundamental dilemma: too many shards in small datasets lead to performance degradation. However, too few shards in large datasets limit scalability and cause data distribution imbalances. In multi-replica scenarios, the requirement for independent index construction per shard multiplies compute costs and reduces resource efficiency.&lt;/p&gt;
&lt;h4 id=&quot;vector-search-performance&quot;&gt;Vector Search Performance&lt;/h4&gt;
&lt;p&gt;The vector search implementation, built on Lucene's core, shows notable performance gaps compared to specialized engines, particularly in high-dimensional spaces. Internal benchmarks indicate performance degradation becomes acute beyond 128 dimensions, with query latency increasing exponentially in high-concurrency scenarios.&lt;/p&gt;
&lt;h2 id=&quot;technical-innovation-a-new-approach-to-unified-search&quot;&gt;Technical Innovation: A New Approach to Unified Search&lt;/h2&gt;
&lt;p&gt;Recent advances in search technology have emerged from extensive experience with real-world search challenges across thousands of production deployments. A consistent pattern has emerged through deep engagement with the open-source community. While vector search excels at semantic matching, organizations often need to maintain separate systems for traditional keyword search, leading to architectural complexities and operational overhead.&lt;/p&gt;
&lt;p&gt;This insight led to a fundamental reimagining of how unified search capabilities could work in the open source vector database &lt;a rel=&quot;nofollow&quot; href=&quot;https://zilliz.com/what-is-milvus&quot;&gt;Milvus&lt;/a&gt;. The result is Sparse-BM25, introduced by Milvus 2.5, an enhanced approach that leverages vector operations while preserving the precision of traditional keyword matching. This technical innovation builds on Milvus's expertise in vector operations while addressing the broader community's need for unified search capabilities.&lt;/p&gt;
&lt;h4 id=&quot;core-technical-architecture&quot;&gt;Core Technical Architecture&lt;/h4&gt;
&lt;p&gt;The implementation introduces several key technical innovations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advanced text processing pipeline powered by Tantivy, delivering&lt;br&gt;
sophisticated stemming, lemmatization, and stop word filtering&lt;br&gt;
capabilities with support for over 30 languages&lt;/li&gt;
&lt;li&gt;Distributed term frequency management system that efficiently handles&lt;br&gt;
corpus-wide statistics at scale, with automatic rebalancing and&lt;br&gt;
optimization&lt;/li&gt;
&lt;li&gt;Novel sparse vector generation utilizing Corpus TF for documents and&lt;br&gt;
Query TF with global IDF for queries, optimized for high-cardinality&lt;br&gt;
vocabularies&lt;/li&gt;
&lt;li&gt;Custom BM25 distance function optimized for high-dimensional sparse&lt;br&gt;
vector spaces, with configurable saturation parameters&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The system implements a sophisticated indexing hierarchy that adapts to query patterns. The WAND-based inverted index provides efficient retrieval for standard queries, while the Block-Max WAND algorithm development promises further optimization for long-tail queries. Through careful pruning of long-tail terms and vector quantization, the system achieves more than 5x performance improvement while keeping recall degradation under 1% and reducing memory usage by over 50%.&lt;/p&gt;
&lt;p&gt;The graph index support extends beyond basic HNSW implementation, incorporating dynamic graph pruning and rebuilding based on query patterns. This approach has shown particular effectiveness in handling high-dimensional sparse vectors, where traditional inverted indices struggle with the curse of dimensionality. The system automatically maintains optimal graph connectivity while minimizing index maintenance overhead.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2326955108801626135&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;technical-advances-in-modern-search-systems&quot;&gt;Technical Advances in Modern Search Systems&lt;/h3&gt;
&lt;h5 id=&quot;algorithm-flexibility&quot;&gt;Algorithm Flexibility&lt;/h5&gt;
&lt;p&gt;Modern search systems transform similarity calculations into vector distance computations, enabling more complex queries and corpus distance analysis. Recent research like &quot;End-to-End Query Term Weighting&quot; has introduced innovations such as the Term Weighting BERT (TW-BERT) algorithm, which uses BERT to infer n-gram term weights from queries and construct query representations. When combined with BM25 for calculating document relevance, these approaches demonstrate significant improvements over traditional token-based methods in both in-domain and out-of-domain scenarios.&lt;/p&gt;
&lt;h5 id=&quot;efficiency-considerations&quot;&gt;Efficiency Considerations&lt;/h5&gt;
&lt;p&gt;Advanced search architectures implement lexical search through sparse vectors, combining traditional inverted index compression techniques with lossy compression for dense embeddings. Through careful pruning of long-tail terms and vector quantization, these systems can achieve substantial performance improvements while maintaining high recall rates and reducing resource usage. Ongoing research continues to optimize data compression to further reduce storage costs and query I/O overhead.&lt;/p&gt;
&lt;h5 id=&quot;handling-complex-queries&quot;&gt;Handling Complex Queries&lt;/h5&gt;
&lt;p&gt;While traditional search engines commonly use WAND (Weak AND) technology to optimize inverted index queries, its effectiveness can diminish with long queries due to excessive inverted list intersections and reduced pruning efficiency. Modern approaches address this by combining sparse embeddings with graph indices like HNSW, showing particular promise for sparse vectors with high dimensionality.&lt;/p&gt;
&lt;p&gt;These technical advances in unified vector and keyword search are particularly significant for RAG applications, where queries often combine natural language questions with specific technical terms or metadata filters. Efficiently processing these mixed queries while maintaining high performance is crucial for production deployments.&lt;/p&gt;
&lt;h2 id=&quot;looking-forward-the-future-of-search&quot;&gt;Looking Forward: The Future of Search&lt;/h2&gt;
&lt;p&gt;Remember that frustrated developer from our opening scenario? Today's reality is that teams shouldn't have to choose between semantic understanding and precise matching, performance and flexibility, or simplicity and scale. As our industry continues to push the boundaries of AI and search technology, we're moving toward a future where search infrastructure becomes truly intelligent - understanding not just what users are searching for but why they're searching for it.&lt;/p&gt;
&lt;p&gt;The next frontier isn't just about combining vector and keyword search - it's about creating systems that can dynamically adapt to different types of queries, learn from user interactions, and seamlessly integrate with the growing ecosystem of AI tools and frameworks. As we continue to build and experiment with these technologies in Milvus, we're not just solving technical challenges - we're reshaping how humans interact with and make sense of the vast amounts of information at our disposal.&lt;/p&gt;
&lt;p&gt;This is an incredibly exciting time for the developers and engineers working on these challenges every day. The tools and capabilities we're building today will form the foundation of how future generations will access and understand information. And that's worth getting right.&lt;/p&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://coderlegion.com/887/beyond-elasticsearch-the-rise-of-unified-vector-and-keyword-search</guid>
<pubDate>Wed, 22 Jan 2025 11:21:23 +0000</pubDate>
</item>
</channel>
</rss>