A Postgres extension in Rust that adds a DiskANN-based index and label filtering on top of pgvector for faster, cheaper vector search.
pgvector/pgvector-python
Python library that adds pgvector vector-type and similarity search support to Django, SQLAlchemy, Psycopg, asyncpg, Peewee and other PostgreSQL drivers.
- Stars
- 1,542
- Forks
- 104
- Open issues
- 9
- Last commit
- 2 days ago
What is it?
pgvector-python is a Python client library that lets applications store and query vectors in PostgreSQL through the pgvector extension. It provides vector, half-precision, bit and sparse vector types, along with distance operators for L2, inner product, cosine, L1, Hamming and Jaccard comparisons.
The package integrates with a range of Python database stacks, including Django, SQLAlchemy, SQLModel, Psycopg 2 and 3, asyncpg, pg8000 and Peewee. Each integration covers the common steps: enabling the extension, adding a vector column, inserting embeddings, running nearest-neighbor queries, and creating HNSW or IVFFlat indexes.
The repository also includes example scripts for retrieval-augmented generation with Ollama, embeddings with OpenAI and Cohere, hybrid search, image search, recommendations and bulk loading with COPY.
Key features
- 01Supports Django, SQLAlchemy, SQLModel, Psycopg 2/3, asyncpg, pg8000 and Peewee.
- 02Provides vector, half-precision, bit and sparse vector field types.
- 03Offers distance operators including L2, inner product, cosine, L1, Hamming and Jaccard.
- 04Creates HNSW and IVFFlat approximate indexes through each library's API.
- 05Converts between Python lists, NumPy arrays and SciPy sparse arrays.
Use cases
- Adding semantic search or RAG retrieval to a Django or SQLAlchemy application backed by PostgreSQL.
- Storing text or image embeddings from OpenAI, Cohere or SentenceTransformers in Postgres.
- Building recommendation features from user-item vectors inside an existing Postgres database.
Quick start
- 1
Install the package from PyPI
pip install pgvector - 2
Enable the pgvector extension in your PostgreSQL database (Psycopg 3 example)
conn.execute('CREATE EXTENSION IF NOT EXISTS vector') - 3
Register the vector type with your connection, then insert and query vectors following the README for your library
register_vector(conn)
Things to know
- Requires the pgvector extension installed on your PostgreSQL server.
- Each database library needs its own setup steps and registration code.
In collections
Topics
FAQ
- What is pgvector-python?
- Python library that adds pgvector vector-type and similarity search support to Django, SQLAlchemy, Psycopg, asyncpg, Peewee and other PostgreSQL drivers. pgvector-python is a Python client library that lets applications store and query vectors in PostgreSQL through the pgvector extension. It provides vector, half-precision, bit and sparse vector types, along with distance operators for L2, inner product, cosine, L1, Hamming and Jaccard comparisons.
- Is pgvector-python free to use? What license does it have?
- pgvector-python is open source under the MIT license. Check the license terms before using it in commercial products.
- Is pgvector-python still maintained?
- Actively maintained. The last commit to pgvector-python was on Nov 5, 2026.
- What can I use pgvector-python for?
- Adding semantic search or RAG retrieval to a Django or SQLAlchemy application backed by PostgreSQL. Storing text or image embeddings from OpenAI, Cohere or SentenceTransformers in Postgres. Building recommendation features from user-item vectors inside an existing Postgres database.
- How do I install pgvector-python?
- Install the package from PyPI: pip install pgvector Enable the pgvector extension in your PostgreSQL database (Psycopg 3 example): conn.execute('CREATE EXTENSION IF NOT EXISTS vector') Register the vector type with your connection, then insert and query vectors following the README for your library: register_vector(conn)
- Where can I get pgvector-python?
- The source code and installation instructions are on GitHub: https://github.com/pgvector/pgvector-python
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Go support for the pgvector PostgreSQL extension, with vector types and helpers for pgx, pg, Bun, Ent, GORM and sqlx.
JavaScript and TypeScript helper library that adds pgvector vector type support to Node.js, Deno, and Bun database clients and ORMs.
Milvus is an open-source, distributed vector database for storing and searching embeddings at scale, used for AI search and RAG applications.
Qdrant is a Rust-based vector similarity search engine and vector database with payload filtering, for semantic search and recommendation.
Open-source vector similarity search extension for Postgres, storing and querying embeddings alongside your relational data.