← Back to Leaderboard
Llangchain-ai

langchain-ai/langchain-postgres

PostgreSQL-backed vector retrieval and chat history for LangChain

View on GitHub ↗
Engineering Health (Methodology)
A+ · 91/100
Maintenance Activity
● Updated yesterday
Latest Release
langchain-postgres==0.0.19
Commercial License Check
MIT · Commercial Friendly

Automated SPDX check for reference only — not legal advice. Disclaimer

Maintenance35/35
Fork Adoption19/25
Release Cadence17/20
License Clarity20/20
DockerSelf-Hosted
Total Stars
★ 282
24h Growth
+0
7d Growth
+0
Forks
132

GitHub Star History

Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.

langchain-ai/langchain-postgres Star History (2024-04-07 - 2026-12-04) ALL-TIME STAR HISTORY (2024-04 – 2026-12) +281 in 971d · avg +0/day 298 149 0 2024-04-07: ★ 12024-06-08: ★ 512024-08-10: ★ 832024-10-12: ★ 1092024-12-14: ★ 1322025-02-15: ★ 1522025-04-19: ★ 1692025-06-21: ★ 1892025-08-23: ★ 2102025-10-25: ★ 2312025-12-27: ★ 2472026-02-28: ★ 2662026-05-02: ★ 2702026-07-04: ★ 2742026-09-05: ★ 2772026-12-04: ★ 282 ★ 282 2024-04 2025-08 2026-12

Evidence-Backed Technical Brief

AI Deep Review

Architecture & Core Mechanics

langchain-postgres is an in-process Python SDK, not a standalone retrieval service. The vector path separates table setup (PGEngine), storage and retrieval (PGVectorStore), and embedding generation (an application-supplied embedding service). The application initializes a named table with a fixed vector dimension, then uses the store to add LangChain Document objects and run similarity queries. Sync APIs have async counterparts.

The manifest requires Python 3.11+ and LangChain Core >=1.2.11,<2.0. Dependencies include SQLAlchemy 2+ with asyncio support, asyncpg, psycopg 3 with binary support, psycopg-pool, the pgvector Python package, and NumPy. Chat persistence is a separate path: PostgresChatMessageHistory takes a psycopg connection, a table name, and an application-assigned session UUID. Both paths can use the same database without coupling their APIs or table lifecycles.

Key Capabilities & Differentiators

PGVectorStore provides document insertion and vector similarity search. HybridSearchConfig adds a text retrieval signal to vector search, with reciprocal rank fusion available as the fusion function. The example's 768-dimensional DeterministicFakeEmbedding is a test fixture, not a required dimension or a production model. The table must match the actual embedding output; changes to models or dimensions should be planned around re-embedding and table compatibility.

PostgresChatMessageHistory persists LangChain message types such as system, human, and AI messages in a PostgreSQL table scoped by session UUID. For cloud-specific connectivity, the separate AlloyDB and Cloud SQL integration packages offer IAM and instance-based connections. Both support metadata filtering, async access, and schema flexibility, but neither is listed as supporting hybrid search.

Trade-offs & Limitations

This is a good fit when PostgreSQL is already an operational dependency: retrieval and chat history can use existing database infrastructure, while LangChain gets a reusable adapter. Compared with writing pgvector SQL directly, the SDK reduces integration code but gives up some direct control over query shape, ranking, and database tuning. Hybrid search also needs relevance testing on representative queries; rank fusion is not a guarantee of better results.

Compared with a dedicated vector database, colocating these workloads avoids running another data service, but retrieval and ingestion may compete with transactional work for CPU, memory, I/O, and connections. Test under mixed load before sharing a production instance, especially if retrieval must scale independently. The package is MIT-licensed. For existing PGVector users, account for migration and cutover work: the class has been deprecated since 0.0.14, and a migration notebook targets PGVectorStore.

Hardware & Deployment Guide

Install langchain-postgres into Python 3.11+ and point the application at PostgreSQL with pgvector enabled. The included Compose file starts only the database: pgvector/pgvector:pg16, port 5432:5432, and a named data volume. It creates langchain_test, but the health check connects to langchain; the separate Python example also targets langchain, on port 6024. Align the health check and application DSN with the database name and host port you actually provision. Replace the fixture credentials and review log_statement=all before ingesting real data.

For production, manage schema changes explicitly and size PostgreSQL for vector dimensions, row count, indexes, and query concurrency. Self-hosting the database does not make the pipeline offline if embeddings still use an external service. The 0.0.19 release removes the vulnerable embed_query_inline fallback as a breaking change; smoke-test embedding and retrieval when upgrading.

Storage boundary: PGEngine initializes a named PostgreSQL vector table with an explicit embedding dimension.
Retrieval: PGVectorStore combines vector and text search through HybridSearchConfig, with reciprocal rank fusion as a configurable option.
Runtime: Python 3.11+, LangChain Core >=1.2.11,<2.0, SQLAlchemy 2+ with asyncio, and asyncpg or psycopg 3 driver support.
Session persistence: PostgresChatMessageHistory groups LangChain messages by caller-supplied session UUID in a chosen table.
Migration: PGVector is deprecated from 0.0.14 onward; a migration notebook targets PGVectorStore.
Development fixture: Docker Compose runs pgvector/pgvector:pg16 with a named volume; the example DSN and health check need alignment with the fixture.
Best For

Python LangChain teams that already operate PostgreSQL and want vector or hybrid retrieval plus session history without adding a separate data service.

Skip If

You need a turnkey retrieval server, must scale retrieval independently of PostgreSQL, or cannot enable pgvector on your database.

Reviewed on 2026-12-03 · Grounded in GitHub README, root file tree & releasesMethodology

Quick Start & Installation

DockerSelf-Hosted
pip install -U langchain-postgres

Comparison vs. Top RAG, Data & Memory Alternatives

Full comparison →
RepositoryStars7d TrendStackLicenseCore Positioning
langchain-postgres ★282—PythonMITPostgreSQL-backed vector retrieval and chat history for LangChain
auto-ontology19.1k+3.7kPythonApache-2.0An ontology framework that grounds agent-generated SQL in reviewed business defi
llama_index53.1k+104PythonMITA modular Python SDK for document ingestion, indexing, and RAG
langextract39.5k+85PythonApache-2.0Python SDK for extracting structured data with traceable source spans

AI Context Briefing (for Claude / Cursor / Windsurf)

Standardized architecture summary & quickstart commands ready to paste into coding agents.

Raw .md ↗
curl -sL https://repoforai.com/repo/langchain-ai/langchain-postgres.md

Embed Star History Chart & Badges in README.md

Full-history Star History SVGs and velocity cards on GitHub Camo: drop-in replacement for OSSInsight and Star History widgets.

langchain-ai/langchain-postgres Star History on RepoForAI

Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).

Frequently Asked Questions about langchain-postgres

How do vector retrieval and chat persistence fit into an existing LangChain application?

Initialize a table with PGEngine.init_vectorstore_table, matching vector_size to your embedding implementation. Construct PGVectorStore with that engine, table, and embedding service, then add and search documents through the store. PostgresChatMessageHistory is separate: it uses a psycopg connection, a history table created once, and a caller-assigned session UUID.

Do I need a GPU or a dedicated database server?

The Python integration and PostgreSQL/pgvector do not require a GPU. DeterministicFakeEmbedding is suitable for a wiring test, not a retrieval-quality test. If you use a local embedding model, size CPU, RAM, and any VRAM for that model and its concurrency. Size PostgreSQL separately for document count, vector dimensions, index footprint, and concurrent queries.

Can I self-host this commercially, and what compliance work remains?

The package is MIT-licensed, so commercial self-hosting is permitted subject to its license terms, including retaining the required notices when redistributing it. The license does not cover a chosen embedding provider's terms or satisfy data-handling obligations. For regulated deployments, review where document and query text are embedded, and define access controls, logging, and retention for stored chat history.

When should I choose PGVectorStore over legacy PGVector, direct SQL, or a cloud-specific integration?

For new tables, use PGVectorStore; PGVector has been deprecated since 0.0.14, and existing deployments should test the migration rather than assume a drop-in replacement. Direct pgvector SQL is a better fit when you need full control over queries and ranking and are willing to maintain the LangChain adapter. The separate AlloyDB and Cloud SQL integrations are worth considering when IAM and instance-based connections matter more than hybrid search through this package.

Upstream README & Documentation

This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.

Maintaining langchain-ai/langchain-postgres? Pin to Homepage + competitor /alternatives pages with a custom Cloud/Demo CTA.Feature langchain-ai/langchain-postgres on Homepage & Alternatives ($19)
WEEKLY BREAKOUT DIGEST

Top 10 Breakout Open-Source AI Repos, Every Thursday

Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.

Zero spam · 1-click unsubscribe · Privacy Policy

Saved in your browser · Export Markdown RFC tables or jump into /vs compare