org.llm4s.extract

Members list

Type members

Classlikes

Service for extracting text content from documents.

Service for extracting text content from documents.

DocumentExtractor is source-agnostic - it works with raw bytes from any source (filesystem, S3, HTTP, database, etc.). This allows the same extraction logic to be used regardless of where the document is stored. extractFromPath is the one filesystem-aware entry point, provided because loading a local file is common enough that every caller would otherwise write the same three lines.

Supported formats:

  • Plain text files (.txt, .md, .json, .xml, .csv, .html)
  • PDF documents (.pdf)
  • Word documents (.docx, .doc)

Usage:

val extractor = TikaDocumentExtractor

// Extract from bytes (common for S3, HTTP responses)
val result = extractor.extract(bytes, "report.pdf")

// Extract from stream (for large files)
val result = extractor.extractFromStream(inputStream, "report.pdf")

Attributes

Source
DocumentExtractor.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
sealed trait DocumentFormat

Supported document formats for extraction.

Supported document formats for extraction.

Attributes

Companion
object
Source
DocumentExtractor.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object CSV
object DOC
object DOCX
object HTML
object JSON
object Markdown
object PDF
object PlainText
object Unknown
object XML
Show all

Attributes

Companion
trait
Source
DocumentExtractor.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
final case class ExtractedDocument(text: String, metadata: Map[String, String], format: DocumentFormat)

Extracted document content with metadata.

Extracted document content with metadata.

Represents the result of extracting text from a document, including any metadata that could be extracted (title, author, etc.)

Value parameters

format

The detected document format

metadata

Document metadata (title, author, pageCount, etc.)

text

The extracted text content

Attributes

Source
DocumentExtractor.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Media-aware extraction: reads a file and returns it as text, an image, audio samples or video frames, discriminated by the MIME type Tika sniffs from its content.

Media-aware extraction: reads a file and returns it as text, an image, audio samples or video frames, discriminated by the MIME type Tika sniffs from its content.

Kept separate from DocumentExtractor on purpose. Document loading wants text and metadata from anything text-bearing; multimodal embedding wants the decoded media itself. The two share only the initial Tika sniff, and the audio and video cases overlap llm4s-speech and llm4s-image rather than RAG, so this may not stay here.

The sniff stays here because it needs Tika; the vocabulary it resolves to (org.llm4s.media.MediaCategory) lives in llm4s-media, so the modules that would consume audio and video branches can name the same categories without inheriting Tika.

Attributes

Source
MediaExtractor.scala
Supertypes
class Object
trait Matchable
class Any
Self type

The DocumentExtractor implementation, backed by Apache Tika, PDFBox and POI.

The DocumentExtractor implementation, backed by Apache Tika, PDFBox and POI.

Reads, with no further dependency:

  • PDF documents via Apache PDFBox
  • Word documents (.docx) via Apache POI
  • Text files, in the charset their byte-order mark or Content-Type names, else UTF-8
  • HTML (as its text), XML and JSON

llm4s-rag depends on tika-core alone, which detects formats but parses none (#3013). Any other format, such as .doc, .rtf, .pptx, .xlsx, .odt or .epub, is read only when the application adds the Apache Tika parser module for it to its own build (org.apache.tika:tika-parser-microsoft-module for the Microsoft formats, tika-parser-miscoffice-module for OpenDocument and EPUB, or tika-parsers-standard-package for all of them, at the tika-core version llm4s-rag uses): Tika finds a parser module on the classpath. Without one, such a format is a ProcessingError whose operation is unsupported-format and whose message names the format and the module to add. Text over 50 million characters is an error (extracted-text-too-long), never silently truncated.

This object is the single Tika/PDFBox/POI entry point in the library. It replaces both org.llm4s.extract.TikaDocumentExtractor and org.llm4s.llmconnect.extractors.UniversalExtractor, which were independent implementations of the same job.

Attributes

Source
TikaDocumentExtractor.scala
Supertypes
class Object
trait Matchable
class Any
Self type