AI & XML / RAG study series / Part 1: structured versus unstructured RAG training data
Introduction
Study summary
This study asks whether structured or unstructured data better suit training a Retrieval-Augmented Generation (RAG) system. RAG combines pretrained language models and external knowledge for more accurate, contextual answers. Which data format works best is a central question.
Three RAG systems were trained on the same knowledge in different formats. Eleven identical questions then tested whether answers differed by format and which worked best.
Study results
Tests clearly showed structured data outperforming unstructured PDF in every case. Data prepared specifically for RAG did particularly well. Markdown performed best, with clear structure producing more precise and consistent answers.
Test results are in the Excel file in this folder: Supporting materials
Categories | HTML correct | PDF correct | MD correct |
|---|---|---|---|
1 | 0 | 1 | |
Bibliography | 0 | 0 | 1 |
Endnote | 1 | 0 | 1 |
Tables | 1 | 1 | 2 |
Emphasis | 0 | 0 | 0 |
Layout | 3 | 1 | 3 |
Mathematical semantics | 1 | 1 | 1 |
Index | 1 | 0 | 1 |
Total | 8 | 3 | 10 |
Conclusion
Targeted structuring substantially improves RAG performance. For optimal results, data should be specifically adapted to the system, ideally in Markdown or a comparable structured format.
1 Investigation methodology
1.1 Motivation
As RAG systems develop, we ask: Which structured information is lost in plain-text conversion, and how does this affect use and the quality of generated answers?
AI developers operating RAG generally know Python and data-driven processes, while content often comes from experts in XML, Word or PDF. These perspectives create preparation and usage challenges.
Language models train on large text collections converted to plain text by libraries, often losing metadata and structure. This can affect accuracy and relevance because RAG typically treats textual proximity as evidence of related meaning.
1.2 Information loss in structured documents
We analyze information lost during plain-text conversion and its effects on RAG answer generation , focusing on references, tables, typography, layout and semantic structures.
We used CustomGPT as the LLM: a customizable GPT model combined with personal content and sources for domain-specific answers, providing easy RAG integration in specific applications.
A simple but typical approach makes practical information transfer problems understandable.
Later studies analyze RAG architecture in more detail and systematically investigate causes of answer quality differences.
1.2.1 Reference systems: footnotes, endnotes, bibliographies and indexes
Scientific and technical reference systems link information structurally.
Footnotes provide additional information or sources. PDF superscripts or symbols link to notes at the page bottom. XML notes often sit directly at the relevant text location, maintaining close context.
PDF-to-text conversion loses explicit links, making the relationship between note and marked text ambiguous.
Endnotes work similarly but collect at a document or chapter end. Structured links are usually lost in plain text or become an unstructured list.
Indexes provide keywords and metadata for targeted searches and cross-references, linked to pages or sections in XML and PDF.
Plain text usually retains a bare term list without links, greatly limiting semantic value.
Bibliographies contain references to cited works, often stored structurally and linked to citations in XML or structured text.
Plain text can lose citation-source links, making scientific reasoning harder to verify.
1.2.2 Tables and their structure
Tables express logical relationships through structure as well as data.
XML, HTML and Markdown tables use explicit tags to delimit rows and columns.
PDF tables may be raster graphics or embedded structures.
Plain text often loses row-column relationships or replaces them with unstructured lists.
RAG cannot extract clear table relationships from unstructured text, losing important semantics.
1.2.3 Typographic and inline emphasis
Bold, italics, underlining and color contribute meaning, emphasize key terms, indicate hierarchy or mark important passages.
Plain text largely ignores these, losing context and emphasis, particularly for formatted terms or definitions.
1.2.4 Layout: text display and visual structure
Layout is crucial to readability and information structure. XML, HTML and PDF permit varied design devices; tests combined several of them.
1.2.5 Semantics: mathematical formulas
Structures with specific meanings, such as mathematical formulas, are particularly critical.
1.3 Analysis procedure
We created a special sample document in PDF, HTML and Markdown containing identical knowledge. Size was irrelevant, about ten pages; clear structure and unambiguous text mattered for easy checking, direct format comparison and RAG impact analysis.
Practical effects were assessed by training three RAG systems on identical technical infrastructure, each using one of the three formats.
The trained bots were then asked targeted questions in the examined areas, including references, tables, layout and semantics.
Generated answers were systematically checked for correctness to establish retained structure and measurable format effects on quality.
Every question and each bot’s answer were saved permanently, enabling detailed analysis, independent review and new tests. The saved answers provide a transparent basis for assessing format effects.
2 Data basis
All three formats accompany the study for independent analysis.
Fig. 2.1: PDF document
Fig. 2.2: HTML document
Fig. 2.3: Markdown document
3 Tasks
The following sections present document structures, underlying problems and RAG questions individually.
3.1 Footnotes
Fig. 3.1: footnotes
The question is:
Where was a dog kept to guard a house called a domestic dog?
The connection between text and footnote must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | A dog kept to guard a house was historically called a domestic dog 1. | - | ||
MD | correct | A dog kept to guard a house was historically called a domestic dog. This is documented in Johann Christoph Adelung’s “Grammatisch-kritisches Wörterbuch der Hochdeutschen Mundart, Band 2”, Leipzig 1796, p. 1030. Available online: http://www.zeno.org/nid/2000022233X 1. | - | |
HTML | correct | A dog kept to guard a house was historically called a domestic dog. This is documented in Johann Christoph Adelung’s “Grammatisch-kritisches Wörterbuch der Hochdeutschen Mundart, Band 2”, Leipzig 1796, p. 1030. Available online: http://www.zeno.org/nid/2000022233X 1. | - |
3.2 Bibliography
Fig. 3.2: bibliographic citation
Fig. 3.3: bibliography
The question is:
Where can I find further literature on dog and wolf offspring?
The connection between text and bibliography must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | Further reading on dog and wolf offspring appears in W. Christopher Wozencraft’s Order Carnivora, in Don E. Wilson and DeeAnn M. Reeder (eds.), Mammal Species of the World: A Taxonomic and Geographic Reference, 3rd edition, The Johns Hopkins University Press, Baltimore 2005, ISBN 0-8018-8221-4, pp. 532–628. Direct link: https://www.departments.bucknell.edu/biology/resources/msw3/browse.asp?id=14000738 1. | - | ||
MD | correct | My knowledge base mentions Dackel, B. (1909). Die Antwort auf alles. Heidelberg: data2type Verlag. This source may contain further information on dog and wolf offspring. | - | |
HTML | incorrect | Further reading is in W. Christopher Wozencraft’s “Order Carnivora”, in “Mammal Species of the World: A Taxonomic and Geographic Reference”, 3rd edition, The Johns Hopkins University Press, Baltimore, 2005, pp. 532–628. Direct link: https://www.departments.bucknell.edu/biology/resources/msw3/browse.asp?id=14000738 1. | - |
3.3 Endnotes
Fig. 3.4: endnotes in running text
Fig. 3.5: endnotes
The question is:
Where can I find more on the dingo as a subspecies of…?
The link between text and endnotes must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | The dingo is considered a domestic dog but provisionally listed as a separate wolf subspecies | - | ||
MD | correct | See W. Christopher Wozencraft’s “Order Carnivora” in “Mammal Species of the World: A Taxonomic and Geographic Reference”. The dingo is provisionally listed there as a separate wolf subspecies | - | |
HTML | correct | See W. Christopher Wozencraft’s “Order Carnivora” in “Mammal Species of the World: A Taxonomic and Geographic Reference”. The dingo is provisionally listed there as a separate wolf subspecies | - |
3.4 Tables
Simple tables were tested before complex ones. A clear 6×6 table had no spans, contained only numbers, and uniquely labeled rows and columns. Combining headers unambiguously identified values.
Complex tables added spans across rows or columns. Tests examined whether systems accounted for these and remained as accurate as with simple tables.
Fig. 3.6: simple table
The question is:
Give the hair-color value for the combination Black and Green
Rows, columns and headers must be related correctly.
Result:
RAG | Assessment | Text | Link | Notes |
correct | The hair-color value for Black and Green is 5 | - | ||
MD | correct | The hair-color value for Black and Green is 5 | - | |
HTML | correct | The hair-color value for Black and Green is 5 | - |
Fig. 3.7: complex table
The question is:
Give the poodle-color value for Red and young
Rows, columns, spans and headers must be related correctly.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | The poodle-color value for Red and young is 17 | - | ||
MD | correct | The poodle-color value for Red and young is 986 | - | |
HTML | incorrect | The poodle-color value for Red and young is 14 | - |
Differences between HTML and Markdown queries
HTML querying failed while Markdown worked. Possibly all attributes, or even all tags, were ignored, preventing correct recognition of spanning tables and causing incorrect or incomplete queries.
Markdown worked because its generation resolved spans, making structure clearer and simpler to query.
The following figure shows the Markdown code used:
Fig. 3.8: optimized Markdown table
3.5 Emphasis
Formatting effects on identifying key properties
Words from a defined list were bold and underlined. The question was designed so humans would likely identify highlighted terms as the central properties.
Neither bold nor underlining nor their combination affected answers. Even later H1 tests showed no effect.
Textual proximity mattered instead: relative position, rather than visual or structural emphasis, determined relevance and inclusion in answers.
Fig. 3.9: emphasis
The question is:
Name the German Shepherd’s most important property. Give only one.
The link between semantic emphasis and importance must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | Versatility | - | ||
MD | incorrect | Versatility | - | |
HTML | incorrect | Versatility | - |
3.6 Layout
Layout effects on text recognition
Three layouts tested RAG processing and interpretation.
Rotated text in a text box
Text was placed in a box and rotated several degrees.Highly distorted text
Text was modified to look highly distorted.Arrows showing a sequence
Arrows in a diagram should convey logical order.
Distorted text worked in all formats. Rotated text and arrows failed in PDF but succeeded in HTML and Markdown.
PDF-to-text likely prioritized horizontal positions and ignored arrows, losing intended order and causing incorrect interpretation.
Rotation may have disrupted text-flow recognition, extracting characters in the wrong order as gibberish rather than meaningful text.
Fig. 3.10: layout 1
The question is:
How many taste buds do dogs have, and how many do humans have in comparison?
PDF-to-text must recognize text flow; other formats already have readable text
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | No idea. I have no information on that. | - | ||
MD | correct | Dogs have 1700 taste buds; humans have 9000 | - | |
HTML | correct | Dogs have 1700 taste buds; humans have 9000 | - |
Fig. 3.11: layout 2
The question is:
How many autosomes does a dog’s cell nucleus have?
PDF-to-text must recognize text flow; other formats already have readable text
Result:
RAG | Assessment | Text | Link | Notes |
correct | A dog’s cell nucleus contains 76 autosomes (38 pairs). | - | ||
MD | correct | A dog’s cell nucleus contains 76 autosomes (38 pairs). | - | |
HTML | correct | A dog’s cell nucleus contains 76 autosomes (38 pairs). | - |
Fig. 3.12: layout 3
The question is:
Order these terms: Ohmacht, Speiseröhre ,Fuss, Halten , Rahmen, Typo.
The arrow-defined order must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | Alphabetical order: Fuss Halten Ohmacht Rahmen Speiseröhre Typo | - | ||
MD | correct | Knowledge-base order: Typo, Fuss, Halten, Speiseröhre, Ohmacht, Rahmen | - | |
HTML | correct | Knowledge-base order: Typo, Fuss, Halten, Speiseröhre, Ohmacht, Rahmen | - |
3.7 Mathematical semantics
Fig. 3.13: formulas
The question is:
Are there formulas with radius r2
Formula semantics must be recognized.
Result:
All three agents answered:
Yes, my knowledge contains a formula with radius ( r_2 ):
[
= \frac{\pi}{3} \cdot h \cdot \left( {r_{1}}^{2} + \frac{r_{1}}{\left( \frac{1}{r_{2}} - \frac{1}{r_{1}} \right)} - \frac{{r_{2}}^{2}}{r_{1} \cdot \left( \frac{1}{r_{2}} - \frac{1}{r_{1}} \right)} \right)
]
The answer was rated correct because it represents the TeX formula. This is a display problem, not a recognition or answering problem.
RAG | Assessment | Text | Link | Notes |
correct | See image | - | ||
MD | correct | See image | - | |
HTML | correct | See image | - |
3.8 Index
Index references often give printed page numbers rather than PDF page indexes, sometimes Roman rather than Arabic, making mapping difficult.
Index terms need not match text. “Eckeltier” never occurs in the sample’s running text but links to “Straßenhunde”. PDF data lose this semantic relationship.
HTML and revised Markdown anchor index entries and marginalia directly in text, supporting identification, processing, semantic understanding and cross-references.
Fig. 3.14: index
The question is:
Which dogs are called “Ekeltiere”?
The index association must be recognized.
Result:
RAG | Assessment | Text | Link | Notes |
incorrect | No idea. I have no information on that. | - | ||
MD | correct | Stray dogs are sometimes called “Ekeltier”, particularly when inadequate food causes chronic deficiencies | - | |
HTML | correct | Stray dogs are sometimes called “Ekeltier”, particularly when inadequate food causes chronic deficiencies | - |
4 Discussion
4.1 RAG training procedure
Extraction/cleaning and embedding calculation/storage are the two crucial training stages where content quality can still be improved for better retrieval and generation.
4.1.1 Data extraction and cleaning
Unstructured data first become uniform text. pdfplumber or PyMuPDF extract PDFs; BeautifulSoup crawls websites; SQL or APIs retrieve database data.
Text is segmented into sentences, paragraphs or topics for smaller, more precise retrieval units, then cleaned of excess whitespace, HTML tags or special characters.
Titles, authors, dates and category metadata can improve semantic quality, later search and context weighting.
4.1.2 Calculate and store embeddings
Text segments become vectors using pretrained sentence-transformers models such as all-MiniLM, BGE and E5, or domain fine-tuning with contrastive learning.
Separate metadata and content embeddings can be combined for semantic relationships. Alternatively, [TITLE] and [DATE] tags can sensitize models to different contexts.
Embeddings are stored in FAISS, Pinecone or ChromaDB vector databases for efficient search and retrieval.
4.2 Critical view of the study
The study was not entirely fair: it illustrated strongly problem-dependent answer quality without comparing methodologies or multiple complete systems, which would support broader evaluation.
Through our Octopus Service, we also have extensive PDF-to-XML expertise and know typical extraction processes. This early stage offers the greatest leverage: lost or misread information is barely recoverable later. Shit in, shit out—even the best system depends on input quality.
5 Conclusions
Structured files clearly produced better RAG training results. References, bibliographies and footnotes are crucial in science and law, supporting understanding and contextualization. Omitting them loses semantic relationships and sources.
Tables also contain crucial structured data. Correct understanding is central to identifying relationships and extracting information.
High-quality RAG requires a structured basis including all relevant footnotes, links and tables.
The resulting test suite permits comparison of RAG providers and embeddings. Training files and prompts support testing systems and comparing answers and ratings to evaluate approaches.
This is only a first step. In part II of the series, embedding models will be analyzed for how they store and use semantics.
A major aim is a structured intermediate format efficiently serving different models for consistent, high-quality data. Octopus will also extract as much as possible automatically from PDF and other formats, supplying richer semantics than usual for precise, contextual processing beyond text extraction (see part III of the series).
Part IV of the series will address storage and content delivery services to optimize efficient storage, retrieval and integration of semantic data into applications.
6 Appendix
The folder contains HTML, Markdown and PDF versions of the same content. An Excel file Ergebnisse_Zusammenfassung.xlsx summarizes all results, prompts, answers and assessments.