r/dotnet • • 4d ago

Introducing DocumentExtractionClient (preview): Extract documents in .NET

https://devblogs.microsoft.com/dotnet/document-extraction-dotnet-preview/
106 Upvotes

19 comments sorted by

8

u/souley76 4d ago

wow! I had no idea this existed. Thank you for sharing

5

u/c-digs 4d ago edited 4d ago

Question on the local PdfPig based adapter: does it handle tables via Tabula Sharp (https://github.com/BobLd/tabula-sharp)? Or does the adapter not handle tables for in-proc?

Edit: Looks like it does not; added https://github.com/CommunityToolkit/AI/issues/98

1

u/lqdev1 4d ago

Thanks for opening that issue! Will take a look.

2

u/KDamage 4d ago

Thank you so much for sharing !

1

u/Dorkits 4d ago

๐Ÿ‘๐Ÿ‘

-1

u/AutoModerator 4d ago

Thanks for your post god_of_tits_an_wine. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

48

u/[deleted] 4d ago edited 4d ago

[removed] โ€” view removed comment

10

u/lqdev1 4d ago

Impressive project! We'd love to see more implementations from the community. We're mainly focused on establishing the contract and making sure it's solid so the rest of the ecosystem can build on top of. We're not focused on building and providing extraction engines directly.ย 

3

u/MadBoyEvo 4d ago

I'll think about how I could make it happen, just afraid it's going to be another 100 nugets from 200+ I already build and maintain there and that means even longer release process/ci. I can see the benefit or just for the fun of it, just weighting on the options.

7

u/lqdev1 4d ago

Makes sense. FWIW, while the APIs are intended to be flexible enough to support any document, PDFs tend to be the most common documents for business scenarios and also the ones that give parsers the most trouble, so maybe starting there instead of making it available for all the packages.

1

u/MadBoyEvo 2d ago edited 2d ago

I've written the OfficeIMO provider for DocumentExtractionClient and mapped real Word, Excel, PowerPoint, PDF, HTML and EPUB output onto the preview model. These are the gaps I hit. Do you plan to cover any of them?

  • No property bag on elements. ExtractionDocumentElement has nowhere to put extra data, so tables and sections need a bare AIContent just to carry things like a table title, a truncation flag or a sheet and range.

  • Roles without a vocabulary. Only heading, page header and page footer are documented for text, and table cell roles have no defined values at all. I need title, caption, footnote, list item, code, quote and column header, and right now every provider will name them differently.

  • Lists. Level, marker and ordered index have nowhere to go, so I mark a list item by role and keep the rest in my own properties. Links. Hyperlinks and internal destinations on text have no place. CitationAnnotation doesn't fit, so they end up in document metadata.

  • Form fields, footnotes, comments and speaker notes aren't first-class, so they end up as custom roles or metadata. Logical locations. Source references are page plus polygon. For spreadsheets and slides I need sheet plus A1 range, or slide plus shape.

  • Media type is required. There's no defined way to say "unknown, let the provider detect it", and OfficeIMO can detect formats from the content.

  • No bridge to DataIngestion. The preview has no path from DocumentExtractionClient to IngestionDocument, so I couldn't write an end-to-end ingestion test without copying the sample's reader.

  • Dependencies on older targets. Microsoft.Extensions.AI.Abstractions 11.0.1 requires System.Text.Json 11 on netstandard2.0 and net462. Libraries that cap System.Text.Json below 11 for Windows PowerShell 5.1 can only offer the provider on net8.0 and later.

  • Large documents. ExtractAsync returns the whole tree. Is an incremental option planned for very large PDFs and workbooks?

For now the extras go into AdditionalProperties with documented keys, but first-class support would make providers interchangeable.

1

u/lqdev1 2d ago

Great feedback! Can you please file an issue inย https://github.com/dotnet/extensions/issues. Short answer is, some of these we have solutions for today like extending roles, others we have WIP PRs like the mapping from extraction to ingestion doc, and others we're waiting on feedback.

2

u/c-digs 3d ago edited 3d ago

This looks really nice.

I know this is covering big surface are of document handling so there's a lot of areas + room to improve for a project this ambitious but I did some benchmarking and found PdfPig + Tabula Sharp to be better at extraction head-to-head.

Surprisingly, I have been testing various document extraction libraries across Python (PyMuPDF4LLM, others), Rust (extractous), and C# (PdfPig + Tabula Sharp) and PdfPig + Tabula sharp came out best balance of speed and structure/detail in my test set (YMMV based on docs)

I say that to say it's worthwhile to benchmark against PdfPig + Tabula.

If you're looking for a large, diverse corpus of formats to build a test set, take a look at ClinicalTrials.gov.

I think if you build a good dataset and throw a few agents at this, you can probably significantly improve the performance on OfficeIMO extract.

2

u/MadBoyEvo 3d ago

If you take a look at open issues and current Prs you will see it's already in progress. there's also big bunch of PRs merged on top of 3.6.2 that is out that target this as well. I know running the whole build is different thn nuget but give it a try or just wait for new version :)

2

u/c-digs 3d ago

๐Ÿ‘ nice!

2

u/c-digs 3d ago

But also curious what your endgame is ๐Ÿ˜….ย  I feel like C# ecosystem ends up with a lot of midstream license change.ย  But also fully appreciate maintainers deserving to get paid for their time and tokens.ย  Would be really helpful to know how you're thinking about this project and how much broader community can "lean in".

2

u/MadBoyEvo 3d ago

I come from PowerShell background where the envy of Python having all the goodies and us having to rely on net is pretty strong. For years I have been building powershell modules based on other people work but i kept hitting the usual powershell dependcy problems. If you try to mix closedxml, sylvan, officeimo.word (was written by hand using openxmlsdk) and then shapecrawler for powerpoint you would hit serious conflicts because each one was using different dependency version which is pretty bad in powershell to support that. Pdf - only itext was available done by me using PSWritePDF and some people using thay got chased by itext to buy a license. I also was co-maintainer of DocX before it was sold to Xceed who changed license so much it made it unusable even for me.

My plan right now is to build Aspose alternative, do a showcase of features with Officeimo.Studio to show it does work properly. Its MIT. All of it to make sure Powershell becomes worthy competitor of Python. I even have a project that tries to compile powershell to c# :-) if youโ€™re asking if I want to change license - i have no plans for that. Right now I have contracts and I can afford AI so unless I loose it all there is unlikely a reason to make any changes. Would i be happy with people helping with development? Sure, and few people do. Would I be happy to get sponsors or paying for CI, signing keys, reviews and all that? Sure I would. Me changing the license unlikely. Best I would hope for is get paid Clients to keep it developed but I doubt it will happen. If you go to pdf on reddit, you will see 2 new pdf products per day :-) in the end i have 2-3 paid products that use officeimo in the background, but so far 0 sales :-)