skillfed

langchain-postgres

An integration package connecting Postgres and LangChain

langchain-postgres v0.0.17 1.6M downloads/30d#3,743 on PyPI
Permissive license MIT Active released

What it is and what it does

langchain-postgres bridges LangChain and PostgreSQL, providing implementations of core LangChain abstractions (vector stores, chat message history, document storage) that persist data in a Postgres database. It supports both synchronous and asynchronous workflows and offers two driver options: asyncpg and psycopg3.

The package's main components are PGVectorStore for semantic search with optional hybrid search (combining vector and keyword matching), and PostgresChatMessageHistory for persisting conversation state across sessions. Both are designed to be used directly or extended for custom applications. The package depends on sqlalchemy for ORM operations, pgvector for vector operations, and numpy for numerical work.

Use it for:

  • Build a RAG (retrieval-augmented generation) application that stores document embeddings in Postgres and retrieves relevant context for LLM prompts.
  • Persist multi-turn chat conversations in a database so users can resume sessions or audit interaction history.
  • Implement hybrid search combining semantic similarity and keyword matching to improve retrieval relevance.
  • Deploy LangChain applications on cloud-hosted Postgres (AlloyDB, Cloud SQL) with simplified connection management.
  • Extend the provided abstractions to add custom metadata filtering or schema changes for domain-specific requirements.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides LangChain abstractions for vector storage, chat history, and document management backed by PostgreSQL with support for both synchronous and asynchronous operations.

Yes. The package is actively maintained, has low install friction, carries no known vulnerabilities, and is licensed permissively. It fills a clear role for developers building LangChain applications that need persistent vector storage or chat history in PostgreSQL. Install it if you are already using LangChain and need a Postgres-backed vector store or session manager; skip it if you do not use LangChain or prefer a different database backend.

Install

langchain-postgres on PyPI

pip

pip install langchain-postgres

uv

uv add langchain-postgres

poetry

poetry add langchain-postgres

Installing langchain-postgres

Before you install

Low friction installation with a pure-Python wheel. Actively maintained as of the latest release. Requires PostgreSQL and one of two supported drivers (asyncpg or psycopg3), which are listed as runtime dependencies.

License in practice

Released under the MIT license (permissive), allowing free use, modification, and distribution with minimal restrictions.

Quickstart

pip install langchain-postgres

from langchain_postgres import PGEngine, PGVectorStore
from langchain_core.embeddings import DeterministicFakeEmbedding

engine = PGEngine.from_connection_string("postgresql+psycopg://user:pass@localhost/db")
embedding = DeterministicFakeEmbedding(size=768)
store = PGVectorStore.create_sync(engine=engine, table_name="docs", embedding_service=embedding)
store.add_documents([...])
results = store.similarity_search("query")

Requires a running PostgreSQL instance and either asyncpg or psycopg driver installed; Python 3.9 or later.

Verify before relying

  • Performance characteristics of hybrid search compared to vector-only search in production workloads.
  • Whether the migration path from deprecated PGVector to PGVectorStore is straightforward for large existing datasets.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 7 — asyncpg, langchain-core, numpy, pgvector, psycopg-pool, psycopg, sqlalchemy
Maintenance actively maintained — 178 days since the last release
First released
Downloads 1,578,491/month — #3,743 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: langchain_postgres-0.0.17-py3-none-any.whl

Tags

langchain postgres integrationvector store postgresqlchat history persistence postgrespgvectorstore embeddingslangchain database backend
langchain-integrationvector-databaserag

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

langchain-astradb

Integrates Astra DB (a serverless vector…

permissive · top 15,000 on PyPI

llama-index-vector-stores-postgres

Integrates PostgreSQL with pgvector extension…

permissive · top 15,000 on PyPI

langchain-pinecone

Connects LangChain applications to Pinecone…

permissive · top 5,000 on PyPI

langchain-qdrant

Connects LangChain applications to Qdrant…

permissive · top 5,000 on PyPI

langchain-elasticsearch

Integrates Elasticsearch with LangChain to…

permissive · top 15,000 on PyPI

langchain-milvus

Integrates LangChain with Milvus vector…

permissive · top 15,000 on PyPI

langchain-chroma

Connects LangChain applications to Chroma, a…

permissive · top 5,000 on PyPI

langchain-google-vertexai

Connects LangChain applications to Google…

permissive · top 1,000 on PyPI

langchain-neo4j

Integrates Neo4j graph databases with…

permissive · top 15,000 on PyPI

langgraph-checkpoint-aws

Provides AWS-based persistence backends for…

permissive · top 15,000 on PyPI