Skip to main content

openai-simple-rerank

一个简单的rank模型的OPENAI兼容API服务的客户端访问工具。

安装

pip install openai-simple-rerank

使用

建议使用xinference启动rerank模型

验证过的模型列表

  • bge-reranker-v2-m3

配置变量设置

# OPENAI兼容API服务,可以xinference提供
# 使用OPENAI_RERANK_BASE_URL或RERANK_BASE_URL设置独立的服务地址
export OPENAI_BASE_URL="http://localhost/v1"
# OPENAI兼容API服务密钥,一般以sk-开头,共16位长
# 使用OPENAI_RERANK_API_KEY或RERANK_API_KEY设置独立的服务密码
export OPENAI_API_KEY=""
# 默认的文本重排序模型
export OPENAI_RERANK_MODEL="bge-reranker-v2-m3"
# 默认的最大字符串长度控制
export OPENAI_RERANK_MAX_SIZE=1024

获取文本向量

代码

from openai_simple_rerank.base import get_rerank_scores

s1, s2 = get_rerank_scores("hello", ["hi", "world"])
print(s1, s2)

输出

0.9953891038894653 0.40583446621894836

关于字符串长度控制

  • 模型本身一般没有字符串长度控制。
  • 但过长的字符串会导入模型占用内存的增长。
  • 所以默认将字符串长度控制在:1024字。
  • 通过OPENAI_RERANK_MAX_SIZE设置默认最大字符串长度。
  • 也可以函数调用中指定最大字符串长度。
  • 注意:所有超过最大长度的字符串将被截断。

版本记录

v0.1.0

  • 版本首发。

v0.1.1

  • 允许rerank模型使用独立的服务地址及密码。

v0.1.2

  • 使用RuntimeError替换自定义错误类。

v0.1.3

  • 修正OPENAI_RERANK_MODEL默认值。

Release files for openai-simple-rerank 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for openai-simple-rerank 0.1.3
File Interpreter ABI Platform
openai_simple_rerank-0.1.3-py3-none-any.whl Python 3 none any Details

Release files / openai_simple_rerank-0.1.3-py3-none-any.whl

Download URL openai_simple_rerank-0.1.3-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83b86409335fef7d38c1e1b4dc8916cf1b6ca5877769125151866ccac794f70d
BLAKE2b-256 checksum
How to use checksums
7ddb8b6990b0ec98c11f943689555675c32707149b9742d239001e158601b6ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page