Skip to content

Commit 22f4f47

Browse files
docs: update PGVectorStore quickstart (#177)
Co-authored-by: Eugene Yurtsev <[email protected]>
1 parent fbcbef7 commit 22f4f47

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

examples/pg_vectorstore.ipynb

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
},
3535
"outputs": [],
3636
"source": [
37-
"%pip install --upgrade --quiet langchain-postgres"
37+
"%pip install --upgrade --quiet langchain-postgres\n",
38+
"# This tutorial also requires the following dependencies\n",
39+
"%pip install --upgrade --quiet langchain-core langchain-cohere SQLAlchemy"
3840
]
3941
},
4042
{
@@ -47,14 +49,29 @@
4749
"## Basic Usage"
4850
]
4951
},
52+
{
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"This package requires a PostgreSQL database with the `pgvector` extension.\n",
57+
"\n",
58+
"You can run the following command to spin up a container for a `pgvector` enabled Postgres instance:\n",
59+
"\n",
60+
"```shell\n",
61+
"docker run --name pgvector-container -e POSTGRES_USER=langchain -e POSTGRES_PASSWORD=langchain -e POSTGRES_DB=langchain -p 6024:5432 -d pgvector/pgvector:pg16\n",
62+
"```"
63+
]
64+
},
5065
{
5166
"cell_type": "markdown",
5267
"id": "OMvzMWRrR6n7",
5368
"metadata": {
5469
"id": "OMvzMWRrR6n7"
5570
},
5671
"source": [
57-
"### Set the postgres connection url"
72+
"### Set the postgres connection url\n",
73+
"\n",
74+
"`PGVectorStore` can be used with the `asyncpg` and `psycopg3` drivers."
5875
]
5976
},
6077
{
@@ -66,26 +83,14 @@
6683
},
6784
"outputs": [],
6885
"source": [
69-
"# @title Set Your Values Here { display-mode: \"form\" }\n",
70-
"POSTGRES_USER = \"postgres-user\" # @param {type: \"string\"}\n",
71-
"POSTGRES_PASSWORD = \"postgres-password\" # @param {type: \"string\"}\n",
72-
"POSTGRES_HOST = \"postgres-host\" # @param {type: \"string\"}\n",
73-
"POSTGRES_PORT = \"postgres-port\" # @param {type: \"string\"}\n",
74-
"POSTGRES_DB = \"postgres-db-name\" # @param {type: \"string\"}\n",
86+
"# @title Set your values or use the defaults to connect to Docker { display-mode: \"form\" }\n",
87+
"POSTGRES_USER = \"langchain\" # @param {type: \"string\"}\n",
88+
"POSTGRES_PASSWORD = \"langchain\" # @param {type: \"string\"}\n",
89+
"POSTGRES_HOST = \"localhost\" # @param {type: \"string\"}\n",
90+
"POSTGRES_PORT = \"6024\" # @param {type: \"string\"}\n",
91+
"POSTGRES_DB = \"langchain\" # @param {type: \"string\"}\n",
7592
"TABLE_NAME = \"vectorstore\" # @param {type: \"string\"}\n",
76-
"VECTOR_SIZE = 768 # @param {type: \"int\"}\n",
77-
"\n",
78-
"CONNECTION_STRING = (\n",
79-
" f\"postgresql+asyncpg://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}\"\n",
80-
" f\":{POSTGRES_PORT}/{POSTGRES_DB}\"\n",
81-
")"
82-
]
83-
},
84-
{
85-
"cell_type": "markdown",
86-
"metadata": {},
87-
"source": [
88-
"*Note:* `PGVectorStore` can only be used with the `postgresql+asyncpg` driver."
93+
"VECTOR_SIZE = 768 # @param {type: \"int\"}"
8994
]
9095
},
9196
{
@@ -111,6 +116,20 @@
111116
"**Note:** This tutorial demonstrates the async interface. All async methods have corresponding sync methods."
112117
]
113118
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"# See docker command above to launch a Postgres instance with pgvector enabled.\n",
126+
"CONNECTION_STRING = (\n",
127+
" f\"postgresql+asyncpg://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}\"\n",
128+
" f\":{POSTGRES_PORT}/{POSTGRES_DB}\"\n",
129+
")\n",
130+
"# To use psycopg3 driver, set your connection string to `postgresql+psycopg://`"
131+
]
132+
},
114133
{
115134
"cell_type": "code",
116135
"execution_count": null,
@@ -374,7 +393,7 @@
374393
"metadata": {},
375394
"outputs": [],
376395
"source": [
377-
"from langchain_postgres.indexes import IVFFlatIndex\n",
396+
"from langchain_postgres.v2.indexes import IVFFlatIndex\n",
378397
"\n",
379398
"index = IVFFlatIndex()\n",
380399
"await store.aapply_vector_index(index)"

examples/vectorstore.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"\n",
2222
"This code has been ported over from langchain_community. The following changes have been made:\n",
2323
"\n",
24-
"* langchain_postgres works only with psycopg3. Please update your connnecion strings from `postgresql+psycopg2://...` to `postgresql+psycopg://langchain:langchain@...` (yes, it's the driver name is `psycopg` not `psycopg3`, but it'll use `psycopg3`.\n",
24+
"* langchain_postgres works only with psycopg3. Please update your connection strings from `postgresql+psycopg2://...` to `postgresql+psycopg://langchain:langchain@...` (yes, it's the driver name is `psycopg` not `psycopg3`, but it'll use `psycopg3`.\n",
2525
"* The schema of the embedding store and collection have been changed to make add_documents work correctly with user specified ids.\n",
2626
"* One has to pass an explicit connection object now.\n",
2727
"\n",

0 commit comments

Comments
 (0)