Package com.google.genkit.ai
Class Embedder
java.lang.Object
com.google.genkit.ai.Embedder
- All Implemented Interfaces:
Action<EmbedRequest,,EmbedResponse, Void> Registerable
- Direct Known Subclasses:
GeminiEmbedder,OpenAIEmbedder
Embedder is an action that generates embeddings from documents.
Embedders convert text or other content into numerical vectors that can be
used for similarity search and retrieval.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionEmbedder(String name, EmbedderInfo info, BiFunction<ActionContext, EmbedRequest, EmbedResponse> handler) Creates a new Embedder. -
Method Summary
Modifier and TypeMethodDescriptionstatic Embedder.Builderbuilder()Creates a builder for Embedder.getDesc()Returns the descriptor of the action containing metadata, schemas, etc.getInfo()Gets the embedder info.Returns the JSON schema for the action's input type.Returns additional metadata for the action.getName()Returns the name of the action.Returns the JSON schema for the action's output type.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, EmbedRequest input) Runs the action with the given input.run(ActionContext ctx, EmbedRequest input, Consumer<Void> streamCallback) Runs the action with the given input and streaming callback.com.fasterxml.jackson.databind.JsonNoderunJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns JSON output.ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns the result with telemetry information.
-
Constructor Details
-
Embedder
public Embedder(String name, EmbedderInfo info, BiFunction<ActionContext, EmbedRequest, EmbedResponse> handler) Creates a new Embedder.- Parameters:
name- the embedder nameinfo- the embedder infohandler- the embedding function
-
-
Method Details
-
builder
Creates a builder for Embedder.- Returns:
- a new builder
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the action name
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the action type
-
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc.- Specified by:
getDescin interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the action descriptor
-
run
Description copied from interface:ActionRuns the action with the given input.- Specified by:
runin interfaceAction<EmbedRequest,EmbedResponse, Void> - Parameters:
ctx- the action contextinput- the input to the action- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
run
public EmbedResponse run(ActionContext ctx, EmbedRequest input, Consumer<Void> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with the given input and streaming callback.- Specified by:
runin interfaceAction<EmbedRequest,EmbedResponse, Void> - Parameters:
ctx- the action contextinput- the input to the actionstreamCallback- callback for receiving streaming chunks, may be null- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
runJson
public com.fasterxml.jackson.databind.JsonNode runJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns JSON output.- Specified by:
runJsonin interfaceAction<EmbedRequest,EmbedResponse, Void> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the JSON output
- Throws:
GenkitException- if the action fails
-
runJsonWithTelemetry
public ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns the result with telemetry information.- Specified by:
runJsonWithTelemetryin interfaceAction<EmbedRequest,EmbedResponse, Void> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the action result including telemetry data
- Throws:
GenkitException- if the action fails
-
getInputSchema
Description copied from interface:ActionReturns the JSON schema for the action's input type.- Specified by:
getInputSchemain interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the input schema as a map, or null if not defined
-
getOutputSchema
Description copied from interface:ActionReturns the JSON schema for the action's output type.- Specified by:
getOutputSchemain interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the output schema as a map, or null if not defined
-
getMetadata
Description copied from interface:ActionReturns additional metadata for the action.- Specified by:
getMetadatain interfaceAction<EmbedRequest,EmbedResponse, Void> - Returns:
- the metadata map
-
register
Description copied from interface:RegisterableRegisters this primitive with the given registry.- Specified by:
registerin interfaceRegisterable- Parameters:
registry- the registry to register with
-
getInfo
Gets the embedder info.- Returns:
- the embedder info
-