FileEmbedder

org.llm4s.rag.embed.FileEmbedder
object FileEmbedder

FileEmbedder handles extracting content from various file types and passing it to the appropriate embedding models.

Encodes files of arbitrary MIME types into embedding vector sequences.

MIME type is detected automatically via Apache Tika. Dispatch then depends on the media type:

  • Text-like files (plain text, HTML, PDF, source code, …): text is extracted by org.llm4s.extract.TikaDocumentExtractor, optionally chunked, then embedded via the supplied EmbeddingClient. Real embeddings are always produced.

  • Image / Audio / Video: behaviour depends on config.experimentalStubs. When false, the file bytes are read (bounded by config.maxMediaFileSize) and forwarded to the MultimodalEmbeddingProvider passed to encodeFromPath; without one the call fails. When true, a deterministic L2-normalised stub vector is returned instead; the vector is seeded from the file name, size, and last-modified time, so the same file always produces the same stub vector.

== Stub dimensions ==

Stub vectors are capped at MAX_STUB_DIMENSION (8 192) regardless of the configured model dimension, to prevent OOM errors during testing.

== Modality disambiguation ==

Each modality (image, audio, video) uses a different XOR seed constant when generating stub vectors, so stubs for the same file differ across modalities.

Attributes

Source
FileEmbedder.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

Encodes the file at path into one or more embedding vectors.

Encodes the file at path into one or more embedding vectors.

Value parameters

client

Embedding client used for text files.

config

Model, chunking and media settings; see FileEmbeddingConfig.

multimodal

Embeds image, audio and video files when config.experimentalStubs is false. No provider llm4s ships is one: implement org.llm4s.llmconnect.provider.MultimodalEmbeddingProvider over a multimodal endpoint.

path

Path to the file to encode; must exist and be a regular file.

Attributes

Returns

Right(vectors) — one vector per text chunk, or one vector per non-text file. Each vector's id starts with the file's absolute, normalised path (/data/docs/a.txt#chunk_0). Left(EmbeddingError) when the file does not exist, the MIME type is unsupported, the media file exceeds config.maxMediaFileSize, or a media file is given with neither a multimodal provider nor config.experimentalStubs; Left(ValidationError) when text chunking is enabled with a non-positive size or an overlap that is not smaller than size.

Source
FileEmbedder.scala

Concrete fields