You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/content/guides/ai/semantic-search.mdx
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,15 +48,15 @@ To implement semantic search in Postgres we use `pgvector` - an extension that a
48
48
createtabledocuments (
49
49
id bigintprimary key generated always as identity,
50
50
content text,
51
-
embedding vector(512)
51
+
embedding extensions.vector(512)
52
52
);
53
53
```
54
54
55
55
Or if you have an existing table, you can add a vector column like so:
56
56
57
57
```sql
58
58
altertable documents
59
-
add column embedding vector(512);
59
+
add column embedding extensions.vector(512);
60
60
```
61
61
62
62
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.
@@ -80,7 +80,7 @@ The easiest way to perform semantic search in Postgres is by creating a function
80
80
```sql
81
81
-- Match documents using cosine distance (<=>)
82
82
create or replacefunctionmatch_documents (
83
-
query_embedding vector(512),
83
+
query_embedding extensions.vector(512),
84
84
match_threshold float,
85
85
match_count int
86
86
)
@@ -108,7 +108,7 @@ You'll notice we are using the cosine distance (`<=>`) operator in our query. Co
108
108
```sql
109
109
-- Match documents using negative inner product (<#>)
110
110
create or replacefunctionmatch_documents (
111
-
query_embedding vector(512),
111
+
query_embedding extensions.vector(512),
112
112
match_threshold float,
113
113
match_count int
114
114
)
@@ -142,7 +142,7 @@ You can also call this method directly from SQL:
142
142
```sql
143
143
select*
144
144
from match_documents(
145
-
'[...]'::vector(512), -- pass the query embedding
145
+
'[...]'::extensions.vector(512), -- pass the query embedding
146
146
0.78, -- chose an appropriate threshold for your data
0 commit comments