Skip to content

hostari/fastapi-pgvector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + PostgreSQL + pgvector

A minimal FastAPI service demonstrating pgvector usage with async SQLAlchemy.

Features

  • GET / — Hello World
  • GET /health — Health check
  • POST /vectors/ — Store a vector embedding with a label
  • GET /vectors/ — List all stored vectors
  • POST /vectors/search — Find nearest neighbours by L2 distance

Quick Start

cp .env.example .env
# Edit .env as needed
docker compose up --build

The API will be available at http://localhost:8000 Interactive docs: http://localhost:8000/docs

Environment Variables

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)

Example: Store and search vectors

# 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, edit VECTOR_DIM in app/models.py before the first run.

About

FastAPI + PostgreSQL + pgvector starter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors