There is no specific code to create an extension inside the Drizzle schema. We assume that if you are using vector types, indexes, and queries, you have a PostgreSQL database with the pg_vector extension installed.
PostgreSQL extensions
pg_vector
pg_vector
is open-source vector similarity search for Postgres
Store your vectors with the rest of your data. Supports:
- exact and approximate nearest neighbor search
- single-precision, half-precision, binary, and sparse vectors
- L2 distance, inner product, cosine distance, L1 distance, Hamming distance, and Jaccard distance
Column Types
vector
Store your vectors with the rest of your data
For more info please refer to the official pg_vector docs docs.
Indexes
You can now specify indexes for pg_vector
and utilize pg_vector
functions for querying, ordering, etc.
Let’s take a few examples of pg_vector
indexes from the pg_vector
docs and translate them to Drizzle
L2 distance, Inner product and Cosine distance
L1 distance, Hamming distance and Jaccard distance - added in pg_vector 0.7.0 version
Helper Functions
For queries, you can use predefined functions for vectors or create custom ones using the SQL template operator.
You can also use the following helpers:
If pg_vector
has some other functions to use, you can replicate implementation from existing one we have. Here is how it can be done
Name it as you wish and change the operator. This example allows for a numbers array, strings array, string, or even a select query. Feel free to create any other type you want or even contribute and submit a PR
Examples
Let’s take a few examples of pg_vector
queries from the pg_vector
docs and translate them to Drizzle
postgis
There is no specific code to create an extension inside the Drizzle schema. We assume that if you are using postgis types, indexes, and queries, you have a PostgreSQL database with the postgis
extension installed.
As PostGIS website mentions:
PostGIS extends the capabilities of the PostgreSQL relational database by adding support for storing, indexing, and querying geospatial data.
If you are using the introspect
or push
commands with the PostGIS extension and don’t want PostGIS tables to be included, you can use extensionsFilters
to ignore all the PostGIS tables
Column Types
geometry
Store your geometry data with the rest of your data
For more info please refer to the official PostGIS docs docs.
mode
Type geometry
has 2 modes for mappings from the database: tuple
and xy
.
tuple
will be accepted for insert and mapped on select to a tuple. So, the database geometry will be typed as [1,2] with drizzle.xy
will be accepted for insert and mapped on select to an object with x, y coordinates. So, the database geometry will be typed as{ x: 1, y: 2 }
with drizzle
type
The current release has a predefined type: point
, which is the geometry(Point)
type in the PostgreSQL PostGIS extension. You can specify any string there if you want to use some other type
Indexes
With the available Drizzle indexes API, you should be able to write any indexes for PostGIS
Examples