Views
No views yet
1import { pipeline } from "@huggingface/transformers";
2
3// Create a feature extraction pipeline
4const extractor = await pipeline(
5 "feature-extraction",
6 "dssjon/Qwen3-Embedding-4B-ONNX",
7 {
8 dtype: "fp32",
9 device: "webgpu", // Use WebGPU for acceleration
10 }
11);
12
13// Format query with instruction
14const taskDescription = "Given a web search query, retrieve relevant passages that answer the query";
15const query = `Instruct: ${taskDescription}\nQuery:What is the capital of China?`;
16
17// Generate embedding
18const output = await extractor(query, {
19 pooling: "last_token",
20 normalize: true
21});
22
23console.log(output.data); // 2560-dimensional embedding1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("Qwen/Qwen3-Embedding-4B")
4
5# For queries
6query = "What is the capital of China?"
7query_embedding = model.encode(query, prompt_name="query")
8
9# For documents (no prompt needed)
10document = "The capital of China is Beijing."
11doc_embedding = model.encode(document)| Task | Score |
|---|---|
| Classification | 89.84 |
| Clustering | 57.51 |
| Pair Classification | 87.01 |
| Reranking | 50.76 |
| Retrieval | 68.46 |
| STS | 88.72 |
| Summarization | 34.39 |
| Mean | 74.60 |
1@article{qwen3embedding2025,
2 title={Qwen3 Embedding},
3 author={Qwen Team},
4 year={2025},
5 url={https://huggingface.co/Qwen/Qwen3-Embedding-4B}
6}