Package org.apache.tika.inference
Class OpenAIEmbeddingEngine
java.lang.Object
org.apache.tika.inference.OpenAIEmbeddingEngine
- All Implemented Interfaces:
Closeable,AutoCloseable,Initializable,EmbeddingEngine,Engine
An OpenAI-compatible embeddings endpoint (
POST /v1/embeddings), named in
"engines". Sends up to maxBatchSize images per request as
{"image": "data:<mime>;base64,..."} inputs and reads the vectors back by index.
requestParameters ride every request body verbatim, for the keys a vendor adds to
the shape (Jina's task, a Matryoshka dimensions); the engine reads float
vectors back, so a key that changes the response shape is refused at load. The OpenAI
shape has no image input, so vendors differ: imageInput is "object" for
the {"image": ...} form (Jina) or "data-uri" for a bare data URI in
input (LiteLLM and other gateways).-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases what the engine holds (a client, a native handle); nothing by default.List<float[]> embedImages(List<byte[]> images, List<String> mimeTypes, ParseContext context) One request; the vectors come back in the order of the images.List<float[]> embedMedia(List<MediaInput> inputs, ParseContext context) Object form only:{"audio": data-uri}or{"video": data-uri}, as Jina names them.List<float[]> embedTexts(List<String> texts, ParseContext context) One request; the vectors come back in the order of the texts.How an image goes intoinput:"object"or"data-uri"; see the class note.intintWhether audio and video may be sent, and how:"none"or"object"({"audio": ...},{"video": ...}).getModel()Extra keys for every request body, as the vendor names them; see the class note.longvoidCalled after all properties have been set to allow for validation and initialization that depends on multiple properties.voidvoidsetApiKeyHeaderName(String apiKeyHeaderName) voidsetApiKeyPrefix(String apiKeyPrefix) voidsetBaseUrl(String baseUrl) voidsetEmbeddingsPath(String embeddingsPath) voidsetImageInput(String imageInput) voidsetMaxBatchSize(int maxBatchSize) voidsetMaxRetries(int maxRetries) Retries of a 429/502/503/504 answer, with backoff inside the parse budget; 0 fails at once.voidsetMediaInput(String mediaInput) voidvoidsetRequestParameters(Map<String, Object> requestParameters) voidsetTimeoutMillis(long timeoutMillis) booleanWhetherEmbeddingEngine.embedMedia(java.util.List<org.apache.tika.inference.MediaInput>, org.apache.tika.parser.ParseContext)is implemented; a MEDIA binding on an engine without it fails at load.
-
Field Details
-
MEDIA_INPUT_NONE
- See Also:
-
MEDIA_INPUT_OBJECT
- See Also:
-
IMAGE_INPUT_OBJECT
- See Also:
-
IMAGE_INPUT_DATA_URI
- See Also:
-
-
Constructor Details
-
OpenAIEmbeddingEngine
public OpenAIEmbeddingEngine()
-
-
Method Details
-
initialize
Description copied from interface:InitializableCalled after all properties have been set to allow for validation and initialization that depends on multiple properties.- Specified by:
initializein interfaceInitializable- Throws:
TikaConfigException- if there is a problem with the configuration
-
embedImages
public List<float[]> embedImages(List<byte[]> images, List<String> mimeTypes, ParseContext context) throws IOException, TikaException Description copied from interface:EmbeddingEngineOne request; the vectors come back in the order of the images.- Specified by:
embedImagesin interfaceEmbeddingEngine- Throws:
IOExceptionTikaException
-
supportsMedia
public boolean supportsMedia()Description copied from interface:EmbeddingEngineWhetherEmbeddingEngine.embedMedia(java.util.List<org.apache.tika.inference.MediaInput>, org.apache.tika.parser.ParseContext)is implemented; a MEDIA binding on an engine without it fails at load.- Specified by:
supportsMediain interfaceEmbeddingEngine
-
embedMedia
public List<float[]> embedMedia(List<MediaInput> inputs, ParseContext context) throws IOException, TikaException Object form only:{"audio": data-uri}or{"video": data-uri}, as Jina names them.- Specified by:
embedMediain interfaceEmbeddingEngine- Throws:
IOExceptionTikaException
-
embedTexts
public List<float[]> embedTexts(List<String> texts, ParseContext context) throws IOException, TikaException Description copied from interface:EmbeddingEngineOne request; the vectors come back in the order of the texts.- Specified by:
embedTextsin interfaceEmbeddingEngine- Throws:
IOExceptionTikaException
-
close
Description copied from interface:EngineReleases what the engine holds (a client, a native handle); nothing by default.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceEngine- Throws:
IOException
-
getBaseUrl
-
setBaseUrl
-
getModel
-
setModel
-
getApiKey
-
setApiKey
-
getTimeoutMillis
public long getTimeoutMillis() -
setTimeoutMillis
public void setTimeoutMillis(long timeoutMillis) -
getMaxRetries
public int getMaxRetries() -
setMaxRetries
public void setMaxRetries(int maxRetries) Retries of a 429/502/503/504 answer, with backoff inside the parse budget; 0 fails at once. -
getMaxBatchSize
public int getMaxBatchSize()- Specified by:
getMaxBatchSizein interfaceEmbeddingEngine
-
setMaxBatchSize
public void setMaxBatchSize(int maxBatchSize) -
getEmbeddingsPath
-
setEmbeddingsPath
-
getApiKeyHeaderName
-
setApiKeyHeaderName
-
getImageInput
How an image goes intoinput:"object"or"data-uri"; see the class note. -
setImageInput
-
getMediaInput
Whether audio and video may be sent, and how:"none"or"object"({"audio": ...},{"video": ...}). -
setMediaInput
-
getRequestParameters
Extra keys for every request body, as the vendor names them; see the class note. -
setRequestParameters
-
getApiKeyPrefix
-
setApiKeyPrefix
-