Skip to content

feat(store-postgres): Add PostgresStore for LangGraph.js #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

abogacki
Copy link
Contributor

Implement PostgreSQL Store with Vector Search Capabilities

Overview

This PR implements a PostgreSQL-based store for LangGraph.js inspired by #887 and Python implementation. The implementation includes comprehensive vector similarity search, hybrid search (combining vector and text search), and TTL management for automatic data expiration.

Key Features

  • Modular architecture with specialized components for different responsibilities
  • Vector similarity search with support for multiple distance metrics (cosine, L2, inner product)
  • Hybrid search combining vector similarity and full-text search
  • Advanced filtering with rich query operators ($eq, $gt, $lt, $in, etc.)
  • Automatic TTL management with configurable expiration settings
  • Support for PostgreSQL's pgvector extension for efficient vector operations

Implementation Details

  • Split the monolithic implementation into specialized modules:
    • database-core.js: Core connection and transaction management
    • database-setup.js: Schema initialization and migration
    • crud-operations.js: Basic CRUD operations
    • search-operations.js: Advanced search capabilities
    • vector-operations.js: Vector embedding and similarity calculations
    • ttl-manager.js: Expiration and cleanup management
    • query-builder.js: SQL query construction
  • Added comprehensive TypeScript types for better developer experience
  • Implemented efficient text extraction from JSON documents using configurable field paths
  • Added extensive test coverage for all features

@@ -2,7 +2,7 @@ version: "3.8"

services:
postgres:
image: postgres:latest
image: pgvector/pgvector:pg16
Copy link
Contributor Author

@abogacki abogacki May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that this won't have any effect on other integration tests relying on this docker-compose file, and it will enable store-postgres to be tested against vector search. I've also added docker-compose.test.yml file in /libs/store-postgres

@@ -0,0 +1,87 @@
/* eslint-disable no-process-env */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to group and split integration tests by tested module/functionality, as originally the file had over 1,5 k lines of code and would be harder to maintain

@abogacki abogacki changed the title Langgraph postgres store feat(store-postgres): Add PostgresStore for LangGraph.js May 30, 2025
@abogacki abogacki marked this pull request as ready for review May 30, 2025 13:38
@@ -0,0 +1,392 @@
import pg from "pg";
import {
Copy link
Contributor Author

@abogacki abogacki May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types/objects are currently included in @langchain/langgraph-checkpoint library, so I've added it as a dependency. I was kind of torn apart between copying them, or creating separate module for @langchain/langgraph-store (similarily to @langchain/langgraph-checkpoint). Lmk which approach would you like me to go with (or include the changes yourself 🙂)

@abogacki abogacki marked this pull request as draft May 30, 2025 18:48
@abogacki abogacki marked this pull request as ready for review June 2, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant