Skip to content

Commit 069e2f8

Browse files
author
Stefano Lottini
committed
last touches and colab-ready
1 parent 5f30305 commit 069e2f8

File tree

1 file changed

+76
-28
lines changed

1 file changed

+76
-28
lines changed

AstraDB_langchain_quickstart_1.ipynb

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"Example values:\n",
5252
"- API Endpoint: `https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com`\n",
5353
"- Token: `AstraCS:6gBhNmsk135....` (it must have a role of at least \"Database Administrator\")\n",
54-
"- Keyspace. Optional, if provided: `my_keyspace`\n",
54+
"- _Keyspace. Optional, if provided:_ `my_keyspace`\n",
5555
"- OpenAI API key: `sk-4fQ3F...`"
5656
]
5757
},
@@ -116,7 +116,7 @@
116116
" collection_name=\"astra_vector_demo\",\n",
117117
" token=os.environ[\"ASTRA_DB_APPLICATION_TOKEN\"],\n",
118118
" api_endpoint=os.environ[\"ASTRA_DB_API_ENDPOINT\"],\n",
119-
" namespace=os.environ.get(\"ASTRA_DB_KEYSPACE\"), # <-- this will disappear in a typical quickstart\n",
119+
" namespace=os.environ.get(\"ASTRA_DB_KEYSPACE\"), # Usually no need for this\n",
120120
")"
121121
]
122122
},
@@ -276,9 +276,9 @@
276276
"name": "stdout",
277277
"output_type": "stream",
278278
"text": [
279-
"* [SIM=0.934124] We are what we are because we have been what we have been. [{'author': 'freud', 'history': 'y'}]\n",
280-
"* [SIM=0.932173] We become what we contemplate. [{'author': 'plato', 'knowledge': 'y', 'ethics': 'y'}]\n",
281-
"* [SIM=0.928669] In the blessings as well as in the ills of life, less depends upon what befalls us than upon the way in which it is met. [{'author': 'schopenhauer', 'knowledge': 'y', 'ethics': 'y'}]\n"
279+
"* [SIM=0.934130] We are what we are because we have been what we have been. [{'author': 'freud', 'history': 'y'}]\n",
280+
"* [SIM=0.932188] We become what we contemplate. [{'author': 'plato', 'knowledge': 'y', 'ethics': 'y'}]\n",
281+
"* [SIM=0.928739] In the blessings as well as in the ills of life, less depends upon what befalls us than upon the way in which it is met. [{'author': 'schopenhauer', 'knowledge': 'y', 'ethics': 'y'}]\n"
282282
]
283283
}
284284
],
@@ -369,29 +369,45 @@
369369
"id": "b8d031f8-4d5e-4ab7-a6a6-020f14a480af",
370370
"metadata": {},
371371
"source": [
372-
"### By document ID\n",
373-
"\n",
374-
"These methods return True if and only if the deletion succeeds completely (in the multiple-ID case, if all IDs result in a successful deletion):"
372+
"### By document ID"
375373
]
376374
},
377375
{
378376
"cell_type": "code",
379377
"execution_count": 13,
378+
"id": "71ab0207-9535-4cc0-8557-ef030c08e73c",
379+
"metadata": {},
380+
"outputs": [
381+
{
382+
"name": "stdout",
383+
"output_type": "stream",
384+
"text": [
385+
"all_succeed=True\n"
386+
]
387+
}
388+
],
389+
"source": [
390+
"delete_1 = vstore.delete(inserted_ids[:3])\n",
391+
"print(f\"all_succeed={delete_1}\") # True, all documents deleted"
392+
]
393+
},
394+
{
395+
"cell_type": "code",
396+
"execution_count": 14,
380397
"id": "1ee19e34-6826-49ec-93cd-692e1af3894e",
381398
"metadata": {},
382399
"outputs": [
383400
{
384401
"name": "stdout",
385402
"output_type": "stream",
386403
"text": [
387-
"all_succeed=True, single_succeeds=False.\n"
404+
"some_succeeds=True\n"
388405
]
389406
}
390407
],
391408
"source": [
392-
"all_succeed = vstore.delete(inserted_ids_2)\n",
393-
"single_succeeds = vstore.delete_by_document_id(inserted_ids_2[0]) # this will fail since we just deleted it...\n",
394-
"print(f\"all_succeed={all_succeed}, single_succeeds={single_succeeds}.\")"
409+
"delete_2 = vstore.delete(inserted_ids[2:5])\n",
410+
"print(f\"some_succeeds={delete_2}\") # True, though some IDs were gone already"
395411
]
396412
},
397413
{
@@ -406,17 +422,17 @@
406422
},
407423
{
408424
"cell_type": "code",
409-
"execution_count": 14,
425+
"execution_count": 15,
410426
"id": "b5bc1cb3-76f7-4d2d-9e00-9919b813da5a",
411427
"metadata": {},
412428
"outputs": [
413429
{
414430
"name": "stdout",
415431
"output_type": "stream",
416432
"text": [
417-
"* [SIM=0.920196] Philosophy can make people sick. [{'author': 'aristotle', 'politics': 'y'}]\n",
418-
"* [SIM=0.920123] For what purpose humanity is there should not even concern us: why you are here, that you should ask yourself: and if you have no ready answer, then set for yourself goals, high and noble goals, and perish in pursuit of them! [{'author': 'nietzsche', 'ethics': 'y', 'knowledge': 'y'}]\n",
419-
"Deleting IDs = ['fadb802157dd47a98587c303a74a0c7a', '42b03381d75c4ffabc4be57e3ca569d5'] ...\n",
433+
"* [SIM=0.920174] Philosophy can make people sick. [{'author': 'aristotle', 'politics': 'y'}]\n",
434+
"* [SIM=0.918580] Philosophy is by its nature something esoteric, neither made for the mob nor capable of being prepared for the mob. [{'author': 'hegel'}]\n",
435+
"Deleting IDs = ['0cb212e7853a4c5eb5354ff02c01429c', '49c47305b4844f6896a4a525dfbe4733'] ...\n",
420436
"Deletion succeeded = True\n"
421437
]
422438
}
@@ -445,16 +461,16 @@
445461
},
446462
{
447463
"cell_type": "code",
448-
"execution_count": 15,
464+
"execution_count": 16,
449465
"id": "24e24396-49e6-4fd5-90c4-badd13274b3c",
450466
"metadata": {},
451467
"outputs": [
452468
{
453469
"name": "stdout",
454470
"output_type": "stream",
455471
"text": [
456-
"* [SIM=0.918580] Philosophy is by its nature something esoteric, neither made for the mob nor capable of being prepared for the mob. [{'author': 'hegel'}]\n",
457-
"* [SIM=0.916111] The business of philosophy is not to give rules, but to analyze the private judgments of common reason. [{'author': 'kant'}]\n"
472+
"* [SIM=0.916127] The business of philosophy is not to give rules, but to analyze the private judgments of common reason. [{'author': 'kant'}]\n",
473+
"* [SIM=0.914889] Philosophy begins with wonder. [{'author': 'aristotle'}]\n"
458474
]
459475
}
460476
],
@@ -478,7 +494,7 @@
478494
},
479495
{
480496
"cell_type": "code",
481-
"execution_count": 16,
497+
"execution_count": 17,
482498
"id": "a7414400-3e1b-45e4-bac7-9b49fcd4cba4",
483499
"metadata": {},
484500
"outputs": [],
@@ -508,7 +524,7 @@
508524
},
509525
{
510526
"cell_type": "code",
511-
"execution_count": 17,
527+
"execution_count": 18,
512528
"id": "a3ee11cd-6513-4289-a4e8-993ab12e0d32",
513529
"metadata": {},
514530
"outputs": [],
@@ -517,9 +533,41 @@
517533
"from langchain.text_splitter import RecursiveCharacterTextSplitter"
518534
]
519535
},
536+
{
537+
"cell_type": "markdown",
538+
"id": "ad348f9e-f6e6-4bab-b4e8-c1d2e0a3bb61",
539+
"metadata": {},
540+
"source": [
541+
"**(Colab-only) Get the source PDF file**\n",
542+
"\n",
543+
"> You don't need to run the following cell unless you are on a Google Colab notebook:"
544+
]
545+
},
520546
{
521547
"cell_type": "code",
522-
"execution_count": 18,
548+
"execution_count": null,
549+
"id": "50827d43-0e84-4f8a-a106-e098d332c6a4",
550+
"metadata": {},
551+
"outputs": [],
552+
"source": [
553+
"# Run this cell if on a Google Colab:\n",
554+
"!mkdir -p sources\n",
555+
"!curl -L \\\n",
556+
" \"https://github.com/awesome-astra/datasets/blob/main/demo-resources/what-is-philosophy/what-is-philosophy.pdf?raw=true\" \\\n",
557+
" -o \"sources/what-is-philosophy.pdf\""
558+
]
559+
},
560+
{
561+
"cell_type": "markdown",
562+
"id": "c1034fcb-4068-476e-8fcd-1bf0b0b68704",
563+
"metadata": {},
564+
"source": [
565+
"#### Load the PDF file in the vector store:"
566+
]
567+
},
568+
{
569+
"cell_type": "code",
570+
"execution_count": 19,
523571
"id": "f711245a-a847-4acb-b4e3-93051adf1ebc",
524572
"metadata": {},
525573
"outputs": [
@@ -552,7 +600,7 @@
552600
},
553601
{
554602
"cell_type": "code",
555-
"execution_count": 19,
603+
"execution_count": 20,
556604
"id": "aaecf5ed-9358-43fd-83f5-a54578cbf81d",
557605
"metadata": {},
558606
"outputs": [],
@@ -565,7 +613,7 @@
565613
},
566614
{
567615
"cell_type": "code",
568-
"execution_count": 20,
616+
"execution_count": 21,
569617
"id": "61bc1ebe-532e-4d8f-9ad1-31d003fe1e04",
570618
"metadata": {},
571619
"outputs": [],
@@ -599,17 +647,17 @@
599647
},
600648
{
601649
"cell_type": "code",
602-
"execution_count": 21,
650+
"execution_count": 22,
603651
"id": "692f2fd6-4bc3-4c10-9c3a-8947d762c1dd",
604652
"metadata": {},
605653
"outputs": [
606654
{
607655
"data": {
608656
"text/plain": [
609-
"\"Russell describes the intellectual consequences of the security blanket paradox, which aligns with Peirce's notion of doubt and uncertainty as anxiety-producing states. Both thinkers suggest that clinging to comforting beliefs can lead to a counterproductive predicament, as having a security blanket only adds to our worries.\""
657+
"\"Russell elaborates on Peirce's idea of the security blanket by describing the intellectual consequences of this paradox. He argues that individuals who lack a philosophical perspective are imprisoned in the prejudices derived from common sense and the beliefs of their time and culture. This suggests that clinging to comforting beliefs can limit one's intellectual growth and hinder the search for truth.\""
610658
]
611659
},
612-
"execution_count": 21,
660+
"execution_count": 22,
613661
"metadata": {},
614662
"output_type": "execute_result"
615663
}
@@ -638,7 +686,7 @@
638686
},
639687
{
640688
"cell_type": "code",
641-
"execution_count": 22,
689+
"execution_count": 23,
642690
"id": "9fe88518-0494-4f08-b0eb-35305ce24ac4",
643691
"metadata": {},
644692
"outputs": [],

0 commit comments

Comments
 (0)