Views
No views yet

検索クエリ: / 検索文書: ).pip install -U sentence-transformers⚠️ Encode queries with the query prompt and documents with the document prompt. (Both use their own prefix; skipping the prompt slightly degrades retrieval quality.)
1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("sionic-ai/comsat-embed-ja-0.3b-preview")
4
5queries = ["日本の首都はどこですか?"]
6documents = ["日本の首都は東京です。"]
7
8# Prefixes ("検索クエリ: " / "検索文書: ") are applied automatically by prompt_name
9q_emb = model.encode(queries, prompt_name="query", normalize_embeddings=True)
10d_emb = model.encode(documents, prompt_name="document", normalize_embeddings=True)
11
12# Option: sentence-transformers 5.x helper API (equivalent)
13# q_emb = model.encode_query(queries)
14# d_emb = model.encode_document(documents)
15
16scores = q_emb @ d_emb.T # cosine similarity
17print(scores)1import torch
2import torch.nn.functional as F
3from torch import Tensor
4from transformers import AutoTokenizer, AutoModel
5
6
7def mean_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor:
8 mask = attention_mask.unsqueeze(-1).to(last_hidden_states.dtype)
9 return (last_hidden_states * mask).sum(dim=1) / mask.sum(dim=1).clamp(min=1e-9)
10
11
12# Prepend the prefixes manually when using plain Transformers
13queries = ["検索クエリ: 日本の首都はどこですか?"]
14documents = ["検索文書: 日本の首都は東京です。"]
15input_texts = queries + documents
16
17tokenizer = AutoTokenizer.from_pretrained("sionic-ai/comsat-embed-ja-0.3b-preview")
18model = AutoModel.from_pretrained("sionic-ai/comsat-embed-ja-0.3b-preview")
19
20batch_dict = tokenizer(
21 input_texts,
22 padding=True,
23 truncation=True,
24 max_length=8192,
25 return_tensors="pt",
26)
27with torch.no_grad():
28 outputs = model(**batch_dict)
29
30embeddings = mean_pool(outputs.last_hidden_state, batch_dict["attention_mask"])
31embeddings = F.normalize(embeddings, p=2, dim=1)
32scores = embeddings[:1] @ embeddings[1:].T # cosine similarity
33print(scores.tolist())ja, MrTidy=japanese).| Model | Avg | NLPJ-TitleAbs | NLPJ-TitleIntro | NLPJ-AbsIntro | NLPJ-AbsArticle | Mintaka | JaGovFaqs | Jaqket | MultiLongDoc | JaCWIR | MIRACL | MrTidy |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| comsat-embed-ja-0.3b-preview | 0.7785 | 0.9807 | 0.9772 | 0.9945 | 0.9951 | 0.3686 | 0.7902 | 0.7617 | 0.4689 | 0.8721 | 0.7143 | 0.6402 |
| Qwen/Qwen3-Embedding-4B | 0.7779 | 0.9753 | 0.9589 | 0.9881 | 0.9959 | 0.5201 | 0.7179 | 0.6136 | 0.5659 | 0.8560 | 0.7244 | 0.6406 |
| codefuse-ai/F2LLM-v2-4B | 0.7705 | 0.9853 | 0.9803 | 0.9937 | 0.9966 | 0.4767 | 0.8064 | 0.6528 | 0.4701 | 0.8166 | 0.6527 | 0.6442 |
| sbintuitions/sarashina-embedding-v2-1b | 0.7659 | 0.9804 | 0.9782 | 0.9954 | 0.9858 | 0.4365 | 0.7561 | 0.7371 | 0.4529 | 0.8552 | 0.6552 | 0.5916 |
| cl-nagoya/ruri-v3-130m | 0.7641 | 0.9807 | 0.9643 | 0.9894 | 0.9959 | 0.3283 | 0.7729 | 0.7514 | 0.4565 | 0.8349 | 0.7157 | 0.6149 |
| cl-nagoya/ruri-v3-310m | 0.7630 | 0.9785 | 0.9653 | 0.9908 | 0.9959 | 0.3353 | 0.7726 | 0.7342 | 0.4393 | 0.8405 | 0.7233 | 0.6168 |
| cl-nagoya/ruri-v3-70m | 0.7473 | 0.9705 | 0.9620 | 0.9862 | 0.9896 | 0.2974 | 0.7461 | 0.7093 | 0.4392 | 0.8201 | 0.7050 | 0.5947 |
| nvidia/llama-nemotron-embed-vl-1b-v2 | 0.7464 | 0.9765 | 0.9669 | 0.9898 | 0.9966 | 0.2949 | 0.7076 | 0.6495 | 0.4257 | 0.8605 | 0.7143 | 0.6277 |
| codefuse-ai/F2LLM-v2-1.7B | 0.7426 | 0.9790 | 0.9699 | 0.9932 | 0.9980 | 0.3584 | 0.7857 | 0.6012 | 0.4597 | 0.8181 | 0.6153 | 0.5897 |
| cl-nagoya/ruri-v3-30m | 0.7330 | 0.9748 | 0.9540 | 0.9910 | 0.9893 | 0.2836 | 0.7236 | 0.6530 | 0.4626 | 0.8193 | 0.6635 | 0.5481 |
| cl-nagoya/ruri-large-v2 | 0.7260 | 0.9750 | 0.8184 | 0.9145 | 0.9083 | 0.3377 | 0.7744 | 0.7336 | 0.3933 | 0.8021 | 0.7136 | 0.6152 |
| Qwen/Qwen3-VL-Embedding-2B | 0.7253 | 0.9644 | 0.9454 | 0.9833 | 0.9946 | 0.3026 | 0.6915 | 0.5605 | 0.4638 | 0.8510 | 0.6402 | 0.5815 |
| BAAI/bge-m3 | 0.7245 | 0.9592 | 0.9164 | 0.9710 | 0.9528 | 0.2145 | 0.7066 | 0.5122 | 0.5034 | 0.8509 | 0.7285 | 0.6545 |
| google/embeddinggemma-300m | 0.7230 | 0.9627 | 0.9231 | 0.9757 | 0.9866 | 0.2683 | 0.7209 | 0.6749 | 0.3852 | 0.8524 | 0.6542 | 0.5490 |
| Snowflake/snowflake-arctic-embed-l-v2.0 | 0.7111 | 0.9727 | 0.9444 | 0.9873 | 0.9643 | 0.2344 | 0.7203 | 0.4328 | 0.4648 | 0.8549 | 0.6608 | 0.5856 |
| sbintuitions/sarashina-embedding-v1-1b | 0.7078 | 0.9688 | 0.9661 | 0.9916 | 0.9920 | 0.4025 | 0.7223 | 0.6412 | 0.3420 | 0.8254 | 0.5124 | 0.4219 |
| codefuse-ai/F2LLM-v2-0.6B | 0.7078 | 0.9671 | 0.9590 | 0.9921 | 0.9966 | 0.2734 | 0.7609 | 0.4896 | 0.4185 | 0.8018 | 0.5723 | 0.5548 |
| cl-nagoya/ruri-base-v2 | 0.7043 | 0.9658 | 0.7821 | 0.8982 | 0.9045 | 0.2997 | 0.7532 | 0.6947 | 0.3675 | 0.8044 | 0.6840 | 0.5928 |
Avg is the mean over the 11 JMTEB(v2) retrieval tasks (higher is better). Reproduction: evaluated with the MTEB/JMTEB retrieval pipeline (NDCG@10, full corpus); the query prompt (検索クエリ:) is applied to queries and the document prompt (検索文書:) to documents.