Skip to content

Commit 3e40f4b

Browse files
committed
Merge branch 'main' into more-embedding-models
2 parents c897c7c + a925f95 commit 3e40f4b

17 files changed

Lines changed: 446 additions & 44 deletions

File tree

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ body:
88
value: Thank you for contributing to open-parse! ✊
99

1010
- type: checkboxes
11-
id: checks
11+
id: version-checks
1212
attributes:
1313
label: Initial Checks
1414
description: Just making sure you're using the latest version
1515
options:
1616
- label: I confirm that I'm on the latest version
1717
required: true
18-
1918
- type: textarea
2019
id: description
2120
attributes:
@@ -41,3 +40,20 @@ body:
4140
4241
...
4342
render: Python
43+
44+
- type: textarea
45+
id: version
46+
attributes:
47+
label: Python, open-parse & OS Version
48+
description: |
49+
Which version of Python & open-parse are you using, and which Operating System?
50+
51+
Please run the following command and copy the output below:
52+
53+
```bash
54+
python -c "import openparse.version; print(openparse.version.version_info())"
55+
```
56+
57+
render: Text
58+
validations:
59+
required: true

ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We parse text into markdown by looking at the font size and style charachter by
2020

2121
Spans get combined into lines and lines get combined into elements. Elements are the basic building blocks of the document. They can be headings, paragraphs, lists of bullets, etc.
2222

23-
Optionally we can use PyMuPDF to OCR the document. This is not recommended as a default due to the additional computational cost and inherent inaccuracies of OCR. We're looking at integrating [doctr](https://github.com/mindee/doctr).
23+
Optionally we can use PyMuPDF to OCR the document. This is not recommended as a default due to the additional computational cost and inherent inaccuracies of OCR. We're looking at integrating [doctr](https://github.com/mindee/doctr). Early tests make this library seem very heavy and slow.
2424

2525
Here's an article that goes into more details on available [OCR libraries](https://source.opennews.org/articles/our-search-best-ocr-tool-2023/).
2626

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ parsed_content = parser.parse(basic_doc_path)
6363

6464
## Cookbooks
6565

66-
https://github.com/Filimoa/open-parse/tree/main/src/cookbooks
66+
[Other Cookbooks](https://github.com/Filimoa/open-parse/tree/main/src/cookbooks)
6767

6868

6969
## Sponsors

docs/integrations.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Llama Index
2+
3+
We have a simple integration with Llama Index. You can convert the parsed document to Llama Index nodes and then create an index from those nodes.
4+
5+
```py
6+
import openparse
7+
from llama_index.core import VectorStoreIndex
8+
9+
doc_path = "./sample-docs/lyft-10k.pdf"
10+
parser = openparse.DocumentParser()
11+
parsed_doc = parser.parse(doc_path)
12+
13+
nodes = parsed_doc.to_llama_index_nodes()
14+
index = VectorStoreIndex(nodes=nodes)
15+
```
16+
17+
Now you can query the index
18+
19+
```py
20+
query_engine = index.as_query_engine()
21+
response = query_engine.query("What do they do to make money?")
22+
print(response)
23+
```
24+
25+
You can also add nodes to an existing index
26+
27+
```py
28+
existing_index.insert_nodes(nodes)
29+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ nav:
7878
- Advanced:
7979
- Customization: processing/customization.md
8080
- Serializing Results: serialization.md
81+
- Integrations: integrations.md
8182
- Visualization: visualization.md
8283
- Config: config.md
8384

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel"]
2+
requires = ["setuptools", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "openparse"
77
description = "Streamlines the process of preparing documents for LLM's."
88
readme = "README.md"
99
requires-python = ">=3.8"
10-
version = "0.5.2"
10+
license = { text = "MIT" }
11+
version = "0.5.6"
1112
authors = [{name = "Sergey Filimonov", email = "hello@sergey.fyi"}]
1213
dependencies = [
1314
"PyMuPDF >= 1.23.2",

src/cookbooks/llama_index.ipynb

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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+
}

src/openparse/doc_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from openparse import tables, text, consts
55
from openparse.pdf import Pdf
6-
from openparse.types import NOT_GIVEN, NotGiven
6+
from openparse._types import NOT_GIVEN, NotGiven
77
from openparse.processing import (
88
IngestionPipeline,
99
BasicIngestionPipeline,
@@ -34,7 +34,7 @@ class PyMuPDFArgsDict(TypedDict, total=False):
3434

3535

3636
def _table_args_dict_to_model(
37-
args_dict: Union[TableTransformersArgsDict, PyMuPDFArgsDict]
37+
args_dict: Union[TableTransformersArgsDict, PyMuPDFArgsDict],
3838
) -> Union[tables.TableTransformersArgs, tables.PyMuPDFArgs]:
3939
if args_dict["parsing_algorithm"] == "table-transformers":
4040
return tables.TableTransformersArgs(**args_dict)

0 commit comments

Comments
 (0)