EmbeddingUtils
public final class EmbeddingUtils
io/agentscope/core/embedding/EmbeddingUtils.java:32–266向量化 Utils,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.embedding 包。核心成员包括 applyTimeoutAndRetry、applyTimeoutAndRetryBatch、ensureDefaultExecutionConfig、convertDoubleListToArray、convertFloatListToDoubleArray、convertFloatArrayToDoubleArray。
Utility class for common EmbeddingModel operations.
This class provides shared functionality used across different EmbeddingModel implementations, including timeout and retry logic for embedding API calls, and conversion utilities.
方法摘要Method Summary
方法详情Method Detail
applyTimeoutAndRetry
public static T Mono<T> applyTimeoutAndRetry(Mono<T> embeddingMono, ExecutionConfig config, String modelName, String provider, Logger logger, String operationType)
应用超时和重试。
Applies timeout and retry configuration to an embedding Mono.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
embeddingMono | Mono<T> | 向量化 Mono(类型 `Mono`)。the original embedding Mono to enhance |
config | ExecutionConfig | 配置对象(类型 `ExecutionConfig`)。execution config containing timeout and retry settings (may be null) |
modelName | String | 模型用于错误消息和日志的名称。the name of the model for error messages and logging |
provider | String | 提供者(类型 `String`)。the provider name (e.g., "dashscope", "openai") for error messages |
logger | Logger | 日志记录器(类型 `Logger`)。the logger instance for debug and warning messages |
operationType | String | operation 类型(类型 `String`)。the operation type description (e.g., "embedding", "batch embedding") |
Mono<T>io/agentscope/core/embedding/EmbeddingUtils.java:74–143applyTimeoutAndRetry
public static Mono<double[]> applyTimeoutAndRetry(Mono<double[]> embeddingMono, ExecutionConfig config, String modelName, String provider, Logger logger)
应用超时和重试。
Applies timeout and retry configuration to a single embedding Mono.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
embeddingMono | Mono<double[]> | 向量化 Mono(类型 `Mono`)。the original embedding Mono to enhance |
config | ExecutionConfig | 配置对象(类型 `ExecutionConfig`)。execution config containing timeout and retry settings (may be null) |
modelName | String | 模型用于错误消息和日志的名称。the name of the model for error messages and logging |
provider | String | 提供者(类型 `String`)。the provider name (e.g., "dashscope", "openai") for error messages |
logger | Logger | 日志记录器(类型 `Logger`)。the logger instance for debug and warning messages |
Mono<double[]>io/agentscope/core/embedding/EmbeddingUtils.java:159–167applyTimeoutAndRetryBatch
public static Mono<List<double[]>> applyTimeoutAndRetryBatch(Mono<List<double[]>> batchEmbeddingMono, ExecutionConfig config, String modelName, String provider, Logger logger)
应用 applyTimeoutAndRetryBatch。
Applies timeout and retry configuration to a batch embedding Mono.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
batchEmbeddingMono | Mono<List<double[]>> | batch 向量化 Mono(类型 `Mono >`)。the original batch embedding Mono to enhance |
config | ExecutionConfig | 配置对象(类型 `ExecutionConfig`)。execution config containing timeout and retry settings (may be null) |
modelName | String | 模型用于错误消息和日志的名称。the name of the model for error messages and logging |
provider | String | 提供者(类型 `String`)。the provider name (e.g., "dashscope", "openai") for error messages |
logger | Logger | 日志记录器(类型 `Logger`)。the logger instance for debug and warning messages |
Mono<List<double[]>>io/agentscope/core/embedding/EmbeddingUtils.java:183–191ensureDefaultExecutionConfig
public static ExecutionConfig ensureDefaultExecutionConfig(ExecutionConfig config)
设置确保默认执行配置。
Ensures ExecutionConfig has MODEL_DEFAULTS applied.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
config | ExecutionConfig | 配置对象(类型 `ExecutionConfig`)。the original config (may be null) |
ExecutionConfigio/agentscope/core/embedding/EmbeddingUtils.java:208–214convertDoubleListToArray
public static double[] convertDoubleListToArray(List<Double> values)
转换 convertDoubleListToArray。
Converts a List of Double values to a double array.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
values | List<Double> | 值(类型 `List`)。the list of Double values |
double[]io/agentscope/core/embedding/EmbeddingUtils.java:225–231convertFloatListToDoubleArray
public static double[] convertFloatListToDoubleArray(List<Float> values)
转换 convertFloatListToDoubleArray。
Converts a List of Float values to a double array.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
values | List<Float> | 值(类型 `List`)。the list of Float values |
double[]io/agentscope/core/embedding/EmbeddingUtils.java:242–248convertFloatArrayToDoubleArray
public static double[] convertFloatArrayToDoubleArray(float[] values)
转换 convertFloatArrayToDoubleArray。
Converts a float array to a double array.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
values | float[] | 值(类型 `float[]`)。the float array |
double[]io/agentscope/core/embedding/EmbeddingUtils.java:259–265