<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[db-one - Medium]]></title>
        <description><![CDATA[Data stories… - Medium]]></description>
        <link>https://medium.com/db-one?source=rss----e060f4a5c6da---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>db-one - Medium</title>
            <link>https://medium.com/db-one?source=rss----e060f4a5c6da---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:32:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/db-one" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Pluggable Database Security++ ]]></title>
            <link>https://medium.com/db-one/pluggable-database-security-32d8cfc448b6?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/32d8cfc448b6</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Thu, 26 Nov 2026 16:48:29 GMT</pubDate>
            <atom:updated>2026-11-26T20:27:18.207Z</atom:updated>
            <content:encoded><![CDATA[<p>Did you know you could easily improve the security posture of your pluggable database?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJZ-FWvXTTtnod3WSez2EQ.png" /></figure><p>In version 12cR2 <em>(2017)</em> of the Oracle database, the new <a href="https://docs.oracle.com/en/database/oracle/oracle-database/12.1/newft/new-features.html#GUID-53A16664-8460-4EF5-8BF2-C062474070B8"><strong>PDB LOCK DOWN PROFILE</strong></a> was introduced!</p><p>So your pluggable database (understand the Oracle database your application connects to) exists within a Container Database (aka CDB).</p><p>Several PDBs can coexist within the CDB and ops DBAs may want to ensure you don’t mess with the resources that would annoy other PDBs… :)</p><p><strong>Introducing PDB Lockdown Profiles</strong></p><p>Basically, you start by creating a <a href="https://docs.oracle.com/en/database/oracle/oracle-database/26/dbseg/restricting-operations-pdbs-using-pdb-lockdown-profiles.html">PDB lockdown profile</a> at the CDB level:</p><pre>create lockdown profile secured_pdbs;</pre><p>And then you enable/disable privileged commands:</p><pre>alter lockdown profile secured_pdbs DISABLE feature=(&#39;UTL_FILE&#39;);<br>alter lockdown profile secured_pdbs DISABLE feature=(&#39;UTL_HTTP&#39;);<br>alter lockdown profile secured_pdbs DISABLE statement=(&#39;ALTER DATABASE&#39;);<br>alter lockdown profile secured_pdbs DISABLE statement=(&#39;ALTER SYSTEM&#39;) clause=(&#39;KILL SESSION&#39;);<br>alter lockdown profile secured_pdbs ENABLE statement=(&#39;ALTER SYSTEM&#39;) clause=(&#39;CANCEL SQL&#39;);<br>...</pre><p>Last, you configure PDBs to use this lockdown profile!</p><pre>-- At the PDB level<br>alter session set container=my_pdb;<br>alter system set pdb_lockdown=SECURED_PDBS sid=&#39;*&#39; scope=both;</pre><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32d8cfc448b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/pluggable-database-security-32d8cfc448b6">Pluggable Database Security++ 👮</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laya System One, powered by the FREE Oracle AI Database 26ai]]></title>
            <link>https://medium.com/db-one/laya-system-one-powered-by-the-free-oracle-ai-database-26ai-e58dd8e417e5?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/e58dd8e417e5</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[system-one-model]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Mon, 19 Oct 2026 13:44:31 GMT</pubDate>
            <atom:updated>2026-10-21T06:35:19.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9MGFWoPbi2Ib9V75Q8e7Q.png" /></figure><p>Have you heard about <strong>System One</strong>? If you live in a cavern, here is <a href="https://www.forbes.com/sites/ronschmelzer/2026/10/12/decisions-decisions-a-guide-to-the-new-wave-of-ai-decision-models-besides-jev/">a quick reminder about JEV who started the movement</a>… (or maybe they just made it trendy again).</p><p>Now, this post is the result of a question: would it be possible to host this new type of lightweight decision model within the Oracle AI Database 26ai FREE edition? Given the limits in terms of available RAM (2GB) and CPU (2 CPU cores); yes, this looks like a good challenge for Autumn. And for adoption purpose, this would be completely FREE!</p><p>Different attempts, but one model (currently) proved to be helpful. I’ve indeed started with <a href="https://contrastive-lm.notion.site/">CLM</a>, then looked at the underlying Qwen3–8B language model but that one was too big already. I tried to retrain the CLM model but using ALL-MINILM-L12-V2 model but that kind of model is not “smart” enough :). I then looked at <a href="https://huggingface.co/vllm-sr/d3-lite">Decision 3 lite</a> but then again a Qwen3.5 model this time was required… Enter <a href="https://huggingface.co/convaiinnovations/laya"><strong>Laya</strong></a><strong> </strong>from Convai Innovations, not the best* but interesting given its small size and the results compared to Jev (see their GitHub README.md file).</p><p>*<a href="https://github.com/wfzyx/von"> Von</a> claimed to be better but I had to start from somewhere, and this project was archived on GitHub 2 days ago.</p><h3>It’s all about Integration!</h3><p>Basically, you can load an ONNX model within the Oracle AI Database. The current ONNX runtime supported in the Oracle AI Database tested is version 1.26.0. The 26ai version comes with this new datatype: VECTOR which can have be of up to 65,535 dimensions. The VECTOR_EMBEDDING function takes as input a VARCHAR2 value along a model and can return a VECTOR. So basically, apart some “details” such as tokenization, input parameters, output parameters… it looked like Laya was a good candidate; BUT the model needed to be changed a bit to accommodate with the current limitations.</p><h4>ONNX format conversion</h4><p>As explained the Oracle database can use directly models in ONNX format. While Laya model was available on Huggingface in Safetensors format, we had to convert it into ONNX float32.</p><p>Using Python, a script was built to do the conversion. Leveraging the laya python package as well as PyTorch, the weights and other files (like configuration and tokenizer) were converted into the float32 ONNX model. But the resulting model size was 1.57 GB. I wanted to get under the 1 GB size so that the memory required to load the model within the database could be in the limits imposed by the FREE edition.</p><p>Enters <strong>selective quantization</strong>, a process to reduce numerical precision by changing the internal representations of the parameters of the model (when possible according to the usage of the different layers). It turns out Oracle doesn’t support float16 nor bfloat16 (some operators not being available) thus I targeted INT8 precision. The final model had a size of 630 MB!</p><h4>INPUT/OUTPUT Parameters adaptation</h4><p>Models prefer working with numbers vs strings. That’s why the first operation is the <em>tokenization</em> which takes text (your prompt, your question and context and possible choices for a System One) and returns a list of integers corresponding to the <a href="https://huggingface.co/convaiinnovations/laya/raw/main/tokenizer/tokenizer.json">dictionary entries</a> used by the model. This list of integers (which includes markers) can easily be stored within a VECTOR.</p><p>I gave it a try creating a small ONNX tokenizer which translated a VARCHAR2 text into a VECTOR and it worked like a charm.</p><p>BUT this was only the beginning as the real Laya model would expect these input parameters:</p><ul><li>input_ids INT64 [batch, sequence]: token IDs for the assembled request (concatenation of markers, state, questions, choices)</li><li>attention_mask INT64 [batch, sequence]: real tokens vs padding</li><li>marker_pos INT64 [batch, markers]: positions of option markers</li><li>marker_mask INT64 [batch, markers]: real options versus padded slots</li><li>qtype INT64 [batch]: choice, score or noul question type ID</li></ul><p>And the resulting output parameters are:</p><ul><li>logits float32 [batch, markers]: used for post-processing</li><li>act_logits float32 [batch, 2]: used for post-processing</li></ul><p>As mentioned above, because the only parameter accepted by the function VECTOR_EMBEDDING for an ONNX model is a VARCHAR2 (and the output is one VECTOR); we needed first to change the model so that it can accept these API restrictions.</p><p>For input parameters, the model was enhanced to first perform the tokenization and produce the expected 5 input parameters. Because of this, the formatted request must fit within <em>512 tokens</em>, without the mode prefix. Oversized requests are flagged invalid (see after output position 1). Before neural inference, unused padding positions are removed so that short requests do not require processing all 512 positions.</p><h4>Input Parameters Padding</h4><p>Without any change all input parameters would consider 512 tokens even if they were not used, which consumes a lot of time. I measured the improvements by padding input parameters and for short requests, such as 30 tokens, the inference duration went from 1,797ms down to 98ms which is a <strong><em>18x improvement</em></strong>!</p><p>However, doing so changes the logits and probabilities vs the initial model and for the 6 test cases I had, probability changed by up to 14.1%</p><h4>Output Parameters Encoding</h4><p>For output parameters, the logits and act_logits are now encoded into a <strong><em>decision</em></strong> vector of 36 elements as following:</p><ul><li>position 1: validity flag, 1 means the request passed the graph’s structural and capacity checks. Other values have to be rejected.</li><li>position 2: Answer count, number of actual answer options (see choices, score).</li><li>positions 3–34: Answer logits, up to 32 unnormalized scores, in the same order as the supplied <em>k choices</em>. Only positions 3 to k+2 are valid answers.</li><li>position 35: Action logit 0, used to compute action probability.</li><li>position 36: Action logit 1, the alternative action score, used to compute action probability.</li></ul><p>Further post-processing (scaled softmax, JSON formatting, etc.), is then done in PL/SQL.</p><p>Example for a 2 choices question with answers being <em>Billing</em> or <em>Technical</em>:</p><pre>[<br>  1,                  // [1] Valid request<br>  2,                  // [2] Two answers<br>  3.2,                // [3] Billing logit (decision score, not probabilities)<br>  0.8,                // [4] Technical logit (decision score, not probabilities)<br>  ...30 unused slots, // [5]–[34] Ignore<br>  1.5,                // [35] Action logit 0<br>  -0.5                // [36] Action logit 1<br>]</pre><p>Interpretation according to the mode:</p><ul><li><strong>choice:</strong> answer logits follow the supplied array order.</li><li><strong>noul:</strong> position 3 is <strong>false/No</strong>, and position 4 is <strong>true/Yes</strong>.</li><li><strong>score:</strong> answer logits follow the ordered levels, from level 0 through level k-1</li></ul><p><em>This also explains that we limit our set of choices to 32 (which “should be enough” :) ).</em></p><h4>Final Post-Processing</h4><p>PL/SQL will play its role of masking input data controls, data preparation, and final post-processing. This former step consists of creating a proper JSON document with the expected information to take decision, most importantly:</p><ul><li>the preferred decision</li><li>the confidence of this decision</li></ul><p>Please keep in mind that requests whose selected-answer confidence falls below a <em>validated</em> threshold can be escalated to a larger model or human review.</p><p>Another obvious method would also consist of fine tuning the current model with your own dataset (question and answers).</p><h3><strong>Scalability</strong></h3><p>The FREE edition of Oracle AI Database 26ai comes with a new capability which consists of sharing model weights among database sessions. Indeed, ONNX model processing is usually done using the PGA, but with newly released In-Memory model loading, PGA memory usage can be reduced by an important factor.</p><p>First thing is to ensure the model can be split with graph on one side and weights on the other. The standard ONNX Python library can be used to produce 2 files. The OML4Py package can then be used to create a JSON file that along the 2 other ONNX files can be used to leverage In-Memory model loading. The result brings a memory usage optimization where shared model data is present only once in MGA, a new memory area that is used by all the sessions. The remaining ONNX graph and intermediate results is still processed (and duplicated) for each session in its own PGA.</p><p>The outcomes are:</p><ul><li>less memory used</li><li>faster model processing</li></ul><p>The size of the produced files are:</p><ul><li>ONNX model (graph): <strong>5.94MB</strong></li><li>ONNX model (weights): 625.36MB (shared in MGA)</li><li>JSON metadata: 43.68kB</li></ul><h4>Container configuration</h4><p>To test this feature, I had to configure my container to run with 5 GB of shared memory instead of the default 64 MB (the MGA requires shared memory); so don’t forget to run it using --shm-size 5G.</p><p>Possible next steps:</p><ul><li>optimize the PL/SQL package</li><li>fine tune the model</li><li>provide ORDS endpoints to call that System One model using REST</li></ul><p>Oh, and by the way, you can find it on my <a href="https://github.com/loiclefevre/oracle-laya-system-one">GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e58dd8e417e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/laya-system-one-powered-by-the-free-oracle-ai-database-26ai-e58dd8e417e5">Laya System One, powered by the FREE Oracle AI Database 26ai</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compress Your Table With NO Downtime!]]></title>
            <link>https://medium.com/db-one/compress-your-table-with-no-downtime-832ba1a46e53?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/832ba1a46e53</guid>
            <category><![CDATA[autonomous-database]]></category>
            <category><![CDATA[oracle-database]]></category>
            <category><![CDATA[compression]]></category>
            <category><![CDATA[online]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 08:06:20 GMT</pubDate>
            <atom:updated>2026-10-09T08:06:21.844Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sxknlmSihTiosD92BDJ5hA.png" /></figure><p>We’ve all been there. Your application lives, data volumes grow and comes the time to reduce disk space <strong>without disturbing the business!</strong></p><p>If you use an Oracle Autonomous AI Database 26ai, you are SO LUCKY!</p><p>I had to do such housekeeping. My table stores test statistics. It grows, a lot, every day. It was reaching 48 GB with close to 266M rows. One third of the database size.</p><pre>SQL&gt; select bytes/1024/1024/1024 <br>from user_segments <br>where segment_name=&#39;MY_STATS&#39;;<br><br>   BYTES/1024/1024/1024 <br>_______________________ <br>          48.3720703125</pre><p>Application is online 24/7 thus how to do it?</p><p>Three steps:</p><ol><li>Change the table structure (DDL)</li><li>Online compress the data with the proper method</li><li>Track compression progress</li></ol><p>Changing the table structure is easy:</p><pre>ALTER TABLE my_stats COMPRESS FOR QUERY HIGH;</pre><p>Done. All the compression methods are available on Autonomous AI Databases (here Transaction Processing Serverless). I used an aggressive one that matches the workloads on this table: numerous insertions and analytical queries. Compression ratio ~x10.</p><p>See documentation for available compression methods from the <a href="https://docs.oracle.com/en/database/oracle/oracle-database/26/arpls/DBMS_COMPRESSION.html?embed=1#GUID-8C9942CA-4EBD-48FF-9E8C-A59BF21A0176">Compression advisor PL/SQL package</a>.</p><p>Compress the table while application can still perform DML operations (writes, reads):</p><pre>ALTER TABLE my_stats MOVE ONLINE;</pre><p>The key word here is of course ONLINE which tells the database: “Hey don’t prevent my apps to do their job as usual!”.</p><p>To track this operation, you can rely on the V$SESSION_LONGOPS view which basically tracks all long operations:</p><pre>select opname as &quot;Operation&quot;,<br>       target_desc as &quot;Target&quot;, <br>       round(100*sofar/totalwork,2) as &quot;Progress (%)&quot;, <br>       time_remaining as &quot;Time remaining (s)&quot; <br>  from v$session_longops <br> where time_remaining &gt; 0;</pre><p>This will display all the unfinished long operations including the compression of your table. Note that the operation of compressing online a table can involve several steps such as <em>online</em> index maintenance, and freed disk space reclamation.</p><pre>SQL&gt; select bytes/1024/1024/1024 <br>from user_segments <br>where segment_name=&#39;MY_STATS&#39;;<br><br>   BYTES/1024/1024/1024 <br>_______________________ <br>              4.7109375</pre><p>Overall, the operation took 50 minutes and freed 43.66 GBs!</p><p>You’re welcome 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=832ba1a46e53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/compress-your-table-with-no-downtime-832ba1a46e53">Compress Your Table With NO Downtime!</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle AI Vector Search in Java (langchain4j )]]></title>
            <link>https://medium.com/db-one/oracle-ai-vector-search-in-java-langchain4j-a9c203855580?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/a9c203855580</guid>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[vector-database]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Wed, 16 Oct 2024 09:04:27 GMT</pubDate>
            <atom:updated>2024-10-16T09:03:17.045Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Inspired from </em><a href="https://medium.com/@timju/chromadb-in-java-langchain4j-41ed910cd3e7"><em>medium post from Tim J</em></a><em>.</em></p><p>This post will explain how to quickly integrate the Oracle database 23ai and its AI Vector Search capabilities into a Java application, enabling semantic search in your AI app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4lLP2RAEFrpjCGO3iyqSQ.png" /></figure><p>To start quickly, we’ll leverage <a href="https://github.com/langchain4j/langchain4j">Langchain4j</a> project.</p><h3>Preparation:</h3><ul><li>A Maven Project</li><li><a href="https://docs.docker.com/engine/install/">Docker</a> or <a href="https://podman.io/docs/installation">Podman</a> installed</li></ul><h3>Step 1: Start the DB</h3><p>Run the gvenzl/23-slim Docker image. You can use the following command:</p><pre>docker run -p 1521:1521 -e ORACLE_PASSWORD=free -e APP_USER=developer -e APP_USER_PASSWORD=free gvenzl/oracle-free:23-slim</pre><h3>Step 2: Install Dependencies</h3><p>The following Maven dependencies will be required. We’ll use Langchain4j ONNX model to generate the vector embeddings locally (no need for any API key).</p><pre>&lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;langchain4j&lt;/artifactId&gt;<br>            &lt;version&gt;${langchain4j.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;!-- ONNX embedding model --&gt;        <br>        &lt;dependency&gt;<br>            &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;langchain4j-embeddings-all-minilm-l6-v2-q&lt;/artifactId&gt;<br>            &lt;version&gt;${langchain4j.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;!-- Oracle database 23ai integration --&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;langchain4j-oracle&lt;/artifactId&gt;<br>            &lt;version&gt;${langchain4j.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;!-- Data source --&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;<br>            &lt;artifactId&gt;ucp&lt;/artifactId&gt;<br>            &lt;version&gt;${jdbc.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;!-- logging --&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;slf4j-nop&lt;/artifactId&gt;<br>            &lt;version&gt;${slf4j.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;<br>            &lt;version&gt;${slf4j.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;</pre><h3>3. Initialize the Vector Store and the Embedding Model</h3><p>For this tutorial, we’ll need an EmbeddingStore and an EmbeddingModel. These are 2 critical objects provided by the Langchain4j library using builders. <br>The EmbeddingStore will use the Oracle database 23ai we provisioned in the first step. The EmbeddingModel will use the “all-minilm-l6-v2-q” ONNX model.</p><p>First, we configure the JDBC URL, and we provide a table name to store the original text data, the computed vector embedding, and, optionally, some metadata.</p><pre>import dev.langchain4j.data.segment.TextSegment;<br>import dev.langchain4j.model.embedding.EmbeddingModel;<br>import dev.langchain4j.model.embedding.onnx.allminilml6v2q.AllMiniLmL6V2QuantizedEmbeddingModel;<br>import dev.langchain4j.store.embedding.EmbeddingStore;<br>import dev.langchain4j.store.embedding.oracle.CreateOption;<br>import dev.langchain4j.store.embedding.oracle.OracleEmbeddingStore;<br>import oracle.ucp.jdbc.PoolDataSource;<br>import oracle.ucp.jdbc.PoolDataSourceFactory;<br><br>import java.sql.SQLException;<br><br>public class Oracle {<br> /**<br>  * Data source for Oracle database 23ai.<br>  */<br> public static final PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();<br><br> static {<br>  try {<br>   // Data source configuration<br>   dataSource.setConnectionFactoryClassName(&quot;oracle.jdbc.datasource.impl.OracleDataSource&quot;);<br><br>   // change the URL accordingly<br>   // format: jdbc:oracle:thin:&lt;user&gt;/&lt;user password&gt;@//&lt;hostname&gt;/&lt;database service&gt;<br>   dataSource.setURL(&quot;jdbc:oracle:thin:developer/free@//localhost/freepdb1&quot;);<br>  }<br>  catch (SQLException sqle) {<br>   throw new RuntimeException(sqle);<br>  }<br> }<br><br> public static final EmbeddingStore&lt;TextSegment&gt; embeddingStore =<br>   OracleEmbeddingStore.builder()<br>     .dataSource(dataSource)<br>     .embeddingTable(<br>       &quot;my_embeddings&quot;,<br>       CreateOption.CREATE_IF_NOT_EXISTS)<br>     .build();<br><br> public static final EmbeddingModel embeddingModel = new AllMiniLmL6V2QuantizedEmbeddingModel();<br>}</pre><h3>4. Add documents</h3><p>Use the code below to add documents with their embedding to the vector store. Metadata are optional, but they can provide interesting context (e.g., type of document).</p><pre>import dev.langchain4j.data.document.Metadata;<br>import dev.langchain4j.data.embedding.Embedding;<br>import dev.langchain4j.data.segment.TextSegment;<br><br>import static org.example.Oracle.embeddingModel;<br>import static org.example.Oracle.embeddingStore;<br><br>public class OracleInserter {<br> /**<br>  * Add text.<br>  */<br> public static void addDocuments(final String text) {<br>  final TextSegment segment1 = TextSegment.from(text, new Metadata());<br>  final Embedding embedding1 = embeddingModel.embed(segment1).content();<br>  embeddingStore.add(embedding1, segment1);<br> }<br><br> /**<br>  * Add text with metadata.<br>  */<br> public static void addDocuments(String text, Metadata metadata) {<br>  final TextSegment segment1 = TextSegment.from(text, metadata);<br>  final Embedding embedding1 = embeddingModel.embed(segment1).content();<br>  embeddingStore.add(embedding1, segment1);<br> }<br>}</pre><h3>5. Search Request</h3><p>Following is the implementation of a quick search for document similarity using our ONNX model:</p><pre>import dev.langchain4j.data.segment.TextSegment;<br>import dev.langchain4j.store.embedding.EmbeddingMatch;<br>import dev.langchain4j.store.embedding.EmbeddingSearchRequest;<br><br>import java.util.List;<br><br>import static org.example.Oracle.embeddingModel;<br>import static org.example.Oracle.embeddingStore;<br><br>public class OracleSearcher {<br> public static List&lt;EmbeddingMatch&lt;TextSegment&gt;&gt; search(String query, int maxResults) {<br>  final EmbeddingSearchRequest embeddingSearchRequest = EmbeddingSearchRequest.builder()<br>    .queryEmbedding(embeddingModel.embed(query).content())<br>    .maxResults(maxResults)<br>    .minScore(0.0)<br>    .build();<br>  return embeddingStore.search(embeddingSearchRequest).matches();<br> }<br>}</pre><h3>6. Document similarity</h3><p>The previous code can now be invoked to interact with the Oracle database 23ai:</p><pre>import dev.langchain4j.data.segment.TextSegment;<br>import dev.langchain4j.store.embedding.EmbeddingMatch;<br><br>import java.util.List;<br><br>public class Main {<br> public static void main(String[] args) {<br>  OracleInserter.addDocuments(&quot;I like football.&quot;);<br>  OracleInserter.addDocuments(&quot;The weather is good today.&quot;);<br><br>  List&lt;EmbeddingMatch&lt;TextSegment&gt;&gt; search = OracleSearcher.search(&quot;What is your favorite sport?&quot;, 1);<br>  // Prints:<br>  // Score: 0,807478<br>  // Result: I like football.<br>  System.out.printf(&quot;Score: %f\nResult: %s\n&quot;, search.getFirst().score(), search.getFirst().embedded().text());<br> }<br>}</pre><p><strong>GitHub repository</strong>: <a href="https://github.com/loiclefevre/ai_vector_search">https://github.com/loiclefevre/ai_vector_search</a></p><p><strong>Langchain4j</strong>: <a href="https://github.com/langchain4j/langchain4j">https://github.com/langchain4j/langchain4j</a></p><p><strong>Oracle Database 23ai AI Vector Search Book</strong>: <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/">https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9c203855580" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/oracle-ai-vector-search-in-java-langchain4j-a9c203855580">Oracle AI Vector Search in Java (langchain4j 🦜)</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deep dive into Binary JSON formats: OSON]]></title>
            <link>https://medium.com/db-one/a-deep-dive-into-binary-json-formats-oson-e3190e5e9eb0?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/e3190e5e9eb0</guid>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 16:08:34 GMT</pubDate>
            <atom:updated>2024-10-03T16:07:30.872Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690"><em>Continuing from the previous chapters</em></a><em>:</em></p><ul><li><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314">History</a></li><li><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314">What is a Binary JSON format?</a></li><li><a href="https://medium.com/@loic-lefevre/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e">BSON format</a></li><li><a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690">JSONB format</a></li></ul><h3>Chapter 5 — OSON format</h3><p><a href="https://blogs.oracle.com/database/post/autonomous-json-database-under-the-covers-oson-format">OSON</a> is Oracle’s optimized binary JSON format that has been inside the Oracle database server since version 12.2 (March 2017). Initially, it was used for the <a href="https://docs.oracle.com/en/database/oracle/oracle-database/12.2/inmem/optimizing-in-memory-expressions.html#GUID-FDA8B0D3-6339-4E19-8D2D-EEA0A7529B46__GUID-3677A454-08F3-4ADF-B349-14A27600BDA3">In-Memory Columnar store</a> to speed up analytical queries over JSON documents. It has then been improved and is now available:</p><ul><li>As the JSON datatype starting from <a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/nfcon/application-development.html#GUID-47BBA332-62C9-41AD-A1D2-51EE02379171">version 21c</a>; and so the preferred datatype for storing JSON documents in <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html#GUID-E441F541-BA31-4E8C-B7B4-D2FB8C42D0DF">23ai</a></li><li>Using BLOB or RAW datatype with a check constraint IS JSON FORMAT OSON in <a href="https://docs.oracle.com/en/database/oracle/oracle-database/19/adjsn/overview-of-storage-and-management-of-JSON-data.html#GUID-26AB85D2-3277-451B-BFAA-9DD45355FCC7">Autonomous databases</a> (managed cloud service) starting from version 19c</li><li>In database drivers (<a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/sql/json/OracleJsonGenerator.html">Java</a>, <a href="https://python-oracledb.readthedocs.io/en/latest/api_manual/async_connection.html#AsyncConnection.encode_oson">Python</a>, <a href="https://node-oracledb.readthedocs.io/en/latest/api_manual/connection.html#connection.encodeOSON">JavaScript</a>, etc.) to support client-side encoding and decoding</li></ul><h4>Key capabilities</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oq1LHMOboPqZZrKVGn1cZg.png" /><figcaption>OSON format with its dictionary. “award” field is stored only once.</figcaption></figure><ul><li>The OSON format is versioned: new capabilities are continuously added while providing backward compatibility (the currently supported versions are 1, 2, 3, and 4).</li><li>Dictionary-based: key/field names are deduplicated and stored inside a dictionary in front of the encoded values; allowing efficient compaction and providing quick access to field names to test for existence. This results in extreme compaction whenever a field name is used several times in arrays and nested objects.</li><li>Duplicate key can be supported optionally (default: not supported)</li><li>Values can be encoded into their native database representation (SQL type) such as date, timestamp, timestamp with time zone, interval, vector, number, etc.; thus providing fidelity between JSON and Relational models (avoiding typecasting)</li><li>Specific compaction attributes are available, such as reusing popular values (dictionary) or previous object values.</li><li>LOW, MEDIUM, and HIGH compression algorithms can be used to reduce storage size.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a96e8hA0TE9wi1DzpJHjSA.png" /><figcaption>OSON compressed with Relative Offset enabled.</figcaption></figure><ul><li>Relative Offset encoding provides an improved compression ratio when enabled (default with 23ai when JSON are compressed)</li><li>Efficient partial update is supported from both an API standpoint (<a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/oracle-sql-function-json_transform.html">JSON_TRANSFORM</a>, <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/oracle-sql-function-json_mergepatch.html">JSON_MERGEPATCH</a>) and storage standpoint (reducing redo log generation and out-of-line updates).</li><li>In 23ai and 21c, inlined JSON documents can use up to <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/nfcoa/data_analytics_sql.html#GUID-83241-2">7950 bytes (for 8 kB blocks)</a>, and up to 3964 bytes before 21c.</li><li>Maximum size of 32 MiB <em>after</em> encoding.</li><li><a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-schema.html#GUID-980BD95E-D0EF-4E22-8E67-08CD419EE7A2">JSON schema</a>: starting from 23ai; extendedType can be used to help <a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-schema.html#GUID-50DD1C0D-A1C1-49BA-88A5-977EB1B734FA">OSON binary encoding type casting</a>.</li><li>Client-side encoding and decoding: offloading encoding/decoding from the database can really make the difference. See below a comparison with database server-side OSON encoding (left) and client-side OSON encoding (right) for loading 10,000 JSON documents (average size: 20 kB encoded vs 50 kB as UTF-8 text).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*deuoDTOgL5CN6_37" /><figcaption>Client-side encoding allows for 9x faster data loading.</figcaption></figure><h3>Additional notes</h3><ul><li><a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/full-text-search-queries.html#GUID-58ADCDE5-7564-4DA0-BED7-B0DBFD5AE6FB">Full-Text index</a>: Search indexes provide Full-Text search capabilities (inverted index, synchronous/asynchronous maintenance, partial or complete document indexed).</li><li><a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/indexes-for-json-data.html#GUID-CA25E863-1EA2-4E9A-A898-E7CA9CD645B1">Multivalue index</a>: particular index for arrays of scalars or arrays of object values (starting from version 21c).</li><li><a href="https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-query-rewrite-use-materialized-view-json_table.html#GUID-90D76388-F022-444C-B5CD-0A7C27FEE30D">Materialized View query rewrite</a>: capability allowing the database to rewrite a given query to use a pre-computed (in real-time, on commit, etc.) dataset to speed up queries. Materialized views can be indexed.</li></ul><h4>Open Source!</h4><p>OSON has been open-sourced since 2023 (Apache License 2.0) with the release of the thin drivers for <a href="https://github.com/oracle/python-oracledb">Python</a> and <a href="https://github.com/oracle/node-oracledb">JavaScript</a>.</p><h3>Chapter 6 — Checkpoint</h3><p>So far, we’ve looked at BSON, JSONB, and OSON formats. OSON is the only format designed from the ground up for common database operations (not just storage). Its integration within both client drivers and database server capabilities makes it compelling. Also, the work done around the Oracle Database API for MongoDB enables easy migrations from MongoDB. You can review the identified capabilities of each format below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*KJvvtX4FRJRF6NnB6qUqvw.png" /><figcaption>Comparisons between JSON binary formats and associated database capabilities.</figcaption></figure><p><em>In the next chapter, we’ll focus on less-known databases JSON formats…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3190e5e9eb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-oson-e3190e5e9eb0">A deep dive into Binary JSON formats: OSON</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deep dive into Binary JSON formats: JSONB]]></title>
            <link>https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/e728ea0f5690</guid>
            <category><![CDATA[jsonb]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 15:46:04 GMT</pubDate>
            <atom:updated>2024-10-03T16:06:35.858Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/db-one/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e"><em>Continuing from the previous chapters</em></a><em>:</em></p><ul><li><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314">History</a></li><li><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314">What is a Binary JSON format?</a></li><li><a href="https://medium.com/@loic-lefevre/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e">BSON format</a></li></ul><h3>Chapter 4 — JSONB format</h3><p>First introduced with PostgreSQL 9.4, the <a href="https://github.com/postgres/postgres/blob/f0577816865dc9e6fab1537b2a112545535a5d51/src/include/utils/jsonb.h#L74">JSONB</a> format is really different from BSON. <em>But more interestingly</em>, there are 3 distinct JSONB formats:</p><ul><li>the <strong>on-disk</strong> format, subject to The Oversized-Attribute Storage Technique (also known as <a href="https://www.postgresql.org/docs/current/storage-toast.html">TOAST</a>) (see below notes)</li><li>the <strong>in-memory</strong> format that supports a bit more value types (more on that later), known as JsonbValue</li><li>the <a href="https://sqlite.org/draft/jsonb.html">JSONB data type from SQLite 3.45.0</a>, which — according to its author “<em>is completely different and incompatible with PostgreSQL JSONB</em>&quot;</li></ul><p>Following, we’ll deal solely with the <strong>on-disk</strong> format (first bullet).</p><h4>Key capabilities</h4><ul><li>Hierarchical format: key/value pairs for the same <em>level</em> are embedded together. Objects and arrays embed their respective children. Per level, key/value pairs are sorted by key length, then alphabetically to allow for efficient binary search (does a field name exist?). Said otherwise, <em>the JSONB format doesn’t keep fields ordering</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COwxjvF_cTn7khDlVEvjlA.png" /><figcaption>Simple JSONB representation. 308 bytes as JSONB vs 199 bytes (after spaces and carriage returns removed).</figcaption></figure><ul><li>Pointers optimization: given a level inside the JSON hierarchy, the structure JEntry manages a set of ordered pointers and value types. (same order as keys). This set is optimized so that</li><li>Binary encoding for numbers: this avoids parsing over and over (<em>See the picture above. The highlighted value in yellow is the number </em><em>2 using PostgreSQL short numeric encoding</em>).</li><li>32-bit alignment for numbers and the identical-level-keys-list (<em>See the picture above. The gray square surrounds 3 bytes added for padding</em>).</li><li>Maximum size of 256 MiB</li><li>Offset/Length encoding of Jentry to speed up array processing and tradeoff with compressibility. Offset is used every 32 children.</li></ul><blockquote>Having only children entry length helps to compress JSONB since these are usually repeated. Having only offsets helps to quickly jump to values (scalar/child) but is far less compressible.</blockquote><h4>Additional notes</h4><ul><li>JSONB JEntry denotes the value data type using 3 bits, hence 8 values. As of today, 6 values are used for string type, numeric type, false value, true value, null value, and object/array entry type.</li><li>The in-memory JSONB format supports additional date, time, timestamp, timestamp with time zone types that require parsing strings.</li><li>Indexing: JSONB columns can be indexed contrarily to JSON columns.</li><li>null, true, and false values are encoded using 4 bytes. (<em>See the picture above with orange underlined values</em>).</li><li>UTF-8 string values do not support the \0 character.</li><li>Duplicate keys are “supported”; only the latest key/value pair appearing inside the UTF-8 text JSON is kept.</li><li>Partial updates of JSON documents are supported from an API standpoint, but PostgreSQL MVCC model defeats this from a storage standpoint (vacuum is important for large JSON documents).</li></ul><h3>TOAST</h3><p>The JSONB data type can have a size of up to 256 MiB (after encoding). Since PostgreSQL uses 8 kiB blocks, it could not fit inside it. For this purpose (and for other types), TOAST is used to compress and/or slice the binary encoded document to store it “out of line” — meaning inside another table/index structure solely for that column.</p><p>The threshold size is usually 2 kiB, and depending upon the definition of the JSONB column, TOAST may compress the encoded bytes to move them compressed or not into this out-of-line structure.</p><p>What this means is:</p><ul><li>depending upon the compression algorithm (PGLZ by default), you may hit a compression/decompression penalty or you could see storage increase</li><li>whenever you have a JSONB larger than 2 kiB, accessing fields without an index may lead to the “detoast syndrome”</li></ul><p>For example, you may consider the <strong>LZ4</strong> compression algorithm available since version 14 usually requires less CPU and can have a very good compression ratio.</p><pre>CREATE TABLE collection (data JSONB compression lz4);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKunxK0SBw6HqDmZpmmu7w.png" /><figcaption>A 1 MiB JSON document on the left compressed down to 297.2 kiB with PGLZ and 70.2 kiB with LZ4.</figcaption></figure><p>Regarding the “detoast syndrome”, this means that whenever you need to access a value from a JSON field, for query filtering or during the projection, the JSONB document will need first be “detoasted”, thus adding an overhead proportional to the number of times you query a field:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-i9kqZpdXUArRRJDMdTtfA.png" /><figcaption>Projecting 1, 2, 3, 4 times the same field with PGLZ compression (p95 in ms after 60,000 runs).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6o27Lbuwnzw4ksOjFeN0nQ.png" /><figcaption>Projecting 1, 2, 3, 4 times the same field with LZ4 compression (p95 in ms after 60,000 runs).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dX58kcDA8QEPKQq3ss2hYg.png" /><figcaption>Projecting 1, 2, 3, 4 times the same field with no compression (p95 in ms after 60,000 runs).</figcaption></figure><p>In the previous example, the JSON UTF-8 text data is 47,321 bytes long while the JSONB encoded value takes 65,667 bytes uncompressed, 12,012 bytes with LZ4 compression, and 9,717 bytes with PGLZ compression.</p><p>The typical queries used were:</p><pre>-- only 1 document present in the table<br>select c.data-&gt;&gt;&#39;age&#39; from collection c;<br>select c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39; from collection c;<br>select c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39; from collection c;<br>select c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39;, c.data-&gt;&gt;&#39;age&#39; from collection c;</pre><p><em>In the next chapter, we’ll focus on </em><a href="https://loic-lefevre.medium.com/a-deep-dive-into-binary-json-formats-oson-e3190e5e9eb0"><em>OSON</em></a><em>…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e728ea0f5690" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690">A deep dive into Binary JSON formats: JSONB</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deep dive into Binary JSON formats : BSON]]></title>
            <link>https://medium.com/db-one/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/83081b10335e</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[bson]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 08:53:28 GMT</pubDate>
            <atom:updated>2024-09-19T15:46:38.877Z</atom:updated>
            <content:encoded><![CDATA[<h3>A deep dive into Binary JSON formats: BSON</h3><p><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314"><em>Continuing from the first chapters</em></a><em>:</em></p><ul><li>History</li><li>What is a Binary JSON format?</li></ul><h3><strong>Chapter 3 — BSON format</strong></h3><p>MongoDB invented the BSON format, which is specified <a href="https://bsonspec.org/spec.html">here</a> (we are at version 1.1 right now).</p><h4>Key capabilities</h4><ul><li>Streaming format: key/value pairs are stored <strong><em>in the order they appear</em></strong> inside the JSON text document. Also, accessing a key/field requires parsing the previous ones (true when the document is not pre-loaded in RAM, which also denotes the importance of indexes).</li></ul><blockquote>This is a unique difference in the sense that other Binary formats don’t follow this rule which by the way is not specified by the JSON standard itself. The only way to guarantee order of fields/values is by using an array.</blockquote><ul><li>Binary encoding for numbers: this avoids parsing over and over</li><li>Optimized encoding for null, true, and false values: 1 byte</li><li>Extensible thanks to the 8 bits reserved for defining field type (up to 256 distinct data types possible): it allows storing in binary more data types than what the JSON standard requires such as <strong>UTC datetime</strong> (Unix epoch), <strong>ObjectIDs, binary, etc. </strong>plus it allows for user-defined data types</li><li><a href="https://github.com/mongodb/specifications/blob/master/source/extended-json.md">Extended JSON</a> (<strong>ejson</strong>) notation: allows forcing data into specific data type encoding</li></ul><pre>// 16 bytes (128-bit IEEE 754-2008 decimal floating point)<br>&quot;price&quot;: { &quot;$numberDecimal&quot;: &quot;1234.5&quot; }</pre><ul><li>Client-side encoding/decoding available</li><li>Duplicate fields/keys are supported (even the special _id field).</li></ul><p><strong>Additional notes</strong></p><ul><li>Strings are terminated by a \0 as for C strings</li><li>Array elements are also stored as key/value pairs: each item has a key/field name corresponding to the position inside the array stored as a string</li></ul><pre>&quot;array&quot;: [ 2, 4, 8, 16, 32 ]<br><br>// BSON encoded looks like:<br>&quot;array&quot;: [ { &quot;0&quot;: 2 }, { &quot;1&quot;: 4 }, { &quot;2&quot;: 8 }, { &quot;3&quot;: 16 }, { &quot;4&quot;: 32 } ]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ah__4oJ03D0UmO3VUzlc9g.png" /><figcaption>Underlined in yellow, the array pseudo-keys</figcaption></figure><ul><li>There is no extended data type for managing time zones. They are usually stored in their own field, and thus, all datetime values have a time zone equal to <em>UTC</em>.</li><li>MongoDB storage engine WiredTiger compresses BSON documents using Snappy (the default). Other compression algorithms, such as Zlib and Zstd (Zstandard), are available.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2g9SSREJDxVQyxBMhCSlkQ.png" /><figcaption>Effect of compression on a 1 MiB JSON text document, encoded into 959 KiB in BSON, then compressed to 256 KiB (Snappy), 157 KiB (Zlib), and 21 KiB (Zstandard).</figcaption></figure><ul><li>Partial updates of JSON documents are supported solely in RAM, not in storage. That’s why, over time, using the <strong>compact</strong> command is required to rewrite (and decompress/recompress) and defragment all data and indexes. Think of it as the famous vacuum process from PostgreSQL.</li></ul><p><em>In the </em><a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690"><em>next chapter</em></a><em>, we’ll focus on the JSONB format…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83081b10335e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e">A deep dive into Binary JSON formats : BSON</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSONB, BSON, OSON… 
A deep dive into Binary JSON formats]]></title>
            <link>https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/d49e41bdb314</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 14:25:07 GMT</pubDate>
            <atom:updated>2024-10-07T09:37:14.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>BSON, JSONB, OSON… <br>A deep dive into Binary JSON formats</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*ZpgGlVncLx8MTIM_r_7HYA.png" /></figure><p>If you’ve used JSON to store and manage data, you’ve likely faced situations where the format seemed to fall short of your expectations. What if some of these disappointments weren’t random but were actually inherent to the design of the format you’re using? Imagine if subtle changes in your development practices or a deeper understanding of the underlying binary JSON format could resolve these issues.</p><p>Let’s embark on a journey where we’ll explore <a href="https://medium.com/db-one/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e"><strong>BSON</strong></a>, <a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-jsonb-e728ea0f5690"><strong>JSONB</strong></a>, and <a href="https://medium.com/db-one/a-deep-dive-into-binary-json-formats-oson-e3190e5e9eb0"><strong>OSON</strong></a>, uncovering how each format addresses common challenges and how you can leverage their unique features to enhance your data management practices — think of it as entering the Matrix of JSON data handling!</p><h3>Chapter 1 — History</h3><p>Here is a brief list of important dates that relate to storing <strong>hierarchical </strong>data (e.g. Tree structure):</p><ul><li>1960s–1970s, also known as the “<strong>Pre-Relational Era</strong>”: data were mostly hierarchical (remember IBM IMS…); also E. F. Codd let us an incredible legacy</li><li>1980s–1990s also known as the <strong>Relational Era:</strong> RDBMSs become popular, the relational model to solve “Hierarchical data problems”</li><li>December 1999: JavaScript standard, includes JSON premise</li><li><strong><em>February 2009: first release of MongoDB with BSON (binary)</em></strong></li><li>September 2012: PostgreSQL 9.2 released with JSON (text format)</li><li>October 2013: ECMA-404 standard (1st edition)</li><li>August 2014: Oracle 12.1.0.2 released with JSON (text)</li><li><strong><em>December 2014: PostgreSQL 9.4 released with JSONB (binary)</em></strong></li><li><strong><em>August 2015: MySQL 5.7.8 released with JSON (binary)</em></strong></li><li>February 2017: Extended JSON v1 (MongoDB)</li><li><strong><em>March 2017: Oracle 12.2.0.1 released with OSON (binary) for Columnar Processing/SIMD CPU instructions</em></strong></li><li>July 2017: Extended JSON v2 (MongoDB)</li><li>December 2017: ECMA-404 standard (2nd edition)</li><li><em>August 2020: Oracle Autonomous JSON Database, a managed cloud service that includes OSON (binary) in BLOB columns</em></li><li><strong><em>August 2021: Oracle 21c released with JSON data type (OSON binary)</em></strong></li><li>February 2022: Oracle Database API for MongoDB available for Autonomous JSON Database</li><li>June 2022: MongoDB Atlas released</li><li>April 2023: Oracle 23c Free Developer release contains the <em>JSON Relational Duality Views</em> feature…</li><li><strong><em>January 2024: SQLite 3.45 now supports JSONB (binary)</em></strong></li><li>May 2024: Oracle 23ai Generally Available (Cloud, FREE, on-premises with Engineered Systems)</li></ul><p>What’s interesting is that Binary JSON has been added to several major databases during the last 15 years. MongoDB, with its BSON format, was the precursor. Then followed PostgreSQL, MySQL, Oracle, and, more recently, SQLite.</p><p>But what is a Binary JSON format? what is its purpose? and why are there so many distinct formats?</p><h3>Chapter 2 — What is a Binary JSON format?</h3><p>The <a href="https://www.json.org/json-en.html">JSON (JavaScript Object Notation) standard</a> is generally well understood. Basically, a JSON document is written using UTF-8 encoded text. It can have fields with values. Field names (aka keys) should not be duplicated inside a JSON document but when written as UTF-8 text, we Humans, can duplicate field names :) In the very same spirit, the standard doesn’t say anything about field name ordering (more on that later). Finally, we can say that the JSON standard supports 4 distinct datatypes for the scalar values (e.g. not speaking about objects nor arrays):</p><ul><li>null</li><li>booleans</li><li>numbers</li><li>strings</li></ul><p>And that’s pretty much all to know.</p><p>One of the problems when dealing with JSON data in databases is that the JSON documents were persisted as text, and thus, they had to be parsed over and over when they were accessed, say for filtering or during the projection of a subset of the fields…</p><p>Parsing can consume a lot of CPU, but it can also require a lot of RAM! Think about the <strong>field names;</strong> usually, they are just metadata but when loading numerous JSON documents, they can represent 20% to 45% of data overhead: they don’t represent meaningful data at all, but they are required and repeated in RAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uu0IMou5z7XVKp4YnoWlhA.png" /><figcaption>Field names (in purple) consumes 46.2% of the document above. One billion of such documents would require 85 GiB solely for storing the field names as text!</figcaption></figure><p><strong>Binary JSON</strong> formats have been invented to pre-parse the UTF-8 text JSON documents and, by doing so, <em>to improve database and application performance</em>. Pre-parsing also means that the JSON documents are first validated hence when documents are persisted with a Binary format, it also means these documents have been validated, hence data quality is also improved!</p><p>But why are we mainly discussing BSON, JSONB, and OSON? Because the formats are <em>really different</em>.</p><p><em>In the </em><a href="https://medium.com/@loic-lefevre/bson-jsonb-oson-a-deep-dive-into-binary-json-formats-2-83081b10335e"><em>next chapters</em></a><em>, we’ll focus on each of these formats in detail, revealing their strengths and sometimes their limitations…</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49e41bdb314" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/jsonb-bson-oson-a-deep-dive-into-binary-json-formats-d49e41bdb314">JSONB, BSON, OSON… 
A deep dive into Binary JSON formats</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extending your OCI VM Boot Volume]]></title>
            <link>https://medium.com/db-one/extending-your-oci-vm-boot-volume-bead736c5c13?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/bead736c5c13</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[oracle-cloud]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Mon, 09 Sep 2024 08:18:21 GMT</pubDate>
            <atom:updated>2024-09-11T11:45:48.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0HAIN0d7mRN2DzyD.jpg" /></figure><p>This is a small post to remember how to extend an OCI VM Boot volume to benefit from more than the default 35.5G.</p><p>First, create a VM with a customized boot volume, say: 200G.</p><p>Right after the OCI VM has been created, log as opc user, then run:</p><pre>sudo /usr/libexec/oci-growfs -y</pre><p>To verify that the command ended properly, run:</p><pre>$ lsblk<br><br>NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT<br>sda                  8:0    0   200G  0 disk <br>├─sda1               8:1    0   100M  0 part /boot/efi<br>├─sda2               8:2    0     1G  0 part /boot<br>└─sda3               8:3    0 198.9G  0 part <br>  ├─ocivolume-root 252:0    0 188.9G  0 lvm  /<br>  └─ocivolume-oled 252:1    0    10G  0 lvm  /var/oled</pre><p>Also:</p><pre>$ df -h /<br><br>Filesystem                  Size  Used Avail Use% Mounted on<br>/dev/mapper/ocivolume-root  189G   16G  174G   9% /</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bead736c5c13" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/extending-your-oci-vm-boot-volume-bead736c5c13">Extending your OCI VM Boot Volume</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle Converged Database 23ai — Let’s talk about Your Productivity…]]></title>
            <link>https://medium.com/db-one/oracle-converged-database-23ai-lets-talk-about-your-productivity-a9dff0186e3d?source=rss----e060f4a5c6da---4</link>
            <guid isPermaLink="false">https://medium.com/p/a9dff0186e3d</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Loïc Lefèvre]]></dc:creator>
            <pubDate>Fri, 24 May 2024 12:42:24 GMT</pubDate>
            <atom:updated>2024-05-24T13:22:38.129Z</atom:updated>
            <content:encoded><![CDATA[<h3>Oracle <em>Converged</em> Database 23ai — Let’s talk about Your Productivity…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SDM5TDpy2jCRzrE1iabYMw.png" /><figcaption>Bring your use cases, really, any, and combined…</figcaption></figure><p>When talking about “Converged Database”, often I’ve got to explain what it means, what are the implications, and all the benefits to expect.</p><p>Looking at the picture above, one should immediately understand that not only an Oracle database can manage <strong>relational data</strong>, but also it shines at storing and analyzing <strong>JSON documents</strong> at scale. And not just JSON documents, but <strong>XML </strong>as well. Now if you have <strong>Property graph</strong> or <strong>RDF data</strong>, then that’s the very same story. If you want to store and analyze <strong>spatial data </strong>(aka GIS), then you can also.</p><p>The lesser-known data types are <strong>Vector embeddings</strong> that have been available since early May 2024 with the 23ai release, the <strong>Text data</strong> (PDF, Word, Powerpoint, etc.) that come with Full-Text indexes; <strong>Columnar Analytics </strong>that provide tremendous performance over an in-memory-only column store; <strong>Blockchain tables</strong> that are immutable and tamper-resistant (e.g. insert only, no drop table, verifiable); <strong>Transactional Event Queue</strong> which allows consistent events/messages exchange between processes; <strong>In-Database Machine Learning</strong> that allows for creating and scoring models within the database without data movements; <strong>Internet of Things</strong> (IoT) which provide very fast asynchronous ingestion capabilities as well as time-series based processing; and finally <strong>External data</strong> which are basically a way to access any other data (local files, object storage, other database data…) as if it was a standard table.</p><p>In terms of architecture, one could deploy one database and be able to store and analyze all of these data; or it could be one container database containing pluggable databases, each with a distinct data use case; or it could be distinct databases.</p><p>As you can imagine, limiting data movements to zero helps to reduce the complexity (ETL, data synchronization across databases). This results in better security as well since all these data can now be protected by leveraging the Maximum Security Architecture. Also High-Availability and Disaster Recovery of all these data can be improved by applying Maximum Availability Architecture.</p><p>Now, to the point of increased productivity, having access to all these data use cases in the very same software allows, if needed and allowed by your security policies, to manage all of these data together using the SQL language.</p><p>Examples:</p><p>I need to query real-time JSON messages sent through a Kafka topic to detect anomalies and perform predictive maintenance; yes, you can do that!</p><p>I need to do Retrieval-Augmented Generation by leveraging Vector embeddings and providing fresh facts to this LLM; no problem, this way!</p><p>I need to analyze relational data as if it were a property graph to look for sub-graph patterns, and this should be accessible through a REST service; of course, the REST service is provided from within the database!</p><p>I need to work on relational data as if it were JSON documents in both read and write mode and restrict some JSON fields to being non-updatable; sure, we can!</p><p>…</p><p>The possibilities are infinite, and all of this can be done using SQL or simple APIs. Think about the complexity involved in using 2, 3, or 4… distinct tools, the required integration, the hard work to secure and make it highly available, and the cost of the skills to do so. A last aspect is the impact on energy to make a complex system evolve vs. a simpler system…</p><p>Get a glimpse of these new possibilities:</p><ul><li><a href="https://github.com/loiclefevre/oracle-23ai/tree/main/23-things-developers-will-love-about-23ai">23 things developers will love about 23ai</a>: a set of scripts built by Chris Saxon from Oracle to quickly start using new features!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9dff0186e3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/db-one/oracle-converged-database-23ai-lets-talk-about-your-productivity-a9dff0186e3d">Oracle Converged Database 23ai — Let’s talk about Your Productivity…</a> was originally published in <a href="https://medium.com/db-one">db-one</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>