mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-27 12:34:22 +00:00
update RAG examples and banner text
Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
This commit is contained in:
parent
734d77c8ae
commit
fb028b71f3
@ -49,18 +49,6 @@
|
|||||||
"load_dotenv()"
|
"load_dotenv()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 3,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"import warnings\n",
|
|
||||||
"\n",
|
|
||||||
"warnings.filterwarnings(action=\"ignore\", category=UserWarning, module=\"pydantic|torch\")\n",
|
|
||||||
"warnings.filterwarnings(action=\"ignore\", category=FutureWarning, module=\"easyocr\")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -86,54 +74,37 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from enum import Enum\n",
|
|
||||||
"from typing import Iterator\n",
|
"from typing import Iterator\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from langchain_core.document_loaders import BaseLoader\n",
|
"from langchain_core.document_loaders import BaseLoader\n",
|
||||||
"from langchain_core.documents import Document as LCDocument\n",
|
"from langchain_core.documents import Document as LCDocument\n",
|
||||||
"from pydantic import BaseModel\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"from docling.document_converter import DocumentConverter\n",
|
"from docling.document_converter import DocumentConverter\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
|
||||||
"class DocumentMetadata(BaseModel):\n",
|
|
||||||
" dl_doc_hash: str\n",
|
|
||||||
" # source: str\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"class DoclingPDFLoader(BaseLoader):\n",
|
"class DoclingPDFLoader(BaseLoader):\n",
|
||||||
" class ParseType(str, Enum):\n",
|
|
||||||
" MARKDOWN = \"markdown\"\n",
|
|
||||||
" # JSON = \"json\"\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" def __init__(self, file_path: str | list[str], parse_type: ParseType) -> None:\n",
|
" def __init__(self, file_path: str | list[str]) -> None:\n",
|
||||||
" self._file_paths = file_path if isinstance(file_path, list) else [file_path]\n",
|
" self._file_paths = file_path if isinstance(file_path, list) else [file_path]\n",
|
||||||
" self._parse_type = parse_type\n",
|
|
||||||
" self._converter = DocumentConverter()\n",
|
" self._converter = DocumentConverter()\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def lazy_load(self) -> Iterator[LCDocument]:\n",
|
" def lazy_load(self) -> Iterator[LCDocument]:\n",
|
||||||
" for source in self._file_paths:\n",
|
" for source in self._file_paths:\n",
|
||||||
" dl_doc = self._converter.convert_single(source).output\n",
|
" dl_doc = self._converter.convert(source).document\n",
|
||||||
" match self._parse_type:\n",
|
" text = dl_doc.export_to_markdown()\n",
|
||||||
" case self.ParseType.MARKDOWN:\n",
|
" yield LCDocument(page_content=text)"
|
||||||
" text = dl_doc.export_to_markdown()\n",
|
]
|
||||||
" # case self.ParseType.JSON:\n",
|
},
|
||||||
" # text = dl_doc.model_dump_json()\n",
|
{
|
||||||
" case _:\n",
|
"cell_type": "code",
|
||||||
" raise RuntimeError(\n",
|
"execution_count": 4,
|
||||||
" f\"Unexpected parse type encountered: {self._parse_type}\"\n",
|
"metadata": {},
|
||||||
" )\n",
|
"outputs": [],
|
||||||
" lc_doc = LCDocument(\n",
|
"source": [
|
||||||
" page_content=text,\n",
|
"FILE_PATH = \"https://raw.githubusercontent.com/DS4SD/docling/main/tests/data/2206.01062.pdf\" # DocLayNet paper"
|
||||||
" metadata=DocumentMetadata(\n",
|
|
||||||
" dl_doc_hash=dl_doc.file_info.document_hash,\n",
|
|
||||||
" ).model_dump(),\n",
|
|
||||||
" )\n",
|
|
||||||
" yield lc_doc"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -141,37 +112,10 @@
|
|||||||
"execution_count": 5,
|
"execution_count": 5,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
|
||||||
"FILE_PATH = \"https://arxiv.org/pdf/2206.01062\" # DocLayNet paper"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 6,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"application/vnd.jupyter.widget-view+json": {
|
|
||||||
"model_id": "1b38d07d5fed4618a44ecf261e1e5c44",
|
|
||||||
"version_major": 2,
|
|
||||||
"version_minor": 0
|
|
||||||
},
|
|
||||||
"text/plain": [
|
|
||||||
"Fetching 7 files: 0%| | 0/7 [00:00<?, ?it/s]"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "display_data"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
|
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
|
||||||
"\n",
|
"\n",
|
||||||
"loader = DoclingPDFLoader(\n",
|
"loader = DoclingPDFLoader(file_path=FILE_PATH)\n",
|
||||||
" file_path=FILE_PATH,\n",
|
|
||||||
" parse_type=DoclingPDFLoader.ParseType.MARKDOWN,\n",
|
|
||||||
")\n",
|
|
||||||
"text_splitter = RecursiveCharacterTextSplitter(\n",
|
"text_splitter = RecursiveCharacterTextSplitter(\n",
|
||||||
" chunk_size=1000,\n",
|
" chunk_size=1000,\n",
|
||||||
" chunk_overlap=200,\n",
|
" chunk_overlap=200,\n",
|
||||||
@ -187,7 +131,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -204,7 +148,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 7,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -223,7 +167,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 8,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -232,7 +176,7 @@
|
|||||||
"from langchain_milvus import Milvus\n",
|
"from langchain_milvus import Milvus\n",
|
||||||
"\n",
|
"\n",
|
||||||
"MILVUS_URI = os.environ.get(\n",
|
"MILVUS_URI = os.environ.get(\n",
|
||||||
" \"MILVUS_URL\", f\"{(tmp_dir := TemporaryDirectory()).name}/milvus_demo.db\"\n",
|
" \"MILVUS_URI\", f\"{(tmp_dir := TemporaryDirectory()).name}/milvus_demo.db\"\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"vectorstore = Milvus.from_documents(\n",
|
"vectorstore = Milvus.from_documents(\n",
|
||||||
@ -252,7 +196,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 9,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -287,7 +231,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 11,
|
"execution_count": 10,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -319,16 +263,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": 11,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"'The human annotation of DocLayNet was performed on 80863 pages.\\n\\nExplanation:\\nThe information is found in the paragraph \"DocLayNet contains 80863 PDF pages\" in the context.'"
|
"'- 80,863 pages were human annotated for DocLayNet.'"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 12,
|
"execution_count": 11,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -336,13 +280,6 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"rag_chain.invoke(\"How many pages were human annotated for DocLayNet?\")"
|
"rag_chain.invoke(\"How many pages were human annotated for DocLayNet?\")"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
"# RAG with LlamaIndex 🦙"
|
"# RAG with LlamaIndex 🦙"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"> ℹ️ 👉 **The LlamaIndex Docling extension update to Docling v2 is ongoing; in the meanwhile, this notebook is showing current extension output, based on Docling v1.**"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
|
@ -4,6 +4,10 @@ Docling is available as an official LlamaIndex extension!
|
|||||||
|
|
||||||
To get started, check out the [step-by-step guide in LlamaIndex \[↗\]](https://docs.llamaindex.ai/en/stable/examples/data_connectors/DoclingReaderDemo/)<!--{target="_blank"}-->.
|
To get started, check out the [step-by-step guide in LlamaIndex \[↗\]](https://docs.llamaindex.ai/en/stable/examples/data_connectors/DoclingReaderDemo/)<!--{target="_blank"}-->.
|
||||||
|
|
||||||
|
!!! info "Docling v2"
|
||||||
|
|
||||||
|
The LlamaIndex Docling extension update to Docling v2 is ongoing.
|
||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
### Docling Reader
|
### Docling Reader
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block announce %}
|
{% block announce %}
|
||||||
<p>🎉 Docling is going v2, <a href="{{ 'v2' | url }}">check out</a> what's new and how to get started!</p>
|
<p>🎉 Docling has gone v2! <a href="{{ 'v2' | url }}">Check out</a> what's new and how to get started!</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user