Skip to main content
Open In ColabOpen on GitHub

百川文本嵌入

截至2024年1月25日,百川文本嵌入(BaichuanTextEmbeddings)在C-MTEB(中文多任务嵌入基准)排行榜上排名第一。

排行榜(在总体下 -> 中文部分):https://huggingface.co/spaces/mteb/leaderboard

官方网站:https://platform.baichuan-ai.com/docs/text-Embedding

使用此嵌入模型需要API密钥。您可以通过在 https://platform.baichuan-ai.com/docs/text-Embedding 注册获取。

百川文本嵌入支持512个标记窗口,并生成1024维的向量。

请注意,BaichuanTextEmbeddings仅支持中文文本嵌入。多语言支持即将推出。

from langchain_community.embeddings import BaichuanTextEmbeddings

embeddings = BaichuanTextEmbeddings(baichuan_api_key="sk-*")

或者,你可以这样设置API密钥:

import os

os.environ["BAICHUAN_API_KEY"] = "YOUR_API_KEY"
text_1 = "今天天气不错"
text_2 = "今天阳光很好"

query_result = embeddings.embed_query(text_1)
query_result
doc_result = embeddings.embed_documents([text_1, text_2])
doc_result