TikaDocumentExtractor

org.llm4s.extract.TikaDocumentExtractor

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
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

override def canExtract(mimeType: String): Boolean

PDF, DOCX, text, HTML, XML and JSON, and any document format a Tika parser module on the classpath reads (#3013). Images, audio and video are not documents here, whatever parser is present: they are media (MediaExtractor).

PDF, DOCX, text, HTML, XML and JSON, and any document format a Tika parser module on the classpath reads (#3013). Images, audio and video are not documents here, whatever parser is present: they are media (MediaExtractor).

Attributes

Definition Classes
Source
TikaDocumentExtractor.scala
override def detectMimeType(content: Array[Byte], filename: String): String

Detect the MIME type of document content.

Detect the MIME type of document content.

Value parameters

content

Raw document bytes (only first few KB are needed)

filename

Filename hint for detection

Attributes

Returns

Detected MIME type string

Definition Classes
Source
TikaDocumentExtractor.scala
def detectMimeType(file: File): String

Detect the MIME type of a file on disk, from its content and name.

Detect the MIME type of a file on disk, from its content and name.

Attributes

Source
TikaDocumentExtractor.scala
override def extract(content: Array[Byte], filename: String, mimeType: Option[String]): Result[ExtractedDocument]

Extract text content from document bytes.

Extract text content from document bytes.

Value parameters

content

Raw document bytes

filename

Filename for type detection (e.g., "report.pdf"). Used to detect format if mimeType is not provided.

mimeType

Optional MIME type override. If provided, skips detection.

Attributes

Returns

Extracted document with text, metadata, and detected format

Definition Classes
Source
TikaDocumentExtractor.scala

Extract text content from a file on the local filesystem.

Extract text content from a file on the local filesystem.

Surrounding whitespace and a single pair of matching quotes are stripped from path before it is resolved, so paths pasted from a shell or a prompt work.

Value parameters

path

Path to the file to read

Attributes

Returns

Extracted document with text, metadata, and detected format

Definition Classes
Source
TikaDocumentExtractor.scala
override def extractFromStream(input: InputStream, filename: String, mimeType: Option[String]): Result[ExtractedDocument]

Extract text content from an InputStream.

Extract text content from an InputStream.

Use this for large files to avoid loading the entire content into memory. The caller is responsible for closing the stream after this method returns.

Value parameters

filename

Filename for type detection

input

InputStream to read from

mimeType

Optional MIME type override

Attributes

Returns

Extracted document with text, metadata, and detected format

Definition Classes
Source
TikaDocumentExtractor.scala
def hasTikaParser(mimeType: String): Boolean

Whether a Tika parser on the classpath reads mimeType itself, as one does once the application adds the Tika parser module for it to its build. tika-core alone has none. A parser of a type it is a kind of does not count: Tika's text parser would read an RTF file (a kind of text/plain) as its markup.

Whether a Tika parser on the classpath reads mimeType itself, as one does once the application adds the Tika parser module for it to its build. tika-core alone has none. A parser of a type it is a kind of does not count: Tika's text parser would read an RTF file (a kind of text/plain) as its markup.

Attributes

Source
TikaDocumentExtractor.scala

Concrete fields

The most characters a Tika parser's extraction returns; a longer text is an error, not cut short (#3013).

The most characters a Tika parser's extraction returns; a longer text is an error, not cut short (#3013).

Attributes

Source
TikaDocumentExtractor.scala

The largest file extractFromPath reads: 256 MiB. A larger one is refused before it is read (#3012).

The largest file extractFromPath reads: 256 MiB. A larger one is refused before it is read (#3012).

Attributes

Source
TikaDocumentExtractor.scala