Skip to main content
Open In Colab在 GitHub 上打开

百川文本嵌入

截至今天(2024 年 1 月 25 日),BaichuanTextEmbeddings 在 C-MTEB(Chinese Multi-Task Embedding Benchmark)排行榜中排名 #1。

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

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

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

BaichuanTextEmbeddings 支持 512 个 token 窗口和 1024 维的 preduces 向量。

请注意,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