-
Notifications
You must be signed in to change notification settings - Fork 796
feat: EXPOSED-1023 Extend VECTOR data type to other supporting databases #2802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Chantal Loncle (bog-walk)
merged 7 commits into
main
from
bog-walk/extend-new-vector-type
May 12, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70d7b75
feat: Extend Vector data type to other supporting databases
bog-walk a2571d8
feat: Extend Vector data type to supporting databases
bog-walk 57bfb55
feat: Extend vector type support to other databases & more dimension …
bog-walk c2b0aef
feat: Extend vector data type support to other databases
bog-walk de7e3df
feat: EXPOSED-1023 Extend VECTOR data type to other supporting databases
bog-walk 8d5dcb8
feat: EXPOSED-1023 Extend Vector data type to other supporting databases
bog-walk 41f7ab3
feat: EXPOSED-1023 Extend Vector data type to other supporting databases
bog-walk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| services: | ||
| postgres: | ||
| image: postgres | ||
| image: pgvector/pgvector:pg18 | ||
| restart: always | ||
| ports: | ||
| - "3004:5432" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
documentation-website/Writerside/topics/Vector-types.topic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE topic | ||
| SYSTEM "https://resources.jetbrains.com/writerside/1.0/xhtml-entities.dtd"> | ||
| <topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/topic.v2.xsd" | ||
| title="Vector" id="Vector-types"> | ||
| <show-structure for="chapter" depth="2"/> | ||
| <tldr> | ||
| <p> | ||
| <b>Required dependencies</b>: <code>org.jetbrains.exposed:exposed-core</code> | ||
| </p> | ||
| <include from="lib.topic" element-id="jdbc-supported"/> | ||
| <include from="lib.topic" element-id="r2dbc-supported"/> | ||
| </tldr> | ||
| <p> | ||
| Exposed provides support for vector data types, allowing you to store and query high-dimensional embeddings directly | ||
| within your database, as well as to run AI-powered similarity searches. Oracle, SQL Server, MySQL, and MariaDB | ||
| all support explicit vector types, with PostgreSQL providing the type through the open-source extension | ||
| <a href="https://github.com/pgvector/pgvector">pgvector</a>. | ||
| </p> | ||
|
|
||
| <chapter title="Supported types" id="supported-types"> | ||
| <p> | ||
| The <code>exposed-core</code> module supports three main ways to define vector columns using the | ||
| <a href="https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.v1.core/-table/vector.html"> | ||
| <code>.vector()</code> | ||
| </a> | ||
| method: | ||
| </p> | ||
| <list> | ||
| <li> | ||
| <p>The most common vector definition that accepts <code>FloatArray</code> values and allows you to define | ||
| dimensions:</p> | ||
| <code-block lang="kotlin"> | ||
| val embedding = vector("embedding", dimensions = 3) | ||
| </code-block> | ||
| This will set the dimensions format as using 32-bit floating-point numbers, if your | ||
| database supports explicit formats. | ||
| </li> | ||
| <li> | ||
| <p>Vector definition with type inference that sets the underlying format. Currently, the only options | ||
| available are <code>FloatArray</code> and <code>IntArray</code>:</p> | ||
| <code-block lang="kotlin"><![CDATA[ | ||
| val embedding = vector<IntArray>("embedding", 99) | ||
| ]]></code-block> | ||
| By default, <code>FloatArray</code> will set a 32-bit floating-point number format, while <code>IntArray</code> | ||
| will set an 8-bit integer format. | ||
| </li> | ||
| <li> | ||
| <p>Full vector definition with control over the accepted input type, the dimensions, and the underlying format:</p> | ||
| <code-block lang="kotlin"><![CDATA[ | ||
| val embedding = vector<FloatArray>("embedding", 2049, VectorFormat.FLOAT64) | ||
| ]]></code-block> | ||
| This is useful, for example, when an alternative floating-point format is required, like for 64-bit numbers. | ||
| </li> | ||
| </list> | ||
| <note> | ||
| <p>A <code>null</code> value can be passed to the <code>dimensions</code> parameter, to define a column with variable length vectors. | ||
| Not all databases support this functionality though. Please check your documentation before choosing this.</p> | ||
| </note> | ||
| </chapter> | ||
|
|
||
| <chapter title="Basic usage" id="basic-usage"> | ||
| <p> | ||
| Vector columns store and retrieve data as Kotlin primitive arrays, either <code>FloatArray</code> or <code>IntArray</code>, | ||
| providing a natural way to work with vector data in your code. | ||
| </p> | ||
| <p>You can define vector columns within a table definition as follows:</p> | ||
| <code-block lang="kotlin"><![CDATA[ | ||
| object MultipleVectors : Table("multiple_vectors") { | ||
| val ve1 = vector("ve1", dimensions = 3) | ||
| val ve2 = vector<IntArray>("ve2", 3) | ||
| val ve3 = vector<FloatArray>("ve3", 3, format = VectorFormat.FLOAT64) | ||
| } | ||
| ]]></code-block> | ||
| <p>Here's an example of inserting data into vector columns:</p> | ||
| <code-block lang="kotlin"><![CDATA[ | ||
| MultipleVectors.insert { | ||
| it[ve1] = floatArrayOf(1f, 0f, 0f) | ||
| it[ve2] = intArrayOf(10, 11, 12) | ||
| it[ve3] = floatArrayOf(0.234f, 0.345f, 0.567f) | ||
| } | ||
| ]]></code-block> | ||
| </chapter> | ||
| <chapter title="PostgreSQL usage" id="postgresql-vectors"> | ||
| <p>PostgreSQL provides support for the vector data type through the installation of the <a href="https://github.com/pgvector/pgvector">pgvector</a> | ||
| extension. Exposed assumes that this extension has already been enabled at some point prior to table creation or use of a vector column:</p> | ||
| <code-block lang="sql"> | ||
| CREATE EXTENSION IF NOT EXISTS vector; | ||
| </code-block> | ||
| <p>If this is not the case, usage of the column will result in a database exception.</p> | ||
| </chapter> | ||
|
|
||
| <chapter title="Vector functions" id="vector-functions"> | ||
| <p>Exposed provides vector distance functions with results being calculated based on the following distance similarity options:</p> | ||
| <list> | ||
| <li>Cosine</li> | ||
| <li>Euclidean</li> | ||
| <li>Dot product</li> | ||
| </list> | ||
| <p>Here's an example of querying vector data using a distance function:</p> | ||
| <code-block lang="kotlin"> | ||
| val distance = MultipleVectors.ve1.cosineDistance(floatArrayOf(0f, 1f, 0f)).alias("cd") | ||
| MultipleVectors | ||
| .select(distance) | ||
| .where { MultipleVectors.ve2.euclideanDistance(intArrayOf(1, 1, 1)) less 5 } | ||
| .orderBy(distance to SortOrder.ASC) | ||
| .toList() | ||
| </code-block> | ||
| <note> | ||
| <p>Not all databases support all available distance metrics. Please check your documentation before using them.</p> | ||
| </note> | ||
| </chapter> | ||
| </topic> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary to access PG vector extension. Should not impact rest of codebase tests as it sits on the official PG docker.