Text embedding generation processor
Input column name | Description |
|---|---|
text_contents | Provide the text data to be processed. |
Returns the embedding array processed by the model. Type: list[float]
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
model | str | doubao-embedding-large | Model name, for example: |
version | str or None | Model version. Enter the version information corresponding to the model. Example: text-250515 | |
api_key | str or None | ||
encoding_format | str or None | Encoding format for embedding. Supported formats: float, base64 | |
request_timeout | int | 1200 | Timeout. The timeout for a single request (seconds) |
max_concurrency | int | 100 | Concurrency. Maximum concurrency per process. |
The following code demonstrates how to use daft to access the ModelArk text embedding model for batch inference. Note that the results of each large model inference may vary.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.ark_llm.doubao_embedding_text import DoubaoEmbeddingText from daft.las.functions.udf import las_udf if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(min_cpu_per_task=0) if __name__ == "__main__": # You need to configure the environment variable LAS_API_KEY: Obtain LAS_API_KEY by creating it on the LAS service page samples = {"text": ["Hello World!", None]} df = daft.from_pydict(samples) # Compute the embedding data for text df = df.with_column( "embeddings", las_udf( DoubaoEmbeddingText, construct_args={ "model": "doubao-embedding-large", }, )(col("text")), ) df.show() # Output (the results of each large model inference may vary) # ╭────────┬───────────────────╮ # │ text ┆ embeddings │ # │ --- ┆ --- │ # │ Utf8 ┆ List[Float32] │ # ╞════════╪═══════════════════╡ # │ Hello World! ┆ [0.080078125, 1.8359375, 0.84… │ # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ # │ None ┆ None │ # ╰────────┴───────────────────╯