Skip to main content

langgraph-store-postgres

A PostgreSQL long-term-memory store (BaseStore) for LangGraph — namespaced key/value memory with prefix search, filters, list_namespaces, and native semantic search via pgvector.

pip install langgraph-store-postgres
from langgraph_store_postgres import PostgresStore

store = PostgresStore("postgresql://user:pass@localhost:5432/db")   # or engine=<Engine>

store.put(("users", "1", "memories"), "food", {"text": "loves sushi", "kind": "pref"})
item = store.get(("users", "1", "memories"), "food")
hits = store.search(("users", "1"), filter={"kind": "pref"}, limit=10)
spaces = store.list_namespaces(prefix=("users",))

Use it as a LangGraph store: graph.compile(store=PostgresStore(...)). Async methods (aget/aput/asearch/…) work too — the sync calls run in a thread.

Semantic search (pgvector)

Pass a LangGraph IndexConfig and the store embeds the configured fields on put and ranks search(query=...) by cosine similarity using pgvector (<=>, HNSW index):

from langgraph_store_core import bedrock_titan_embeddings
from langgraph_store_postgres import PostgresStore

store = PostgresStore(url, table_name="memory",
                      index={"dims": 1024, "embed": bedrock_titan_embeddings(dimensions=1024), "fields": ["text"]})
store.put(("memories", "kamal"), "k1", {"text": "the user loves sushi", "kind": "pref"})
hits = store.search(("memories", "kamal"), query="what food does the user like?", filter={"kind": "pref"})
print(hits[0].score, hits[0].value)

embed may be any LangChain Embeddings, a list[str] -> list[list[float]] callable, or a provider string. fields defaults to ["$"] (whole value as JSON). put(..., index=False) skips embedding for one item.

Requires the pgvector extension on the server (apt install postgresql-16-pgvector, or built in on RDS / Cloud SQL / Azure Database). The store runs CREATE EXTENSION IF NOT EXISTS vector, adds an embedding vector(dims) column and an HNSW cosine index. Namespace prefix and plain-equality filters run inside the SQL query (JSONB containment); operator filters ($gt, $in, …) are applied on the returned candidates.

Data model

A single table (prefix, key, value JSONB, created_at, updated_at[, embedding vector]) with primary key (prefix, key), created automatically. Namespace tuples are joined with a unit separator into prefix; search is a prefix scan, filters and namespace matching are evaluated in the core.

Docs: https://skamalj.github.io/agentstate-reducer/

License

MIT

Release files for langgraph-store-postgres 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langgraph-store-postgres 0.1.0
File Size Uploaded
langgraph_store_postgres-0.1.0.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langgraph-store-postgres 0.1.0
File Interpreter ABI Platform
langgraph_store_postgres-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size:11.3 kB

Release files / langgraph_store_postgres-0.1.0.tar.gz

Download URL langgraph_store_postgres-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ee5cb2dfd33632ae4f86693adc7f5180471eba9f2adacec7422a0d51b5fe8f1d
BLAKE2b-256 checksum
How to use checksums
73aae37c9c00c54d4b8b30ef7835f6894590d3fde324f4b22561ebab42a77744
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / langgraph_store_postgres-0.1.0-py3-none-any.whl

Download URL langgraph_store_postgres-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92b4d612a4f3a71105749ba1b0093700769945c0608564a15af2c6b9a7b04679
BLAKE2b-256 checksum
How to use checksums
64fb24bebf0a1215cff4e018b49c5e6103074b6a3391343fb3a1fc1e045c0703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page