Skip to main content
All integrationsDatabase

PostgreSQL Integration

Async PostgreSQL with pgvector, migrations, and connection pooling.

FastAPI AI Kit uses SQLAlchemy 2.0 async with PostgreSQL. Alembic migrations, connection pooling, pgvector for embeddings, and JSONB for flexible storage — all configured.

Setup in 4 steps

  1. 1Set DATABASE_URL in your .env
  2. 2Run alembic upgrade head to apply migrations
  3. 3pgvector extension enabled automatically on first migration
  4. 4Connection pool settings configurable in config.py

What's included

  • SQLAlchemy 2.0 async ORM with full type annotations
  • Alembic migrations with auto-generate support
  • pgvector extension for embedding storage and similarity search
  • Connection pooling with asyncpg driver
  • JSONB columns for flexible structured data storage

Code example

example.py
# models.py — full async SQLAlchemy 2.0
class Document(Base):
    __tablename__ = "documents"
    id: Mapped[uuid.UUID] = mapped_column(primary_key=True)
    content: Mapped[str]
    embedding: Mapped[list[float]] = mapped_column(Vector(1536))
    metadata: Mapped[dict] = mapped_column(JSONB, default=dict)

# Similarity search with pgvector
async def search_similar(query_embedding, top_k=5):
    return await db.execute(
        select(Document)
        .order_by(Document.embedding.l2_distance(query_embedding))
        .limit(top_k)
    )

Full documentation: /docs/project-structure

PostgreSQL integration pre-wired and ready.

FastAPI AI Kit ships with PostgreSQL configured out of the box. No manual setup required.

Ready to ship your AI backend this weekend?

Join developers who skipped weeks of boilerplate and went straight to building.

Read the docs
No subscriptions · One-time payment · Lifetime updates