Skip to content

docs: add async SQLAlchemy + HNSW full example#151

Open
ChunkyTortoise wants to merge 1 commit intopgvector:masterfrom
ChunkyTortoise:docs/async-sqlalchemy-hnsw-example
Open

docs: add async SQLAlchemy + HNSW full example#151
ChunkyTortoise wants to merge 1 commit intopgvector:masterfrom
ChunkyTortoise:docs/async-sqlalchemy-hnsw-example

Conversation

@ChunkyTortoise
Copy link

Summary

The README documents async driver registration (Psycopg 3 register_vector_async) and HNSW index creation separately, but there's no combined example showing the end-to-end async pattern that production FastAPI/async Python applications typically use.

This adds a complete working example under "Async Full Example" in the SQLAlchemy section showing:

  • Async engine + session setup (async_sessionmaker)
  • Extension creation + table setup (run_sync)
  • HNSW index creation with vector_cosine_ops
  • Async vector insertion
  • Async cosine distance nearest-neighbor query

Motivation

I use this exact pattern in a production document extraction API (docextract) with 768-dim Gemini embeddings, and had to piece together the async + HNSW workflow from separate README sections and test files. A combined example would have saved significant time.

Test plan

  • Example is syntactically valid Python
  • Follows existing README conventions (single quotes, same model pattern)
  • Placed after async driver registration, before SQLModel section

🤖 Generated with Claude Code

Add a complete working example showing async SQLAlchemy with HNSW
indexing and cosine distance queries. The README documents async
driver registration and HNSW index creation separately, but lacks
a combined example showing the most common production pattern
(async engine + HNSW index + cosine nearest-neighbor queries).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant