langchain-postgres  by langchain-ai

PostgreSQL backend for LangChain AI applications

Created 1 year ago
271 stars

Top 95.1% on SourcePulse

GitHubView on GitHub
Project Summary

Provides PostgreSQL-backed implementations for core LangChain abstractions, enabling developers to leverage a robust relational database for vector embeddings and chat message history. It offers a persistent and scalable backend for AI applications built with LangChain, simplifying data management and retrieval.

How It Works

This package integrates LangChain with PostgreSQL using asyncpg or psycopg3 drivers. It offers PGVectorStore for managing vector embeddings, supporting efficient similarity searches and hybrid search capabilities via configurations like reciprocal rank fusion. Additionally, PostgresChatMessageHistory allows for the persistence of chat session dialogues within PostgreSQL tables, keyed by session ID.

Quick Start & Requirements

  • Primary install: pip install -U langchain-postgres
  • Non-default prerequisites: PostgreSQL database, asyncpg or psycopg3 drivers.
  • Note: PGVector is deprecated in v0.0.14+; migration to PGVectorStore is recommended for improved performance and manageability.
  • Resources: Example code demonstrates setup for vector stores and chat history persistence. Links to LangSmith for AI agent development are provided.

Highlighted Details

  • PGVectorStore: Offers enhanced performance and manageability over the deprecated PGVector.
  • Hybrid Search: Supports combining keyword and vector search using configurable fusion functions like reciprocal rank fusion within PGVectorStore.
  • Chat Message History: Provides PostgresChatMessageHistory for durable storage of conversational data.
  • Google Cloud Integrations: Dedicated packages (langchain-google-alloydb-pg, langchain-google-cloud-sql-pg) offer secure, simplified connections to Google Cloud's AlloyDB and Cloud SQL for PostgreSQL, featuring IAM authorization and instance name-based connection.

Maintenance & Community

No specific details on contributors, sponsorships, or community channels were present in the provided README snippet.

Licensing & Compatibility

Released under the permissive MIT license, allowing for broad use, modification, and distribution, including within commercial applications.

Limitations & Caveats

The primary adoption blocker is the deprecation of the older PGVector implementation, necessitating migration to PGVectorStore for ongoing support and feature access. Users should consult the migration guide for a smooth transition.

Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
8
Issues (30d)
2
Star History
7 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.