Skip to content

Commit b36e2cc

Browse files
authored
[Doc] PG Extension (#315)
* [Doc] PG Extension * fix: missing link
1 parent ecc932d commit b36e2cc

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

doc/quickstart/database.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This guide walks you through deploying and connecting to a PostgreSQL database.
99
- [Connect to Your Database](#4-connect-to-your-database)
1010
- [Using Command Line (CLI)](#using-command-line-cli)
1111
- [Using pgAdmin (GUI)](#using-pgadmin-gui)
12+
- [Install Database Extensions](#5-install-database-extensions)
13+
- [DuckDB Extension](#duckdb-extension)
14+
- [PG Vector Extension](#pg-vector-extension)
1215

1316
(1-create-a-database)=
1417
## 1. Create a Database
@@ -104,3 +107,62 @@ Choose one of the following methods to connect to your database:
104107
4. Click "Save" to establish the connection
105108
5. Your database will appear in the server list
106109

110+
(5-install-database-extensions)=
111+
## 5. Install Database Extensions
112+
113+
(duckdb-extension)=
114+
### DuckDB Extension
115+
116+
To install and use the DuckDB extension in PostgreSQL:
117+
118+
```sql
119+
-- Install the DuckDB extension
120+
CREATE EXTENSION IF NOT EXISTS pg_duckdb;
121+
122+
-- Verify the installation
123+
SELECT * FROM pg_extension WHERE extname = 'pg_duckdb';
124+
125+
-- Example: Run a DuckDB query from PostgreSQL
126+
SELECT * FROM duckdb.query('
127+
FROM range(10) as a(a)
128+
SELECT [a for i in generate_series(0, a)] as arr
129+
');
130+
```
131+
132+
(pg-vector-extension)=
133+
### PG Vector Extension
134+
135+
To install and use the PG Vector extension for vector similarity search:
136+
137+
```sql
138+
-- Install the pgvector extension
139+
CREATE EXTENSION IF NOT EXISTS vector;
140+
141+
-- Verify the installation
142+
SELECT * FROM pg_extension WHERE extname = 'vector';
143+
144+
-- Example: Create a table with vector support
145+
CREATE TABLE items (
146+
id bigserial PRIMARY KEY,
147+
embedding vector(3) -- 3-dimensional vectors for this example
148+
);
149+
150+
-- Insert sample vectors
151+
INSERT INTO items (embedding)
152+
VALUES ('[1,2,3]'), ('[4,5,6]');
153+
154+
-- Query vectors by similarity (using cosine distance)
155+
SELECT * FROM items
156+
ORDER BY embedding <-> '[3,1,2]' -- Find vectors closest to [3,1,2]
157+
LIMIT 5;
158+
159+
-- Create an index for faster similarity search
160+
CREATE INDEX ON items USING ivfflat (embedding vector_cosine_ops);
161+
```
162+
163+
> 💡 **Note**:
164+
> - For vector operations, ensure your database instance has sufficient resources
165+
> - The vector dimension (3 in this example) should match your use case
166+
> - The `<->` operator calculates cosine distance between vectors
167+
> - Consider creating appropriate indexes for better query performance
168+

0 commit comments

Comments
 (0)