--- id: langchain-postgres version: "0.0.17" license: MIT license_treatment: permissive maintenance: active --- # langchain-postgres — An integration package connecting Postgres and LangChain License: permissive · Maintenance: active · Downloads: 1.6M/mo ## 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 above — 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 pip install langchain-postgres uv add langchain-postgres 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_current - Install friction: low - Maintenance: active - Downloads: 1.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags langchain postgres integration, vector store postgresql, chat history persistence postgres, pgvectorstore embeddings, langchain database backend, langchain-integration, vector-database, rag [View on SkillFed](https://skillfed.io/packages/langchain-postgres) · [View on PyPI](https://pypi.org/project/langchain-postgres/)