---
title: "Deploy pgvector-pg18"
description: "PostgreSQL 18 vector database for AI: embeddings, RAG, semantic search"
category: "Storage"
url: https://railway.com/deploy/pgvector-pg18
---

# Deploy pgvector-pg18

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

**[Deploy pgvector-pg18 on Railway](https://railway.com/template/pgvector-pg18)**

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

## Template content

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

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

## Documentation

# Deploy and Host pgvector-pg18 on Railway

**TL;DR:** This template is like the existing pgvector template, but with PostgreSQL v18 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.

## About Hosting pgvector-pg18

This template provides PostgreSQL v18 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;
   ```

## Common Use Cases

- NLP Applications (Semantec text search, RAG applications)
- Similarity Search (Similar item recommendations, Related documents)
- Image Similarity Search (Visual similarity, Product image matching)
- Anomaly Detection (Fraud detection, Log analysis)

## 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.

## Dependencies for pgvector-pg18 Hosting

The Railway template includes the required dependencies with pre-configured deployment settings.

### Deployment Dependencies

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

## Why Deploy pgvector-pg18 on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying pgvector-pg18 on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## 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/pgvector-pg18
