Enable the PGVector Plugin¶
pgvector is an extension for storing and manipulating vector data in the PostgreSQL database. It provides support for high-dimensional vector data, allowing users to directly store, retrieve, and manipulate vectors in a relational database. Its main features include:
- Vector storage: Supports storing high-dimensional vectors directly in PostgreSQL tables, making it convenient to use together with other relational data.
- Similarity search: Provides efficient vector similarity search algorithms, such as Euclidean distance, cosine similarity, and inner product, making vector search in the database efficient and convenient.
- Index support: Supports using vector indexes (such as L2, IP, and Cosine) to accelerate vector similarity search and improve query performance.
Enable the pgvector Extension¶
-
Log in to the PostgreSQL instance and execute the following SQL command in a database with pgvector pre-enabled to create the pgvector extension plugin.
Verify the pgvector Plugin¶
-
Create a test table containing vector data, and insert some test vector data.
-
Query the vector data in the table.
The returned result is as follows:
```json
id | embedding
----+-----------
1 | [1, 2, 3]
2 | [4, 5, 6]
3 | [7, 8, 9]
```
Verify the Vector Similarity Search¶
-
Execute the following SQL to verify the similarity search feature.
The returned result is as follows:
```json
id | embedding
----+-----------
1 | [1, 2, 3]
2 | [4, 5, 6]
3 | [7, 8, 9]
```