Qwen (Tongyi Qianwen)
Qwen embedding models are purpose-built for text embedding and ranking. The family is based on the Qwen3 dense foundation models and is available in sizes from 0.6B to 8B parameters, suitable for edge deployment through to data-center workloads. The models support 100+ languages and multiple programming languages, handle long context (up to 32K tokens), and offer strong reasoning capabilities.
Using Qwen service requires you to follow Dashscope's pricing rules and may incur corresponding fees. Before proceeding, please visit their official website or refer to relevant documentation to confirm and accept their pricing standards. If you do not agree, please do not proceed.
Dependencies and authentication
- Install the
pyseekdbpackage. - Create a Dashscope API key for authentication.
Example: create a Qwen embedding function
Import and initialize QwenEmbeddingFunction. API keys are usually provided via environment variables.
-
Basic usage
Specify the model name; the function uses the default environment variable
DASHSCOPE_API_KEY.from pyseekdb.utils.embedding_functions import QwenEmbeddingFunction
ef = QwenEmbeddingFunction(
model_name="text-embedding-v1"
) -
Advanced usage
Override the API key environment variable and set
dimensionsandtimeoutas needed.from pyseekdb.utils.embedding_functions import QwenEmbeddingFunction
# Custom env var and timeout
ef = QwenEmbeddingFunction(
model_name="text-embedding-v1",
api_key_env="DASHSCOPE_API_KEY",
timeout=30
)
# Dynamic-dimension model with output dimension 512
ef = QwenEmbeddingFunction(
model_name="text-embedding-v3",
dimensions=512 # Reduce from default 1024 to 512
)
Parameters:
model_name: Qwen embedding model name (for example,text-embedding-v1,text-embedding-v3).api_key_env: Environment variable name for the API key (default:DASHSCOPE_API_KEY).timeout: Request timeout (seconds), optional.dimensions: Output vector dimension (only effective when the model supports dynamic dimensions, such astext-embedding-v3can be adjusted from the default 1024 to a smaller value), optional.