<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Vector functions</title>
    <link>/en/sql-reference/functions/vector-functions/</link>
    <description>Recent content in Vector functions on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/functions/vector-functions/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: COSINE_SIMILARITY</title>
      <link>/en/sql-reference/functions/vector-functions/cosine-similarity/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/vector-functions/cosine-similarity/</guid>
      <description>
        
        
        &lt;p&gt;Returns the cosine similarity of two n-dimensional vectors. Cosine similarity is the cosine of the angle between two non-zero vectors. A returned value of 1 means that the vectors are identical, a value of 0 means the vectors are orthogonal, and a value of -1 means that the vectors are opposites.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;COSINE_SIMILARITY( &lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;/dl&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

NULL and NaN values are treated equivalently. If any element in the input array is NULL or NaN, the function returns NULL.

&lt;/div&gt;
&lt;p&gt;For input vector arrays that have a norm of 0, the following logic is used:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If both vectors are 0, then a value of 1 is returned as they are identical.&lt;/li&gt;
&lt;li&gt;If only one of the vectors is 0, then a value of 0 is returned as the vectors are orthogonal (zero similarity).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;FLOAT&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example computes the cosine similarity for two vector arrays:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT id, vector_arr1, vector_arr2, COSINE_SIMILARITY(vector_arr1, vector_arr2) AS similarity FROM vectors_array;
id |  vector_arr1  |  vector_arr2  |    similarity     
----+---------------+---------------+-------------------
  1 | [1.0,2.0,3.0] | [4.0,5.0,6.0] | 0.974631846197076
  2 | [1.5,2.5,3.5] | [4.5,5.5,6.5] | 0.985871023540107
  3 | [0.0,1.0,0.0] | [0.0,0.0,1.0] |                 0
  4 | [2.0,0.0,0.0] | [0.0,2.0,0.0] |                 0
  5 | [1.0,1.0,1.0] | [1.0,1.0,1.0] |                 1
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example computes the cosine similarity for a 5D vector:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT COSINE_SIMILARITY(Array[1.0, 2.0, 3.0, 4.0, 5.0], Array[1.0, 2.0, 3.0, 3.0, 4.0]);
COSINE_SIMILARITY
-------------------
  0.99321708930132
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: DOT_PRODUCT</title>
      <link>/en/sql-reference/functions/vector-functions/dot-product/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/vector-functions/dot-product/</guid>
      <description>
        
        
        &lt;p&gt;Returns the dot product of two n-dimensional vectors, represented as two equal length ARRAYs. Dot products may sometimes be referred to as scalar products.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;DOT_PRODUCT( &lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;/dl&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

NULL and NaN values are treated equivalently. If any element in the input array is NULL or NaN, the function returns NULL.

&lt;/div&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;FLOAT&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example computes dot products for two vector arrays:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT id, vector_arr1, vector_arr2, DOT_PRODUCT(vector_arr1, vector_arr2) AS dot_product FROM vectors_array;
id |  vector_arr1  |  vector_arr2  | dot_product 
----+---------------+---------------+-------------
  1 | [1.0,2.0,3.0] | [4.0,5.0,6.0] |          32
  2 | [1.5,2.5,3.5] | [4.5,5.5,6.5] |       43.25
  3 | [0.0,1.0,0.0] | [0.0,0.0,1.0] |           0
  4 | [2.0,0.0,0.0] | [0.0,2.0,0.0] |           0
  5 | [1.0,1.0,1.0] | [1.0,1.0,1.0] |           3
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example computes the dot product for a 5D vector:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT DOT_PRODUCT(Array[1.0, 2.0, 3.0, 4.0, 5.0], Array[5.0, 4.0, 3.0, 2.0, 1.0]);
DOT_PRODUCT 
------------
         35
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VECTOR_L2</title>
      <link>/en/sql-reference/functions/vector-functions/vector-distance/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/vector-functions/vector-distance/</guid>
      <description>
        
        
        &lt;p&gt;Returns the Euclidean, or L2, distance between two n-dimensional vectors.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VECTOR_L2( &lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr1&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr2&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;/dl&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

NULL and NaN values are treated equivalently. If any element in the input array is NULL or NaN, the function returns NULL.

&lt;/div&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;FLOAT&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example computes the distance for two vector arrays:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT id, vector_arr1, vector_arr2, VECTOR_L2(vector_arr1, vector_arr2) AS distance FROM vectors_array;
id |  vector_arr1  |  vector_arr2  |     distance     
----+---------------+---------------+------------------
  1 | [1.0,2.0,3.0] | [4.0,5.0,6.0] | 5.19615242270663
  2 | [1.5,2.5,3.5] | [4.5,5.5,6.5] | 5.19615242270663
  3 | [0.0,1.0,0.0] | [0.0,0.0,1.0] |  1.4142135623731
  4 | [2.0,0.0,0.0] | [0.0,2.0,0.0] | 2.82842712474619
  5 | [1.0,1.0,1.0] | [1.0,1.0,1.0] |                0
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example computes the distance between two 5D vectors:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT VECTOR_L2(Array[1.0, 2.0, 3.0, 4.0, 5.0], Array[1.0, 2.0, 3.0, 3.0, 4.0]);
VECTOR_L2 
-----------------
1.4142135623731
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VECTOR_MAGNITUDE</title>
      <link>/en/sql-reference/functions/vector-functions/vector-length/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/vector-functions/vector-length/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the magnitude of an n-dimensional vector. The magnitude of a vector is its length expressed as a positive scalar.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VECTOR_MAGNITUDE( &lt;span class=&#34;code-variable&#34;&gt;vector_arr&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;vector_arr&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;N-dimensional vector, type ARRAY of INT, FLOAT, NUMERIC&lt;/dd&gt;
&lt;/dl&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

NULL and NaN values are treated equivalently. If any element in the input array is NULL or NaN, the function returns NULL.

&lt;/div&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;FLOAT&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example computes the vector magnitude for two input arrays using two function calls of VECTOR_MAGNITUDE():&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT id, vector_arr1, VECTOR_MAGNITUDE(vector_arr1) AS mag1, vector_arr2, VECTOR_MAGNITUDE(vector_arr2) AS mag2
FROM vectors_array;
id |  vector_arr1  |      mag1         |  vector_arr2  |     mag2      
----+---------------+------------------+---------------+------------------
  1 | [1.0,2.0,3.0] | 3.74165738677394 | [4.0,5.0,6.0] | 8.77496438739212
  2 | [1.5,2.5,3.5] | 4.55521678957215 | [4.5,5.5,6.5] | 9.63068014212911
  3 | [0.0,1.0,0.0] |                1 | [0.0,0.0,1.0] |                1
  4 | [2.0,0.0,0.0] |                2 | [0.0,2.0,0.0] |                2
  5 | [1.0,1.0,1.0] | 1.73205080756888 | [1.0,1.0,1.0] | 1.73205080756888
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example computes the vector magnitude for a 5D vector:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT VECTOR_MAGNITUDE(Array[1.0, 2.0, 3.0, 4.0, 5.0]);
VECTOR_MAGNITUDE   
------------------
7.41619848709566
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
