---
title: "Deploy pgvector-pg17: Postgres Vector DB for Embeddings and RAG"
description: "PostgreSQL 17 vector database for AI: embeddings, RAG, semantic search"
category: "Storage"
url: https://railway.com/deploy/qcuy_M
---

# Deploy pgvector-pg17: Postgres Vector DB for Embeddings and RAG

PostgreSQL 17 vector database for AI: embeddings, RAG, semantic search

**[Deploy pgvector-pg17: Postgres Vector DB for Embeddings and RAG on Railway](https://railway.com/template/qcuy_M)**

- **Creator:** ProCode
- **Category:** Storage
- **Total deploys:** 390

## Template content

### pgvector https://devicons.railway.app/i/postgresql.svg

- **Image:** pgvector/pgvector:pg17
- **Start command:** `/bin/sh -c "unset PGPORT; docker-entrypoint.sh postgres --port=5432"`

## Documentation

## PostgreSQL v17 with pgvector

**TL;DR:** This template is like the existing pgvector template, but with PostgreSQL v17 instead of PostgreSQL v16.

### What is PGVector?

PGVector is an extension for PostgreSQL that enables efficient storage and retrieval of vector embeddings, making it ideal for machine learning and AI applications like similarity search. It adds support for vector data types and indexing methods to facilitate quick querying on high-dimensional vectors.

### How to Use the Template

This template provides PostgreSQL v17 with the pgvector extension pre-installed. You’ll need to enable the `pgvector` extension in each database where you intend to use it.

1. **Connection Setup:**
   - Find the appropriate connection string under the service variables tab:
     - `DATABASE_URL`: Used for connecting from other Railway services.
     - `DATABASE_PUBLIC_URL`: Used for connecting from external services/tools.
   - Reference these URLs in your other services variables as needed (For instance, `${{ pgvector.DATABASE_URL }}`)

2. **Enabling PGVector Extension:**
   Before using pgvector, you must enable the extension in your database:
   ```sql
   CREATE EXTENSION IF NOT EXISTS vector;
   ```

### Example Usage Script

Here’s a simple example to verify that the pgvector extension is set up and working as expected:
   ```sql
   CREATE EXTENSION IF NOT EXISTS vector;
   
   -- Create a table with an embedding vector
   CREATE TABLE items (
       id bigserial PRIMARY KEY,
       embedding vector(3)
   );
   
   -- Insert some example data
   INSERT INTO items (embedding) VALUES 
   ('[1,2,3]'), 
   ('[4,5,6]');
   
   -- Perform a vector similarity search
   SELECT * FROM items 
   ORDER BY embedding &lt;-&gt; '[3,1,2]' 
   LIMIT 5;
   ```

This SQL snippet sets up the pgvector extension, creates a table, inserts data, and runs a basic similarity query using the `&lt;-&gt;` operator to measure vector distance.

### Further Information

For more details on PGVector, visit the official GitHub repository: https://github.com/pgvector/pgvector

## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/qcuy_M
