|
14 | 14 | "You can run the following command to spin up a pg-vector container:\n", |
15 | 15 | "\n", |
16 | 16 | "```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", |
18 | 18 | "```\n", |
19 | 19 | "\n", |
20 | | - "**BETA** This vectorstore is in **beta** and **not** recommended for production usage at enterprise level.\n", |
| 20 | + "## Status\n", |
21 | 21 | "\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", |
23 | 23 | "\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", |
35 | 25 | "* 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", |
36 | 27 | "\n", |
37 | 28 | "\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." |
39 | 31 | ] |
40 | 32 | }, |
41 | 33 | { |
|
48 | 40 | }, |
49 | 41 | { |
50 | 42 | "cell_type": "code", |
51 | | - "execution_count": 12, |
| 43 | + "execution_count": 1, |
52 | 44 | "id": "42d42297-11b8-44e3-bf21-7c3d1bce8277", |
53 | 45 | "metadata": { |
54 | 46 | "tags": [] |
|
68 | 60 | }, |
69 | 61 | { |
70 | 62 | "cell_type": "code", |
71 | | - "execution_count": 13, |
| 63 | + "execution_count": 2, |
72 | 64 | "id": "979a65bd-742f-4b0d-be1e-c0baae245ec6", |
73 | 65 | "metadata": { |
74 | 66 | "tags": [] |
|
80 | 72 | "from langchain_postgres.vectorstores import PGVector\n", |
81 | 73 | "from langchain_core.documents import Document\n", |
82 | 74 | "\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", |
84 | 77 | "collection_name = \"my_docs\"\n", |
85 | 78 | "embeddings = CohereEmbeddings()\n", |
86 | 79 | "\n", |
87 | 80 | "vectorstore = PGVector(\n", |
88 | | - " embedding_function=embeddings,\n", |
| 81 | + " embeddings=embeddings,\n", |
89 | 82 | " collection_name=collection_name,\n", |
90 | | - " connection_string=connection_string,\n", |
| 83 | + " connection=connection,\n", |
91 | 84 | " use_jsonb=True,\n", |
92 | 85 | ")" |
93 | 86 | ] |
94 | 87 | }, |
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 | | - }, |
107 | 88 | { |
108 | 89 | "cell_type": "markdown", |
109 | 90 | "id": "0fc32168-5a82-4629-a78d-158fe2615086", |
|
138 | 119 | }, |
139 | 120 | { |
140 | 121 | "cell_type": "code", |
141 | | - "execution_count": 15, |
| 122 | + "execution_count": 5, |
142 | 123 | "id": "88a288cc-ffd4-4800-b011-750c72b9fd10", |
143 | 124 | "metadata": { |
144 | 125 | "tags": [] |
|
161 | 142 | }, |
162 | 143 | { |
163 | 144 | "cell_type": "code", |
164 | | - "execution_count": 16, |
| 145 | + "execution_count": 6, |
165 | 146 | "id": "73aa9124-9d49-4e10-8ed3-82255e7a4106", |
166 | 147 | "metadata": { |
167 | 148 | "tags": [] |
|
173 | 154 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" |
174 | 155 | ] |
175 | 156 | }, |
176 | | - "execution_count": 16, |
| 157 | + "execution_count": 6, |
177 | 158 | "metadata": {}, |
178 | 159 | "output_type": "execute_result" |
179 | 160 | } |
|
184 | 165 | }, |
185 | 166 | { |
186 | 167 | "cell_type": "code", |
187 | | - "execution_count": 17, |
| 168 | + "execution_count": 7, |
188 | 169 | "id": "a5b2b71f-49eb-407d-b03a-dea4c0a517d6", |
189 | 170 | "metadata": { |
190 | 171 | "tags": [] |
|
205 | 186 | " Document(page_content='a new coffee shop opened on Main Street', metadata={'id': 7, 'topic': 'food', 'location': 'Main Street'})]" |
206 | 187 | ] |
207 | 188 | }, |
208 | | - "execution_count": 17, |
| 189 | + "execution_count": 7, |
209 | 190 | "metadata": {}, |
210 | 191 | "output_type": "execute_result" |
211 | 192 | } |
|
224 | 205 | }, |
225 | 206 | { |
226 | 207 | "cell_type": "code", |
227 | | - "execution_count": 18, |
| 208 | + "execution_count": 8, |
228 | 209 | "id": "13c69357-aaee-4de0-bcc2-7ab4419c920e", |
229 | 210 | "metadata": { |
230 | 211 | "tags": [] |
|
273 | 254 | }, |
274 | 255 | { |
275 | 256 | "cell_type": "code", |
276 | | - "execution_count": 19, |
| 257 | + "execution_count": 9, |
277 | 258 | "id": "f15a2359-6dc3-4099-8214-785f167a9ca4", |
278 | 259 | "metadata": { |
279 | 260 | "tags": [] |
|
288 | 269 | " Document(page_content='ducks are also found in the pond', metadata={'id': 2, 'topic': 'animals', 'location': 'pond'})]" |
289 | 270 | ] |
290 | 271 | }, |
291 | | - "execution_count": 19, |
| 272 | + "execution_count": 9, |
292 | 273 | "metadata": {}, |
293 | 274 | "output_type": "execute_result" |
294 | 275 | } |
|
309 | 290 | }, |
310 | 291 | { |
311 | 292 | "cell_type": "code", |
312 | | - "execution_count": 20, |
| 293 | + "execution_count": 10, |
313 | 294 | "id": "88f919e4-e4b0-4b5f-99b3-24c675c26d33", |
314 | 295 | "metadata": { |
315 | 296 | "tags": [] |
|
322 | 303 | " Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]" |
323 | 304 | ] |
324 | 305 | }, |
325 | | - "execution_count": 20, |
| 306 | + "execution_count": 10, |
326 | 307 | "metadata": {}, |
327 | 308 | "output_type": "execute_result" |
328 | 309 | } |
|
336 | 317 | }, |
337 | 318 | { |
338 | 319 | "cell_type": "code", |
339 | | - "execution_count": 21, |
| 320 | + "execution_count": 11, |
340 | 321 | "id": "88f423a4-6575-4fb8-9be2-a3da01106591", |
341 | 322 | "metadata": { |
342 | 323 | "tags": [] |
|
349 | 330 | " Document(page_content='there are cats in the pond', metadata={'id': 1, 'topic': 'animals', 'location': 'pond'})]" |
350 | 331 | ] |
351 | 332 | }, |
352 | | - "execution_count": 21, |
| 333 | + "execution_count": 11, |
353 | 334 | "metadata": {}, |
354 | 335 | "output_type": "execute_result" |
355 | 336 | } |
|
366 | 347 | }, |
367 | 348 | { |
368 | 349 | "cell_type": "code", |
369 | | - "execution_count": 22, |
| 350 | + "execution_count": 12, |
370 | 351 | "id": "65133340-2acd-4957-849e-029b6b5d60f0", |
371 | 352 | "metadata": { |
372 | 353 | "tags": [] |
|
385 | 366 | " Document(page_content='fresh apples are available at the market', metadata={'id': 3, 'topic': 'food', 'location': 'market'})]" |
386 | 367 | ] |
387 | 368 | }, |
388 | | - "execution_count": 22, |
| 369 | + "execution_count": 12, |
389 | 370 | "metadata": {}, |
390 | 371 | "output_type": "execute_result" |
391 | 372 | } |
|
0 commit comments