Installation#
Requirements#
Python 3.11–3.14. On Python 3.10, pip installs 0.2.0 instead, without an error, and these pages do not describe it.
A running AgensGraph 2.17 or later. An older server is refused at connect.
The pgvector extension, for the vector store and
AgensStoresemantic search
Every database call goes through the
agensgraph-python 2.0 driver
(psycopg 3), which is installed with the package. The integration targets langchain-core 1.x
and langgraph 1.x, and has no dependency on the archived langchain-community.
Install#
pip install -U langchain-agensgraph
or through the agensgraph-ai umbrella package, which installs the same thing:
pip install "agensgraph-ai[langchain]"
There is no agensgraph_ai module; either way you import langchain_agensgraph. This
documentation covers 0.3.1. 0.3.1 is a documentation release; its code is 0.3.0’s.
The examples that embed text or call an LLM use langchain-openai, which is not a
dependency. Install it separately if you want to run them as written:
pip install langchain-openai
Set up pgvector#
AgensGraph does not bundle the pgvector extension. Build and install it against your
AgensGraph install’s pg_config:
git clone https://github.com/pgvector/pgvector.git
export PG_CONFIG=/path/to/agens/bin/pg_config
cd pgvector && make && make install
-- in your AgensGraph database, as a superuser:
CREATE EXTENSION IF NOT EXISTS vector;
On a large graph, enabling auto_gather_graphmeta on the database
(ALTER DATABASE mydb SET auto_gather_graphmeta = on) makes DETACH DELETE much faster.
Connecting#
AgensGraph, AgensChatMessageHistory, AgensSaver, and AgensStore accept a conf
dictionary of psycopg.connect keyword arguments. The last three can instead take an existing
AgensGraph as graph=:
conf = {
"dbname": "mydb",
"user": "postgres",
"password": "postgres",
"host": "localhost",
"port": 55432,
}
The vector store takes a libpq url instead, such as
postgresql://user:password@localhost:55432/mydb, or reads it from the AGENSGRAPH_URL
environment variable. It can also be built on an existing AgensGraph (graph=). To share
one connection pool between the graph store and several vector stores, create an
AgensEngine and pass it as engine=. Pass create=True to have the graph store create the
graph if it does not exist. See Usage for full examples.