|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "--2024-05-01 17:04:54-- https://sergey-filimonov.nyc3.digitaloceanspaces.com/open-parse/sample-docs/lyft_2021-first-20-pages.pdf\n", |
| 13 | + "Resolving sergey-filimonov.nyc3.digitaloceanspaces.com (sergey-filimonov.nyc3.digitaloceanspaces.com)... 162.243.189.2\n", |
| 14 | + "Connecting to sergey-filimonov.nyc3.digitaloceanspaces.com (sergey-filimonov.nyc3.digitaloceanspaces.com)|162.243.189.2|:443... connected.\n", |
| 15 | + "HTTP request sent, awaiting response... 200 OK\n", |
| 16 | + "Length: 379188 (370K) [application/pdf]\n", |
| 17 | + "Saving to: ‘sample-docs/lyft-10k.pdf’\n", |
| 18 | + "\n", |
| 19 | + "sample-docs/lyft-10 100%[===================>] 370.30K 1.99MB/s in 0.2s \n", |
| 20 | + "\n", |
| 21 | + "2024-05-01 17:04:57 (1.99 MB/s) - ‘sample-docs/lyft-10k.pdf’ saved [379188/379188]\n", |
| 22 | + "\n" |
| 23 | + ] |
| 24 | + } |
| 25 | + ], |
| 26 | + "source": [ |
| 27 | + "import sys\n", |
| 28 | + "\n", |
| 29 | + "sys.path.append(\"..\")\n", |
| 30 | + "\n", |
| 31 | + "!wget https://sergey-filimonov.nyc3.digitaloceanspaces.com/open-parse/sample-docs/lyft_2021-first-20-pages.pdf -O sample-docs/lyft-10k.pdf" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": 9, |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "# make sure llama-index is installed, it's not a formal dependency of open-parse\n", |
| 41 | + "# %pip install llama-index" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": 3, |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [ |
| 49 | + { |
| 50 | + "name": "stdout", |
| 51 | + "output_type": "stream", |
| 52 | + "text": [ |
| 53 | + "Finished parsing\n" |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
| 57 | + "source": [ |
| 58 | + "import openparse\n", |
| 59 | + "\n", |
| 60 | + "doc_path = \"./sample-docs/lyft-10k.pdf\"\n", |
| 61 | + "parser = openparse.DocumentParser()\n", |
| 62 | + "parsed_doc = parser.parse(doc_path)\n", |
| 63 | + "\n", |
| 64 | + "print(\"Finished parsing\")" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": 4, |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [ |
| 72 | + { |
| 73 | + "name": "stdout", |
| 74 | + "output_type": "stream", |
| 75 | + "text": [ |
| 76 | + "Node ID: 33747e2d-0478-4628-b112-d733b1fc5039\n", |
| 77 | + "Text: Securities registered pursuant to Section 12(g) of the\n", |
| 78 | + "Act:**None** Indicate by check mark if the Registrant is a well-known\n", |
| 79 | + "seasoned issuer, as defined in Rule 405 of the Securities Act. Yes ☒\n", |
| 80 | + "No ☐ Indicate by check mark if the Registrant is not required to file\n", |
| 81 | + "reports pursuant to Section 13 or 15(d) of the Act. Yes ☐ No ☒\n", |
| 82 | + "Indicate by check ma...\n" |
| 83 | + ] |
| 84 | + } |
| 85 | + ], |
| 86 | + "source": [ |
| 87 | + "nodes = parsed_doc.to_llama_index_nodes()\n", |
| 88 | + "\n", |
| 89 | + "print(nodes[1])" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": 5, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [ |
| 97 | + { |
| 98 | + "data": { |
| 99 | + "text/plain": [ |
| 100 | + "{'id_': '33747e2d-0478-4628-b112-d733b1fc5039',\n", |
| 101 | + " 'embedding': None,\n", |
| 102 | + " 'metadata': {'bbox': [{'page': 0,\n", |
| 103 | + " 'page_height': 792.0,\n", |
| 104 | + " 'page_width': 612.0,\n", |
| 105 | + " 'x0': 17.31,\n", |
| 106 | + " 'y0': 332.53,\n", |
| 107 | + " 'x1': 586.25,\n", |
| 108 | + " 'y1': 424.21}]},\n", |
| 109 | + " 'excluded_embed_metadata_keys': ['bbox'],\n", |
| 110 | + " 'excluded_llm_metadata_keys': ['bbox'],\n", |
| 111 | + " 'relationships': {<NodeRelationship.PREVIOUS: '2'>: {'node_id': '59644551-d995-4d0a-88f5-49bbf22f0617',\n", |
| 112 | + " 'node_type': <ObjectType.TEXT: '1'>,\n", |
| 113 | + " 'metadata': {'bbox': [{'page': 0,\n", |
| 114 | + " 'page_height': 792.0,\n", |
| 115 | + " 'page_width': 612.0,\n", |
| 116 | + " 'x0': 17.31,\n", |
| 117 | + " 'y0': 457.56,\n", |
| 118 | + " 'x1': 590.92,\n", |
| 119 | + " 'y1': 743.41}]},\n", |
| 120 | + " 'hash': '77baa9ef95633b4c77c243ed3db29b4555c4f1f78c5b68f620eb8c4ff7f0a480',\n", |
| 121 | + " 'class_name': 'RelatedNodeInfo'},\n", |
| 122 | + " <NodeRelationship.NEXT: '3'>: {'node_id': '50744a8a-4ccb-4efa-a625-a1e7e3feec0c',\n", |
| 123 | + " 'node_type': <ObjectType.TEXT: '1'>,\n", |
| 124 | + " 'metadata': {'bbox': [{'page': 0,\n", |
| 125 | + " 'page_height': 792.0,\n", |
| 126 | + " 'page_width': 612.0,\n", |
| 127 | + " 'x0': 17.31,\n", |
| 128 | + " 'y0': 211.34,\n", |
| 129 | + " 'x1': 586.62,\n", |
| 130 | + " 'y1': 290.85}]},\n", |
| 131 | + " 'hash': '965f5304799146fde0d2bb8fb5726c0646ddf46df3ada30a902adee9005c2333',\n", |
| 132 | + " 'class_name': 'RelatedNodeInfo'},\n", |
| 133 | + " <NodeRelationship.PARENT: '4'>: {'node_id': 'dc94d72c-ec16-41b7-9e01-f359284464d2',\n", |
| 134 | + " 'node_type': <ObjectType.DOCUMENT: '4'>,\n", |
| 135 | + " 'metadata': {'file_name': 'lyft-10k.pdf',\n", |
| 136 | + " 'file_size': 379188,\n", |
| 137 | + " 'creation_date': '2024-05-01',\n", |
| 138 | + " 'last_modified_date': '2024-04-07'},\n", |
| 139 | + " 'hash': '60b974c64ec56d53a58cfe7703901cd049f6f11c39af6612861193672cc07bd9',\n", |
| 140 | + " 'class_name': 'RelatedNodeInfo'}},\n", |
| 141 | + " 'text': 'Securities registered pursuant to Section 12(g) of the Act:**None**\\nIndicate by check mark if the Registrant is a well-known seasoned issuer, as defined in Rule 405 of the Securities Act. Yes ☒ No ☐\\nIndicate by check mark if the Registrant is not required to file reports pursuant to Section 13 or 15(d) of the Act. Yes ☐ No ☒\\nIndicate by check mark whether the Registrant: (1) has filed all reports required to be filed by Section 13 or 15(d) of the Securities Exchange Act of 1934 during the preceding 12 months (or for such\\nshorter period that the Registrant was required to file such reports), and (2) has been subject to such filing requirements for the past 90 days. Yes ☒ No ☐\\nIndicate by check mark whether the Registrant has submitted electronically every Interactive Data File required to be submitted pursuant to Rule 405 of Regulation S-T (§232.405 of this chapter) during\\nthe preceding 12 months (or for such shorter period that the Registrant was required to submit such files). Yes ☒ No ☐\\nIndicate by check mark whether the registrant is a large accelerated filer, an accelerated filer, a non-accelerated filer, smaller reporting company, or an emerging growth company. See the definitions of\\n“large accelerated filer,” “accelerated filer,” “smaller reporting company,” and “emerging growth company” in Rule 12b-2 of the Exchange Act.',\n", |
| 142 | + " 'start_char_idx': None,\n", |
| 143 | + " 'end_char_idx': None,\n", |
| 144 | + " 'text_template': '{metadata_str}\\n\\n{content}',\n", |
| 145 | + " 'metadata_template': '{key}: {value}',\n", |
| 146 | + " 'metadata_seperator': '\\n',\n", |
| 147 | + " 'class_name': 'TextNode'}" |
| 148 | + ] |
| 149 | + }, |
| 150 | + "execution_count": 5, |
| 151 | + "metadata": {}, |
| 152 | + "output_type": "execute_result" |
| 153 | + } |
| 154 | + ], |
| 155 | + "source": [ |
| 156 | + "nodes[1].dict()" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "markdown", |
| 161 | + "metadata": {}, |
| 162 | + "source": [ |
| 163 | + "## Let's add the nodes to a vector store" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "code", |
| 168 | + "execution_count": 6, |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [], |
| 171 | + "source": [ |
| 172 | + "from llama_index.core import VectorStoreIndex\n", |
| 173 | + "\n", |
| 174 | + "index = VectorStoreIndex(nodes=nodes)" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "markdown", |
| 179 | + "metadata": {}, |
| 180 | + "source": [ |
| 181 | + "## Now let's query our index" |
| 182 | + ] |
| 183 | + }, |
| 184 | + { |
| 185 | + "cell_type": "code", |
| 186 | + "execution_count": 7, |
| 187 | + "metadata": {}, |
| 188 | + "outputs": [ |
| 189 | + { |
| 190 | + "name": "stdout", |
| 191 | + "output_type": "stream", |
| 192 | + "text": [ |
| 193 | + "They generate revenue primarily from service fees and commissions collected from drivers for their use of the ridesharing marketplace. Additionally, they earn revenue from riders renting Light Vehicles, drivers renting vehicles through Express Drive, Lyft Rentals renters, Lyft Driver Center and Lyft Auto Care users, and by providing their ridesharing marketplace to organizations through Lyft Business offerings. In the second quarter of 2021, they also started generating revenues from licensing and data access agreements with third-party autonomous vehicle companies.\n" |
| 194 | + ] |
| 195 | + } |
| 196 | + ], |
| 197 | + "source": [ |
| 198 | + "query_engine = index.as_query_engine()\n", |
| 199 | + "response = query_engine.query(\"What do they do to make money?\")\n", |
| 200 | + "print(response)" |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + "metadata": { |
| 205 | + "kernelspec": { |
| 206 | + "display_name": "open-parse-notebooks", |
| 207 | + "language": "python", |
| 208 | + "name": "python3" |
| 209 | + }, |
| 210 | + "language_info": { |
| 211 | + "codemirror_mode": { |
| 212 | + "name": "ipython", |
| 213 | + "version": 3 |
| 214 | + }, |
| 215 | + "file_extension": ".py", |
| 216 | + "mimetype": "text/x-python", |
| 217 | + "name": "python", |
| 218 | + "nbconvert_exporter": "python", |
| 219 | + "pygments_lexer": "ipython3", |
| 220 | + "version": "3.10.4" |
| 221 | + } |
| 222 | + }, |
| 223 | + "nbformat": 4, |
| 224 | + "nbformat_minor": 2 |
| 225 | +} |
0 commit comments