dashscope

package module
v0.0.0-...-20b2a55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 3

README

DashScope Embedding for Eino

English | 简体中文

Introduction

This is a DashScope Embedding component implementation for Eino, which implements the Embedder interface and seamlessly integrates into Eino's embedding system to provide text vectorization capabilities. It uses Alibaba Cloud's DashScope text embedding API through OpenAI-compatible endpoints.

Features

  • Implements github.com/cloudwego/eino/components/embedding.Embedder interface
  • Easy integration into Eino workflows
  • Support for multiple DashScope embedding models (text-embedding-v1, text-embedding-v2, text-embedding-v3)
  • Configurable output dimensions for text-embedding-v3 model
  • Built-in callback support in Eino
  • Configurable timeout and HTTP client settings

Installation

go get github.com/cloudwego/eino-ext/components/embedding/dashscope

Quick Start

package main

import (
	"context"
	"log"
	"time"

	"github.com/cloudwego/eino-ext/components/embedding/dashscope"
)

func main() {
	ctx := context.Background()

	embedder, err := dashscope.NewEmbedder(ctx, &dashscope.EmbeddingConfig{
		APIKey:  "your-dashscope-api-key",
		Model:   "text-embedding-v3",
		Timeout: 30 * time.Second,
	})
	if err != nil {
		log.Fatalf("NewEmbedder of dashscope error: %v", err)
		return
	}

	vectors, err := embedder.EmbedStrings(ctx, []string{"hello", "how are you"})
	if err != nil {
		log.Fatalf("EmbedStrings of DashScope failed, err=%v", err)
	}

	log.Printf("vectors : %v", vectors)
}

Configuration

The embedder can be configured through the EmbeddingConfig structure:

type EmbeddingConfig struct {
    // APIKey is your DashScope API key
    // Required
    APIKey string `json:"api_key"`

    // Timeout specifies the http request timeout.
    // If HTTPClient is set, Timeout will not be used.
    // Optional. Default: no timeout
    Timeout time.Duration `json:"timeout"`

    // HTTPClient specifies the client to send HTTP requests.
    // If HTTPClient is set, Timeout will not be used.
    // Optional. Default &http.Client{Timeout: Timeout}
    HTTPClient *http.Client `json:"http_client"`

    // Model specifies which embedding model to use
    // Available models: text-embedding-v1, text-embedding-v2, text-embedding-v3
    // Async embedding models are not supported
    // Required
    Model string `json:"model"`

    // Dimensions specify output vector dimension
    // Only applicable to text-embedding-v3 model
    // Can only be selected between three values: 1024, 768, and 512
    // Optional. Default: 1024
    Dimensions *int `json:"dimensions,omitempty"`
}

Available Models

DashScope supports the following text embedding models:

  • text-embedding-v1: Basic text embedding model
  • text-embedding-v2: Enhanced text embedding model
  • text-embedding-v3: Latest text embedding model with configurable dimensions (512, 768, or 1024)

Note: Async embedding models are not supported.

Examples

See the following examples for more usage:

API Reference

For more details about DashScope's text embedding API, please refer to:

License

This component is licensed under the Apache License 2.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder struct {
	// contains filtered or unexported fields
}

func NewEmbedder

func NewEmbedder(ctx context.Context, config *EmbeddingConfig) (*Embedder, error)

func (*Embedder) EmbedStrings

func (e *Embedder) EmbedStrings(ctx context.Context, texts []string, opts ...embedding.Option) ([][]float64, error)

func (*Embedder) GetType

func (e *Embedder) GetType() string

func (*Embedder) IsCallbacksEnabled

func (e *Embedder) IsCallbacksEnabled() bool

type EmbeddingConfig

type EmbeddingConfig struct {
	// APIKey is typically OPENAI_API_KEY, but if you have set up Azure, then it is Azure API_KEY.
	APIKey string `json:"api_key"`
	// Timeout specifies the http request timeout.
	// If HTTPClient is set, Timeout will not be used.
	Timeout time.Duration `json:"timeout"`
	// HTTPClient specifies the client to send HTTP requests.
	// If HTTPClient is set, Timeout will not be used.
	// Optional. Default &http.Client{Timeout: Timeout}
	HTTPClient *http.Client `json:"http_client"`

	// Model available models: text_embedding_v / text_embedding_v2 / text_embedding_v3
	// Async embedding models not support.
	Model string `json:"model"`
	// Dimensions specify output vector dimension.
	// Only applicable to text-embedding-v3 model, can only be selected between three values: 1024, 768, and 512.
	// The default value is 1024.
	Dimensions *int `json:"dimensions,omitempty"`
}

Directories

Path Synopsis
examples
embedding command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL