Skip to content

Commit b898343

Browse files
authored
Update documentation (#22)
Update documentation
1 parent a188868 commit b898343

File tree

2 files changed

+29
-58
lines changed

2 files changed

+29
-58
lines changed

examples/vectorstore.ipynb

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,20 @@
1414
"You can run the following command to spin up a pg-vector container:\n",
1515
"\n",
1616
"```shell\n",
17-
"docker run --name pgvector-container -e POSTGRES_PASSWORD=langchain -d pgvector/pgvector:pg16\n",
17+
"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",
1818
"```\n",
1919
"\n",
20-
"**BETA** This vectorstore is in **beta** and **not** recommended for production usage at enterprise level.\n",
20+
"## Status\n",
2121
"\n",
22-
"The main issue with the existing implementation is:\n",
22+
"This code has been ported over from langchain_community. The following changes have been made:\n",
2323
"\n",
24-
"1) Handling of connection objects\n",
25-
"2) Lack of support for schema migrations\n",
26-
"\n",
27-
"If you're OK with these limitations (and know how to create migrations for the table) or are fine re-creating the collection and embeddings if the schema changes, then feel free to use this implementation.\n",
28-
"\n",
29-
"While this code has been ported over from langchain_community with minimal changes to allow users to easily transition from langchain_community to langchain_postgres,\n",
30-
"some changes still had to be made to make it easier for users that are relying on this implementation to transition to `langchain_postgres`.\n",
31-
"\n",
32-
"Some changes had to be made to address issues with the community implementation:\n",
33-
"\n",
34-
"* langchain_postgres now works 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 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",
3525
"* The schema of the embedding store and collection have been changed to make add_documents work correctly with user specified ids.\n",
26+
"* One has to pass an explicit connection object now.\n",
3627
"\n",
3728
"\n",
38-
"This vectorstore is in **beta** and **not** recommended for production usage at enetprise level. It should be fine to use it for smaller datasets and/or for prototyping RAG."
29+
"Currently, there is **no mechanism** that supports easy data migration on schema changes. So any schema changes in the vectorstore will require the user to recreate the tables and re-add the documents.\n",
30+
"If this is a concern, please use a different vectorstore. If not, this implementation should be fine for your use case."
3931
]
4032
},
4133
{
@@ -48,7 +40,7 @@
4840
},
4941
{
5042
"cell_type": "code",
51-
"execution_count": 12,
43+
"execution_count": 1,
5244
"id": "42d42297-11b8-44e3-bf21-7c3d1bce8277",
5345
"metadata": {
5446
"tags": []
@@ -68,7 +60,7 @@
6860
},
6961
{
7062
"cell_type": "code",
71-
"execution_count": 13,
63+
"execution_count": 2,
7264
"id": "979a65bd-742f-4b0d-be1e-c0baae245ec6",
7365
"metadata": {
7466
"tags": []
@@ -80,30 +72,19 @@
8072
"from langchain_postgres.vectorstores import PGVector\n",
8173
"from langchain_core.documents import Document\n",
8274
"\n",
83-
"connection_string = \"postgresql+psycopg://langchain:langchain@localhost:6024/langchain\"\n",
75+
"# See docker command above to launch a postgres instance with pgvector enabled.\n",
76+
"connection = \"postgresql+psycopg://langchain:langchain@localhost:6024/langchain\" \n",
8477
"collection_name = \"my_docs\"\n",
8578
"embeddings = CohereEmbeddings()\n",
8679
"\n",
8780
"vectorstore = PGVector(\n",
88-
" embedding_function=embeddings,\n",
81+
" embeddings=embeddings,\n",
8982
" collection_name=collection_name,\n",
90-
" connection_string=connection_string,\n",
83+
" connection=connection,\n",
9184
" use_jsonb=True,\n",
9285
")"
9386
]
9487
},
95-
{
96-
"cell_type": "code",
97-
"execution_count": 14,
98-
"id": "42211476-f875-42e1-8a7c-75805d48c717",
99-
"metadata": {
100-
"tags": []
101-
},
102-
"outputs": [],
103-
"source": [
104-
"vectorstore.create_tables_if_not_exists()"
105-
]
106-
},
10788
{
10889
"cell_type": "markdown",
10990
"id": "0fc32168-5a82-4629-a78d-158fe2615086",
@@ -138,7 +119,7 @@
138119
},
139120
{
140121
"cell_type": "code",
141-
"execution_count": 15,
122+
"execution_count": 5,
142123
"id": "88a288cc-ffd4-4800-b011-750c72b9fd10",
143124
"metadata": {
144125
"tags": []
@@ -161,7 +142,7 @@
161142
},
162143
{
163144
"cell_type": "code",
164-
"execution_count": 16,
145+
"execution_count": 6,
165146
"id": "73aa9124-9d49-4e10-8ed3-82255e7a4106",
166147
"metadata": {
167148
"tags": []
@@ -173,7 +154,7 @@
173154
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
174155
]
175156
},
176-
"execution_count": 16,
157+
"execution_count": 6,
177158
"metadata": {},
178159
"output_type": "execute_result"
179160
}
@@ -184,7 +165,7 @@
184165
},
185166
{
186167
"cell_type": "code",
187-
"execution_count": 17,
168+
"execution_count": 7,
188169
"id": "a5b2b71f-49eb-407d-b03a-dea4c0a517d6",
189170
"metadata": {
190171
"tags": []
@@ -205,7 +186,7 @@
205186
" Document(page_content='a new coffee shop opened on Main Street', metadata={'id': 7, 'topic': 'food', 'location': 'Main Street'})]"
206187
]
207188
},
208-
"execution_count": 17,
189+
"execution_count": 7,
209190
"metadata": {},
210191
"output_type": "execute_result"
211192
}
@@ -224,7 +205,7 @@
224205
},
225206
{
226207
"cell_type": "code",
227-
"execution_count": 18,
208+
"execution_count": 8,
228209
"id": "13c69357-aaee-4de0-bcc2-7ab4419c920e",
229210
"metadata": {
230211
"tags": []
@@ -273,7 +254,7 @@
273254
},
274255
{
275256
"cell_type": "code",
276-
"execution_count": 19,
257+
"execution_count": 9,
277258
"id": "f15a2359-6dc3-4099-8214-785f167a9ca4",
278259
"metadata": {
279260
"tags": []
@@ -288,7 +269,7 @@
288269
" Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'})]"
289270
]
290271
},
291-
"execution_count": 19,
272+
"execution_count": 9,
292273
"metadata": {},
293274
"output_type": "execute_result"
294275
}
@@ -309,7 +290,7 @@
309290
},
310291
{
311292
"cell_type": "code",
312-
"execution_count": 20,
293+
"execution_count": 10,
313294
"id": "88f919e4-e4b0-4b5f-99b3-24c675c26d33",
314295
"metadata": {
315296
"tags": []
@@ -322,7 +303,7 @@
322303
" Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]"
323304
]
324305
},
325-
"execution_count": 20,
306+
"execution_count": 10,
326307
"metadata": {},
327308
"output_type": "execute_result"
328309
}
@@ -336,7 +317,7 @@
336317
},
337318
{
338319
"cell_type": "code",
339-
"execution_count": 21,
320+
"execution_count": 11,
340321
"id": "88f423a4-6575-4fb8-9be2-a3da01106591",
341322
"metadata": {
342323
"tags": []
@@ -349,7 +330,7 @@
349330
" Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]"
350331
]
351332
},
352-
"execution_count": 21,
333+
"execution_count": 11,
353334
"metadata": {},
354335
"output_type": "execute_result"
355336
}
@@ -366,7 +347,7 @@
366347
},
367348
{
368349
"cell_type": "code",
369-
"execution_count": 22,
350+
"execution_count": 12,
370351
"id": "65133340-2acd-4957-849e-029b6b5d60f0",
371352
"metadata": {
372353
"tags": []
@@ -385,7 +366,7 @@
385366
" Document(page_content='fresh apples are available at the market', metadata={'id': 3, 'topic': 'food', 'location': 'market'})]"
386367
]
387368
},
388-
"execution_count": 22,
369+
"execution_count": 12,
389370
"metadata": {},
390371
"output_type": "execute_result"
391372
}

langchain_postgres/vectorstores.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,7 @@ def from_texts(
972972
use_jsonb: bool = True,
973973
**kwargs: Any,
974974
) -> PGVector:
975-
"""
976-
Return VectorStore initialized from texts and embeddings.
977-
Postgres connection string is required
978-
"Either pass it as a parameter
979-
or set the PGVECTOR_CONNECTION_STRING environment variable.
980-
"""
975+
"""Return VectorStore initialized from documents and embeddings."""
981976
embeddings = embedding.embed_documents(list(texts))
982977

983978
return cls.__from(
@@ -1106,12 +1101,7 @@ def from_documents(
11061101
use_jsonb: bool = True,
11071102
**kwargs: Any,
11081103
) -> PGVector:
1109-
"""
1110-
Return VectorStore initialized from documents and embeddings.
1111-
Postgres connection string is required
1112-
"Either pass it as a parameter
1113-
or set the PGVECTOR_CONNECTION_STRING environment variable.
1114-
"""
1104+
"""Return VectorStore initialized from documents and embeddings."""
11151105

11161106
texts = [d.page_content for d in documents]
11171107
metadatas = [d.metadata for d in documents]

0 commit comments

Comments
 (0)