WARP.md
Documents a Docker-based Django development environment for testing PostgreSQL extensions (PostGIS, TimescaleDB, pgVector) with Python 3.14 and uv.
What this file does
Documents a Docker-based Django development environment for testing PostgreSQL extensions (PostGIS, TimescaleDB, pgVector) with Python 3.14 and uv.
When to use it
- You need a reproducible setup for experimenting with multiple PostgreSQL extensions
- You want to combine Django ORM with PostGIS, TimescaleDB, and pgVector in one project
- You are using WARP and need a project-specific orientation file
- You want to run local AI experiments with Ollama alongside a Django app
Assumes this stack
WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
Project Overview
PlaygreSQL is a Docker-based development environment for testing PostgreSQL extensions (PostGIS, TimescaleDB, pgVector) using Django ORM with Python 3.14 and the uv package manager. This is a development environment only and is not production-ready.
Architecture
Multi-Container Setup
The project uses Docker Compose with three services:
- db (PostgreSQL 16): Custom-built container with PostGIS 3.4, TimescaleDB, and pgVector extensions pre-installed and enabled via
init.sql - web (Django 5.2+): Python 3.14 container running Django with hot-reload for development
- ollama: LLM inference service for local AI experiments
Django Configuration
- Settings:
playgresql/settings.pyconditionally loads PostGIS support based onENABLE_GISenvironment variable - Database Backend: Automatically switches between
django.contrib.gis.db.backends.postgis(whenENABLE_GIS=true) anddjango.db.backends.postgresql - Sample Apps:
series/andvectors/are empty Django apps for TimescaleDB and pgVector experimentation - Demo Models:
extensions_demo.pycontains commented example models for all three extensions with usage patterns
Extension-Specific Patterns
PostGIS Models:
- Use
from django.contrib.gis.db import models as gis_models - Fields:
PointField(),LineStringField(),PolygonField() - Requires
ENABLE_GIS=trueenvironment variable
TimescaleDB Models:
- Use regular Django models with
DateTimeFieldas primary key - Convert to hypertables via migration using
migrations.RunSQL("SELECT create_hypertable('table_name', 'time', if_not_exists => TRUE);") - Time-based queries leverage TimescaleDB's automatic optimizations
pgVector Models:
- Store embeddings using
ArrayField(models.FloatField(), size=DIMENSIONS) - Or use
pgvector.django.VectorField(dimensions=DIMENSIONS)(as seen invectors/models.py) - Query with raw SQL using distance operators:
<=>(cosine),<->(L2),<#>(inner product)
Common Commands
Container Management
Start all services:
./start.sh # Automated with health checks and migrations
Or manually:
docker compose up --build
Stop and remove volumes (full reset):
docker compose down -v
Django Operations
All Django commands must be prefixed with docker compose exec web uv run:
Migrations:
docker compose exec web uv run python manage.py makemigrations
docker compose exec web uv run python manage.py migrate
Django Shell:
docker compose exec web uv run python manage.py shell
Create Superuser:
docker compose exec web uv run python manage.py createsuperuser
Create New App:
docker compose exec web uv run python manage.py startapp <app_name>
Then add to playgresql/settings.py INSTALLED_APPS.
Database Access
From host machine:
psql postgresql://postgres:postgres@localhost:5432/playgresql
Django dbshell:
docker compose exec web uv run python manage.py dbshell
Direct psql:
docker compose exec db psql -U postgres -d playgresql
Verification Commands
Check database health:
docker compose exec db pg_isready -U postgres
Verify extensions:
docker compose exec db psql -U postgres -d playgresql -c "SELECT extname, extversion FROM pg_extension;"
View logs:
docker compose logs -f
docker compose logs -f web # Django only
docker compose logs -f db # PostgreSQL only
Local Development (Optional)
Install dependencies locally without Docker:
uv sync
Run Django commands locally (requires local PostgreSQL):
uv run python manage.py migrate
Linting (ruff is in dev dependencies):
uv run ruff check .
Ollama Usage
Pull model:
docker compose exec ollama ollama pull llama2
Interactive session:
docker compose exec ollama ollama run llama2
From Django (OLLAMA_HOST is pre-configured to http://ollama:11434):
import os
print(os.getenv('OLLAMA_HOST'))
Development Workflow
Adding New Extension Features
- Copy relevant model examples from
extensions_demo.pyto your app'smodels.py - Create migrations:
docker compose exec web uv run python manage.py makemigrations - For TimescaleDB, add a second migration with
RunSQLto create hypertables - For pgVector, add indexes via raw SQL migrations for optimal performance
- Apply migrations:
docker compose exec web uv run python manage.py migrate
Working with TimescaleDB
After creating a time-series model, convert it to a hypertable in a migration:
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [('app_name', 'XXXX_previous_migration')]
operations = [
migrations.RunSQL(
"SELECT create_hypertable('table_name', 'time', if_not_exists => TRUE);",
reverse_sql="SELECT 1;"
),
]
Working with pgVector
Create vector indexes after initial table creation:
migrations.RunSQL(
"CREATE INDEX ON table_name USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);",
reverse_sql="DROP INDEX IF EXISTS table_name_embedding_idx;"
)
For similarity search, use raw SQL with distance operators in Django shell.
Important Notes
- The web container has hot-reload enabled; code changes reflect immediately without restart
- Database and Ollama data persist in Docker volumes between restarts
- Ollama is mapped to port 11435 (not 11434) to avoid conflicts with local instances
- Use
ENABLE_GIS=trueenvironment variable to enable PostGIS features - All credentials default to
postgres:postgresfor development convenience - Never commit
.envfile (use.env.exampleas template)
What's inside
7 sections covering project overview, architecture, commands, development workflow, and important notes with 6 code examples
Change this for your project
- Replace
playgresqlwith your project name in connection strings and settings paths - Replace
postgres:postgrescredentials with your own if different - Replace
llama2with the model you intend to use in Ollama commands - Replace
ENABLE_GIS=truewith your own environment variable name if needed
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Conditionally loading PostGIS backend based on an environment variable
- Using RunSQL migrations to create hypertables and vector indexes
- Pre-configuring OLLAMA_HOST in Django environment for container-to-container communication
Related Documents
Building SupportX AI Assist: A Multi-Agent IT Support System
Describes building a multi-agent IT support system with AutoGen, Azure AI Search, and Gemini embeddings for instant issue resolution and automatic escalation.
An Introduction to Transformers
Presents a slide deck introducing transformer architecture, attention mechanisms, and a PyTorch implementation from scratch.
SMART-CAM (Smart AI Camera) — Full Documentation
Documents an edge AI surveillance pipeline that detects people, extracts ReID embeddings, and tracks identities locally on a Raspberry Pi with optional Hailo NPU acceleration.
Building an AI Travel Assistant with Micronaut and LangChain4j
Builds a Micronaut travel advisor that embeds user queries, runs vector similarity search in Oracle AI Database, and returns semantically matched destinations via a chat endpoint.