Vector Search Quickstart for PostgreSQL

Validated on 27 Apr 2026 • Last edited on 27 Apr 2026

DigitalOcean Managed PostgreSQL for vector search uses the same managed PostgreSQL engine available under Managed Databases, with the pgvector and pgvectorscale extensions for storing and querying vector embeddings alongside relational data.

This quickstart walks you through creating a DigitalOcean Managed PostgreSQL cluster, enabling the pgvector extension, storing a handful of sample embeddings, and running a similarity search. It takes about 10 minutes.

Prerequisites

  • A DigitalOcean account.
  • A terminal with psql installed.
  • An embedding pipeline. PostgreSQL does not generate embeddings; generate them in your application and send them as parameter-bound values. See Enable pgvector and Load Embeddings for provider examples.

Step 1: Create a Managed PostgreSQL Cluster

  1. In the Control Panel, click Create > Vector Database.
  2. Select PostgreSQL as the engine and pick the latest version.
  3. Choose a machine size and region.
  4. Name the cluster and click Create Vector Database Cluster.

For full options, see Create a PostgreSQL Cluster.

Step 2: Secure the Cluster and Get Connection Details

On the cluster’s Overview tab:

  1. Copy the connection string from Connection Details.
  2. Under Network Access, add the IP addresses or DigitalOcean resources that should be allowed to connect. Until you do this, the cluster rejects all traffic.

See Secure PostgreSQL Clusters with Trusted Sources for details.

Step 3: Enable the Vector Extension

Connect with psql and enable the extension:

psql "postgresql://doadmin:PASSWORD@HOST:25060/defaultdb?sslmode=require"
CREATE EXTENSION IF NOT EXISTS vector;
\dx vector
Note
The project is named pgvector, but the registered extension name is vector. CREATE EXTENSION pgvector; fails. Always use CREATE EXTENSION vector;.

Step 4: Store Embeddings

Create a table with a vector column sized to match your embedding model. This example uses 1,536 dimensions, which matches OpenAI text-embedding-3-small.

CREATE TABLE documents (
    id         bigserial PRIMARY KEY,
    content    text        NOT NULL,
    embedding  vector(1536),
    created_at timestamptz NOT NULL DEFAULT now()
);

Generate an embedding in your application, then insert it:

INSERT INTO documents (content, embedding) VALUES ($1, $2);

pgvector accepts vectors in the textual form [v1, v2, ...].

Given a query embedding, return the five most similar documents ordered by cosine distance:

SELECT id, content, 1 - (embedding <=> $1) AS cosine_similarity
FROM   documents
ORDER  BY embedding <=> $1
LIMIT  5;

For production workloads, add an HNSW index to the embedding column. See Index and Tune Vector Search.

Next Steps

We can't find any results for your search.

Try using different keywords or simplifying your search terms.