A minimal FastAPI service demonstrating pgvector usage with async SQLAlchemy.
GET /— Hello WorldGET /health— Health checkPOST /vectors/— Store a vector embedding with a labelGET /vectors/— List all stored vectorsPOST /vectors/search— Find nearest neighbours by L2 distance
cp .env.example .env
# Edit .env as needed
docker compose up --buildThe API will be available at http://localhost:8000 Interactive docs: http://localhost:8000/docs
| Variable | Default | Description |
|---|---|---|
POSTGRES_USER |
postgres |
DB username |
POSTGRES_PASSWORD |
postgres |
DB password |
POSTGRES_DB |
vectordb |
Database name |
DATABASE_URL |
(derived) | Full async DB URL (overrides individual vars) |
# Store a vector
curl -X POST http://localhost:8000/vectors/ \
-H "Content-Type: application/json" \
-d '{"label": "example", "content": "some text", "embedding": [0.1, 0.2, ...]}'
# Search for similar vectors
curl -X POST http://localhost:8000/vectors/search \
-H "Content-Type: application/json" \
-d '{"vector": [0.1, 0.2, ...], "top_k": 3}'Note: The default embedding dimension is 1536 (OpenAI
text-embedding-ada-002). To change it, editVECTOR_DIMinapp/models.pybefore the first run.