PostgreSQL

Connect to PostgreSQL with full async support, extensions, and vector search.

Configuration

Connection String

Connection Pooling

PostgreSQL-Specific Types

PostgreSQL Extensions

Prax supports PostgreSQL extensions through the datasource block in your schema. Extensions are automatically created during migrations.

💡 Schema vs Config Separation

schema.prax: Declares what database features to use (provider, extensions)

prax.toml: Configures how to connect (URL, pool settings, credentials)

Basic Usage

Common Extensions

Generated Migration

Prax generates CREATE EXTENSION statements at the beginning of migrations:

Vector Types

Prax provides native support for pgvector types for AI/ML embeddings and similarity search.

Vector Types Reference

@for (row of vectorTypesTable; track row.type) { }
Type Rust Type Storage Use Case
{{ row.type }} {{ row.rust }} {{ row.storage }} {{ row.use }}

Vector Indexes

Vector indexes enable fast approximate nearest neighbor (ANN) search. Choose the right index type based on your dataset size and quality requirements.

HNSW Index

Hierarchical Navigable Small World - Best recall, recommended for most use cases.

IVFFlat Index

Inverted File with Flat quantization - Faster builds, good for large datasets.

Index Comparison

@for (row of vectorIndexComparison; track row.aspect) { }
Aspect HNSW IVFFlat
{{ row.aspect }} {{ row.hnsw }} {{ row.ivfflat }}

Distance Operations

Choose the distance metric that matches your embedding model. Most text embeddings (OpenAI, Cohere) are normalized and work best with Cosine distance.

@for (row of vectorOpsTable; track row.op) { }
Operation PostgreSQL Ops Operator Best For
{{ row.op }} {{ row.pgOps }} {{ row.operator }} {{ row.best }}

💡 Which distance metric should I use?

  • Cosine: Text embeddings (OpenAI, Cohere, etc.) - vectors are normalized
  • L2: Image features (ResNet, CLIP) - vectors are NOT normalized
  • Inner Product: When you need maximum inner product search (MIPS)

Querying Vectors

Use the generated query builder to perform similarity search.

Best Practices

Generated SQL

Prax generates optimized SQL for vector indexes during migrations.