bge small en v1.5

提供商michaelfeil
分类feature-extraction
许可证mit
下载量2.3M
星标0

简介

bge-small-en-v1.5 是一款轻量级的英文文本向量化模型,由 BAAI(北京智源人工智能研究院)开发。它主要用于将文本转化为高维向量,是构建 RAG(检索增强生成)系统的核心组件。相比于大型模型,它在保持极高检索精度的同时,极大地降低了推理延迟和内存占用。对于开发者而言,该模型上手简单,可直接替代 OpenAI 的 embedding 接口,在本地部署环境下能显著提升知识库检索的响应速度,非常适合处理大规模文档的索引与相似度匹配。

核心亮点

  • 由智源研究院开发,英文检索精度领先
  • 模型体积小,推理速度快,极低资源占用
  • RAG 架构首选,大幅提升知识库检索效率
  • MIT 协议开源,支持本地私有化灵活部署

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("michaelfeil/bge-small-en-v1.5")
tokenizer = AutoTokenizer.from_pretrained("michaelfeil/bge-small-en-v1.5")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download michaelfeil/bge-small-en-v1.5

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download michaelfeil/bge-small-en-v1.5 config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('michaelfeil/bge-small-en-v1.5')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/michaelfeil/bge-small-en-v1.5

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/michaelfeil/bge-small-en-v1.5

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('michaelfeil/bge-small-en-v1.5')
tokenizer = AutoTokenizer.from_pretrained('michaelfeil/bge-small-en-v1.5')

完整文档

来源: HuggingFace

---
tags:

  • sentence-transformers

  • feature-extraction

  • sentence-similarity

  • transformers

license: mit
language:
  • en

---

<h1 align="center">Infinity Embedding Model</h1>

This is the stable default model for infinity.

bash
pip install infinity_emb[all]

More details about the infinity inference project please refer to the Github: Infinity.

Usage for Embedding Model via infinity in Python

To deploy files with the infinity_emb pip package.
Recommended is device="cuda", engine="torch" with flash attention on gpu, and device="cpu", engine="optimum" for onnx inference.

python
import asyncio
from infinity_emb import AsyncEmbeddingEngine, EngineArgs

sentences = ["Embed this is sentence via Infinity.", "Paris is in France."]
engine = AsyncEmbeddingEngine.from_args(
EngineArgs(
model_name_or_path = "michaelfeil/bge-small-en-v1.5",
device="cuda",
# or device="cpu"
engine="torch",
# or engine="optimum"
compile=True # enable torch.compile
))

async def main():
async with engine:
embeddings, usage = await engine.embed(sentences=sentences)
asyncio.run(main())

CLI interface

The same args

bash
pip install infinity_emb
infinity_emb --model-name-or-path michaelfeil/bge-small-en-v1.5 --port 7997

Contact

If you have any question or suggestion related to this project, feel free to open an issue or pull request. You also can email Michael Feil (infinity at michaelfeil.eu).

Citation

If you find this repository useful, please consider giving a star :star: and citation

code
@software{Feil_Infinity_2023,
author = {Feil, Michael},
month = oct,
title = {{Infinity - To Embeddings and Beyond}},
url = {https://github.com/michaelfeil/infinity},
year = {2023}
}

License

Infinity is licensed under the MIT License.