Package com.google.genkit.ai
Class Retriever
java.lang.Object
com.google.genkit.ai.Retriever
- All Implemented Interfaces:
Action<RetrieverRequest,,RetrieverResponse, Void> Registerable
Retriever is an action that retrieves documents based on a query.
Retrievers are used for RAG (Retrieval Augmented Generation) workflows to
find relevant documents to include in model prompts.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRetriever(String name, BiFunction<ActionContext, RetrieverRequest, RetrieverResponse> handler) Creates a new Retriever. -
Method Summary
Modifier and TypeMethodDescriptionstatic Retriever.Builderbuilder()Creates a builder for Retriever.getDesc()Returns the descriptor of the action containing metadata, schemas, etc.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, RetrieverRequest input) Runs the action with the given input.run(ActionContext ctx, RetrieverRequest 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
-
Retriever
Creates a new Retriever.- Parameters:
name- the retriever namehandler- the retrieval function
-
-
Method Details
-
builder
Creates a builder for Retriever.- Returns:
- a new builder
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<RetrieverRequest,RetrieverResponse, Void> - Returns:
- the action name
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<RetrieverRequest,RetrieverResponse, Void> - Returns:
- the action type
-
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc.- Specified by:
getDescin interfaceAction<RetrieverRequest,RetrieverResponse, Void> - Returns:
- the action descriptor
-
run
Description copied from interface:ActionRuns the action with the given input.- Specified by:
runin interfaceAction<RetrieverRequest,RetrieverResponse, 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 RetrieverResponse run(ActionContext ctx, RetrieverRequest input, Consumer<Void> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with the given input and streaming callback.- Specified by:
runin interfaceAction<RetrieverRequest,RetrieverResponse, 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<RetrieverRequest,RetrieverResponse, 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<RetrieverRequest,RetrieverResponse, 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<RetrieverRequest,RetrieverResponse, 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<RetrieverRequest,RetrieverResponse, 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<RetrieverRequest,RetrieverResponse, 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
-