Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/guides/ai/engineering-for-scale.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ We can now create a foreign table to access the data in our secondary project.
```sql
create foreign table docs (
id text not null,
embedding vector(384),
embedding extensions.vector(384),
metadata jsonb,
url text
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def seed():
"id": "text",
"start_time": "float8",
"end_time": "float8",
"embedding": "vector(768)",
"embedding": "extensions.vector(768)",
"metadata": "jsonb"
})

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/guides/ai/examples/nextjs-vector-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Let's prepare the database schema. We can use the "OpenAI Vector Search" quickst
page_id bigint not null references public.nods_page on delete cascade,
content text,
token_count int,
embedding vector(1536),
embedding extensions.vector(1536),
slug text,
heading text
);
Expand All @@ -156,7 +156,7 @@ Let's prepare the database schema. We can use the "OpenAI Vector Search" quickst
```sql
-- Create embedding similarity search functions
create or replace function match_page_sections(
embedding vector(1536),
embedding extensions.vector(1536),
match_threshold float,
match_count int,
min_content_length int
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/content/guides/ai/hybrid-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ create table documents (
id bigint primary key generated always as identity,
content text,
fts tsvector generated always as (to_tsvector('english', content)) stored,
embedding vector(512)
embedding extensions.vector(512)
);
```

Expand Down Expand Up @@ -83,7 +83,7 @@ Finally we'll create our `hybrid_search` function:
```sql
create or replace function hybrid_search(
query_text text,
query_embedding vector(512),
query_embedding extensions.vector(512),
match_count int,
full_text_weight float = 1,
semantic_weight float = 1,
Expand Down Expand Up @@ -158,7 +158,7 @@ select
from
hybrid_search(
'Italian recipes with tomato sauce', -- user query
'[...]'::vector(512), -- embedding generated from user query
'[...]'::extensions.vector(512), -- embedding generated from user query
10
);
```
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/guides/ai/langchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ create table documents (
id bigserial primary key,
content text, -- corresponds to Document.pageContent
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
embedding extensions.vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);

-- Create a function to search for documents
create function match_documents (
query_embedding vector(1536),
query_embedding extensions.vector(1536),
match_count int default null,
filter jsonb DEFAULT '{}'
) returns table (
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/guides/ai/rag-with-permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ create table document_sections (
id bigint primary key generated always as identity,
document_id bigint not null references documents (id),
content text not null,
embedding vector (384)
embedding extensions.vector (384)
);
```

Expand Down Expand Up @@ -176,7 +176,7 @@ create table document_sections (
id bigint primary key generated always as identity,
document_id bigint not null,
content text not null,
embedding vector (384)
embedding extensions.vector (384)
);
```

Expand Down
10 changes: 5 additions & 5 deletions apps/docs/content/guides/ai/semantic-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ To implement semantic search in Postgres we use `pgvector` - an extension that a
create table documents (
id bigint primary key generated always as identity,
content text,
embedding vector(512)
embedding extensions.vector(512)
);
```

Or if you have an existing table, you can add a vector column like so:

```sql
alter table documents
add column embedding vector(512);
add column embedding extensions.vector(512);
```

In this example, we create a column named `embedding` which uses the newly enabled `vector` data type. The size of the vector (as indicated in parentheses) represents the number of dimensions in the embedding. Here we use 512, but adjust this to match the number of dimensions produced by your embedding model.
Expand All @@ -80,7 +80,7 @@ The easiest way to perform semantic search in Postgres is by creating a function
```sql
-- Match documents using cosine distance (<=>)
create or replace function match_documents (
query_embedding vector(512),
query_embedding extensions.vector(512),
match_threshold float,
match_count int
)
Expand Down Expand Up @@ -108,7 +108,7 @@ You'll notice we are using the cosine distance (`<=>`) operator in our query. Co
```sql
-- Match documents using negative inner product (<#>)
create or replace function match_documents (
query_embedding vector(512),
query_embedding extensions.vector(512),
match_threshold float,
match_count int
)
Expand Down Expand Up @@ -142,7 +142,7 @@ You can also call this method directly from SQL:
```sql
select *
from match_documents(
'[...]'::vector(512), -- pass the query embedding
'[...]'::extensions.vector(512), -- pass the query embedding
0.78, -- chose an appropriate threshold for your data
10 -- choose the number of matches
);
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/content/guides/ai/structured-unstructured.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Most vector stores treat metadata associated with embeddings like NoSQL, unstruc
```sql
create table docs (
id uuid primary key,
embedding vector(3),
embedding extensions.vector(3),
content text,
url text
);
Expand All @@ -31,7 +31,7 @@ Notice that we've associated two pieces of metadata, `content` and `url`, with t
```sql
create table docs (
id uuid primary key,
embedding vector(3),
embedding extensions.vector(3),
meta jsonb
);

Expand Down Expand Up @@ -84,7 +84,7 @@ The structured metadata style is recommended when the fields being tracked are k
```sql
create table docs (
id uuid primary key,
embedding vector(3),
embedding extensions.vector(3),
content text,
url string,
meta jsonb
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/guides/ai/vector-columns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ create table documents (
id serial primary key,
title text not null,
body text not null,
embedding vector(384)
embedding extensions.vector(384)
);
```

Expand Down Expand Up @@ -113,7 +113,7 @@ Supabase client libraries like `supabase-js` connect to your Postgres instance v

```sql
create or replace function match_documents (
query_embedding vector(384),
query_embedding extensions.vector(384),
match_threshold float,
match_count int
)
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/guides/database/extensions/http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ A successful call to a web URL from the `http` extension returns a record with t
select
"status", "content"::jsonb
from
http_get('https://jsonplaceholder.typicode.com/todos/1');
extensions.http_get('https://jsonplaceholder.typicode.com/todos/1');
```

### Simple `POST` example
Expand All @@ -103,7 +103,7 @@ from
select
"status", "content"::jsonb
from
http_post(
extensions.http_post(
'https://jsonplaceholder.typicode.com/posts',
'{ "title": "foo", "body": "bar", "userId": 1 }',
'application/json'
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/guides/database/extensions/pgrouting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ create table wi29 (
id bigint,
x float,
y float,
geom geometry
geom gis.geometry
);

insert into wi29 (id, x, y)
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/guides/database/extensions/pgvector.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ create table posts (
id serial primary key,
title text not null,
body text not null,
embedding vector(384)
embedding extensions.vector(384)
);
```

Expand Down
27 changes: 9 additions & 18 deletions apps/docs/content/guides/database/extensions/postgis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ You can get started with PostGIS by enabling the PostGIS extension in your Supab
<TabPanel id="sql" label="SQL">

```sql
-- Create a dedicated separate schema
create schema if not exists "gis";

-- Example: enable the "postgis" extension
create extension postgis with schema "gis";
create extension postgis with schema "extensions";

-- Example: disable the "postgis" extension
drop extension if exists postgis;
Expand All @@ -58,7 +55,7 @@ Let’s create our table. Each row represents a restaurant with its location sto
create table if not exists public.restaurants (
id int generated by default as identity primary key,
name text not null,
location gis.geography(POINT) not null
location extensions.geography(POINT) not null
);
```

Expand Down Expand Up @@ -102,9 +99,9 @@ You can insert geographical data through SQL or through our API.
insert into public.restaurants
(name, location)
values
('Supa Burger', gis.st_point(-73.946823, 40.807416)),
('Supa Pizza', gis.st_point(-73.94581, 40.807475)),
('Supa Taco', gis.st_point(-73.945826, 40.80629));
('Supa Burger', extensions.st_point(-73.946823, 40.807416)),
('Supa Pizza', extensions.st_point(-73.94581, 40.807475)),
('Supa Taco', extensions.st_point(-73.945826, 40.80629));
```

</TabPanel>
Expand Down Expand Up @@ -216,18 +213,12 @@ returns table (id public.restaurants.id%TYPE, name public.restaurants.name%TYPE,
set search_path = ''
language sql
as $$
select id, name, gis.st_y(location::gis.geometry) as lat, gis.st_x(location::gis.geometry) as long, gis.st_distance(location, gis.st_point(long, lat)::gis.geography) as dist_meters
select id, name, extensions.st_y(location::extensions.geometry) as lat, extensions.st_x(location::extensions.geometry) as long, extensions.st_distance(location, extensions.st_point(long, lat)::extensions.geography) as dist_meters
from public.restaurants
order by location operator(gis.<->) gis.st_point(long, lat)::gis.geography;
order by location operator(extensions.<->) extensions.st_point(long, lat)::extensions.geography;
$$;
```

Before being able to call this function from our client we need to grant access to our `gis` schema:

```sql
grant usage on schema gis to anon, authenticated;
```

Now you can call this function from your client using `rpc()` like this:

<Tabs
Expand Down Expand Up @@ -347,9 +338,9 @@ returns table (id public.restaurants.id%TYPE, name public.restaurants.name%TYPE,
set search_path to ''
language sql
as $$
select id, name, gis.st_y(location::gis.geometry) as lat, gis.st_x(location::gis.geometry) as long
select id, name, extensions.st_y(location::extensions.geometry) as lat, extensions.st_x(location::extensions.geometry) as long
from public.restaurants
where location operator(gis.&&) gis.ST_SetSRID(gis.ST_MakeBox2D(gis.ST_Point(min_long, min_lat), gis.ST_Point(max_long, max_lat)), 4326)
where location operator(extensions.&&) extensions.ST_SetSRID(extensions.ST_MakeBox2D(extensions.ST_Point(min_long, min_lat), extensions.ST_Point(max_long, max_lat)), 4326)
$$;
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ create extension if not exists vector with schema extensions;
create table embeddings (
id bigint primary key generated always as identity,
content text not null,
embedding vector (384)
embedding extensions.vector (384)
);
alter table embeddings enable row level security;

Expand Down Expand Up @@ -72,7 +72,7 @@ Given the [following Postgres Function](https://github.com/supabase/supabase/blo
--
-- Returns a setof embeddings so that we can use PostgREST resource embeddings (joins with other tables)
-- Additional filtering like limits can be chained to this function call
create or replace function query_embeddings(embedding vector(384), match_threshold float)
create or replace function query_embeddings(embedding extensions.vector(384), match_threshold float)
returns setof embeddings
language plpgsql
as $$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ select
'PostgreSQL package manager',
resp.contents ->> 'sql'
)
from http(
from extensions.http(
(
'GET',
'https://api.database.dev/rest/v1/'
Expand All @@ -35,7 +35,7 @@ from http(
|| '&order=version.desc'
|| '&limit=1',
array[
('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::http_header
('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::extensions.http_header
],
null,
null
Expand Down Expand Up @@ -141,7 +141,7 @@ select
'PostgreSQL package manager',
resp.contents ->> 'sql'
)
from http(
from extensions.http(
(
'GET',
'https://api.database.dev/rest/v1/'
Expand All @@ -150,7 +150,7 @@ from http(
|| '&order=version.desc'
|| '&limit=1',
array[
('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::http_header
('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::extensions.http_header
],
null,
null
Expand Down
Loading
Loading