Skip to content

Commit deb227d

Browse files
authored
Merge branch 'main' into migration
2 parents 5510701 + 01ee285 commit deb227d

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ pip install -U langchain-postgres
3535
For a detailed example on `PGVectorStore` see [here](https://github.com/langchain-ai/langchain-postgres/blob/main/examples/pg_vectorstore.ipynb).
3636

3737
```python
38-
from langchain_postgres import PGEngine, PGVectorStore
38+
from langchain_core.documents import Document
3939
from langchain_core.embeddings import DeterministicFakeEmbedding
40-
import uuid
40+
from langchain_postgres import PGEngine, PGVectorStore
4141

42-
# Replace these variable values
42+
# Replace the connection string with your own Postgres connection string
43+
CONNECTION_STRING = "postgresql+psycopg3://langchain:langchain@localhost:6024/langchain"
4344
engine = PGEngine.from_connection_string(url=CONNECTION_STRING)
4445

46+
# Replace the vector size with your own vector size
4547
VECTOR_SIZE = 768
4648
embedding = DeterministicFakeEmbedding(size=VECTOR_SIZE)
4749

50+
TABLE_NAME = "my_doc_collection"
51+
4852
engine.init_vectorstore_table(
49-
table_name="destination_table",
53+
table_name=TABLE_NAME,
5054
vector_size=VECTOR_SIZE,
5155
)
5256

examples/pg_vectorstore.ipynb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
{
7878
"cell_type": "code",
79-
"execution_count": null,
79+
"execution_count": 2,
8080
"id": "irl7eMFnSPZr",
8181
"metadata": {
8282
"id": "irl7eMFnSPZr"
@@ -90,7 +90,7 @@
9090
"POSTGRES_PORT = \"6024\" # @param {type: \"string\"}\n",
9191
"POSTGRES_DB = \"langchain\" # @param {type: \"string\"}\n",
9292
"TABLE_NAME = \"vectorstore\" # @param {type: \"string\"}\n",
93-
"VECTOR_SIZE = 768 # @param {type: \"int\"}"
93+
"VECTOR_SIZE = 1024 # @param {type: \"int\"}"
9494
]
9595
},
9696
{
@@ -118,7 +118,7 @@
118118
},
119119
{
120120
"cell_type": "code",
121-
"execution_count": null,
121+
"execution_count": 3,
122122
"metadata": {},
123123
"outputs": [],
124124
"source": [
@@ -132,13 +132,13 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": null,
135+
"execution_count": 4,
136136
"metadata": {},
137137
"outputs": [],
138138
"source": [
139139
"from langchain_postgres import PGEngine\n",
140140
"\n",
141-
"engine = PGEngine.from_connection_string(url=CONNECTION_STRING)"
141+
"pg_engine = PGEngine.from_connection_string(url=CONNECTION_STRING)"
142142
]
143143
},
144144
{
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": null,
155+
"execution_count": 5,
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
@@ -178,13 +178,13 @@
178178
},
179179
{
180180
"cell_type": "code",
181-
"execution_count": null,
181+
"execution_count": 7,
182182
"metadata": {
183183
"id": "avlyHEMn6gzU"
184184
},
185185
"outputs": [],
186186
"source": [
187-
"await engine.ainit_vectorstore_table(\n",
187+
"await pg_engine.ainit_vectorstore_table(\n",
188188
" table_name=TABLE_NAME,\n",
189189
" vector_size=VECTOR_SIZE,\n",
190190
")"
@@ -200,7 +200,7 @@
200200
"```python\n",
201201
"SCHEMA_NAME=\"my_schema\"\n",
202202
"\n",
203-
"await engine.ainit_vectorstore_table(\n",
203+
"await pg_engine.ainit_vectorstore_table(\n",
204204
" table_name=TABLE_NAME,\n",
205205
" vector_size=768,\n",
206206
" schema_name=SCHEMA_NAME, # Default: \"public\"\n",
@@ -219,7 +219,7 @@
219219
},
220220
{
221221
"cell_type": "code",
222-
"execution_count": null,
222+
"execution_count": 8,
223223
"metadata": {
224224
"colab": {
225225
"base_uri": "https://localhost:8080/"
@@ -231,7 +231,7 @@
231231
"source": [
232232
"from langchain_cohere import CohereEmbeddings\n",
233233
"\n",
234-
"embedding = CohereEmbeddings()"
234+
"embedding = CohereEmbeddings(model=\"embed-english-v3.0\")"
235235
]
236236
},
237237
{
@@ -245,7 +245,7 @@
245245
},
246246
{
247247
"cell_type": "code",
248-
"execution_count": null,
248+
"execution_count": 9,
249249
"metadata": {
250250
"id": "z-AZyzAQ7bsf"
251251
},
@@ -254,7 +254,7 @@
254254
"from langchain_postgres import PGVectorStore\n",
255255
"\n",
256256
"store = await PGVectorStore.create(\n",
257-
" engine=engine,\n",
257+
" engine=pg_engine,\n",
258258
" table_name=TABLE_NAME,\n",
259259
" # schema_name=SCHEMA_NAME,\n",
260260
" embedding_service=embedding,\n",
@@ -272,7 +272,7 @@
272272
},
273273
{
274274
"cell_type": "code",
275-
"execution_count": null,
275+
"execution_count": 11,
276276
"metadata": {},
277277
"outputs": [],
278278
"source": [
@@ -298,10 +298,9 @@
298298
"store_with_documents = await PGVectorStore.afrom_documents(\n",
299299
" documents=docs,\n",
300300
" ids=ids,\n",
301-
" engine=engine,\n",
301+
" engine=pg_engine,\n",
302302
" table_name=TABLE_NAME,\n",
303-
" # schema_name=SCHEMA_NAME,\n",
304-
" embedding_service=embedding,\n",
303+
" embedding=embedding,\n",
305304
")"
306305
]
307306
},
@@ -389,7 +388,7 @@
389388
},
390389
{
391390
"cell_type": "code",
392-
"execution_count": null,
391+
"execution_count": 16,
393392
"metadata": {},
394393
"outputs": [],
395394
"source": [
@@ -408,7 +407,7 @@
408407
},
409408
{
410409
"cell_type": "code",
411-
"execution_count": null,
410+
"execution_count": 17,
412411
"metadata": {},
413412
"outputs": [],
414413
"source": [
@@ -424,7 +423,7 @@
424423
},
425424
{
426425
"cell_type": "code",
427-
"execution_count": null,
426+
"execution_count": 18,
428427
"metadata": {},
429428
"outputs": [],
430429
"source": [
@@ -444,7 +443,7 @@
444443
},
445444
{
446445
"cell_type": "code",
447-
"execution_count": null,
446+
"execution_count": 19,
448447
"metadata": {},
449448
"outputs": [],
450449
"source": [
@@ -454,7 +453,7 @@
454453
"TABLE_NAME = \"vectorstore_custom\"\n",
455454
"# SCHEMA_NAME = \"my_schema\"\n",
456455
"\n",
457-
"await engine.ainit_vectorstore_table(\n",
456+
"await pg_engine.ainit_vectorstore_table(\n",
458457
" table_name=TABLE_NAME,\n",
459458
" # schema_name=SCHEMA_NAME,\n",
460459
" vector_size=VECTOR_SIZE,\n",
@@ -464,7 +463,7 @@
464463
"\n",
465464
"# Initialize PGVectorStore\n",
466465
"custom_store = await PGVectorStore.create(\n",
467-
" engine=engine,\n",
466+
" engine=pg_engine,\n",
468467
" table_name=TABLE_NAME,\n",
469468
" # schema_name=SCHEMA_NAME,\n",
470469
" embedding_service=embedding,\n",
@@ -578,7 +577,7 @@
578577
"\n",
579578
"# Initialize PGVectorStore\n",
580579
"custom_store = await PGVectorStore.create(\n",
581-
" engine=engine,\n",
580+
" engine=pg_engine,\n",
582581
" table_name=TABLE_NAME,\n",
583582
" # schema_name=SCHEMA_NAME,\n",
584583
" embedding_service=embedding,\n",
@@ -685,7 +684,7 @@
685684
"name": "python",
686685
"nbconvert_exporter": "python",
687686
"pygments_lexer": "ipython3",
688-
"version": "3.12.3"
687+
"version": "3.12.8"
689688
}
690689
},
691690
"nbformat": 4,

0 commit comments

Comments
 (0)