Skip to main content

基于RedisStack向量数据库,集成embeddings和rerank模型,支持二阶段召回,支持添加和删除等管理功能。

Project description

openai-redis-vectorstore

基于RedisStack向量数据库,集成embeddings和rerank模型,支持二阶段召回,支持添加和删除等管理功能。

安装

pip install openai-redis-vectorstore

依赖说明

  • 使用python-environment-settings管理配置项。详见该项目的参考文档。
  • 深度依赖于openai-simple-embeddingsopenai-simple-rerank。同时也依赖于两者的配置项。详见这两个项目的参考文档。

配置项说明

  • REDIS_STACK_URL: redis-stack服务器地址。如:redis://localhost:6379/0
    • 有资料提到要使用redis-stack向量功能,必须是0号库(未测试)
    • (配置项别名)
    • REDIS_URL
    • REDIS

使用

将文本插入到向量数据库

代码:

from openai_redis_vectorstore.base import RedisVectorStore

index_name = str(uuid.uuid4())
rvs = RedisVectorStore()
uid = rvs.insert("hello", meta={"id": 1}, index_name=index_name)

说明:

  • id=1表示内容在业务系统中的唯一码。
  • uid表示内容在向量数据库中的唯一码。可以根据uid唯一码,从向量数据库中删除相应内容。

搜索向量数据库

代码:

from openai_redis_vectorstore.base import RedisVectorStore

index_name1 = str(uuid.uuid4())
index_name2 = str(uuid.uuid4())
rvs = RedisVectorStore()

# 向1号逻辑库中插入3条数据
rvs.insert_many(
    ["开会了", "再见", "你好"],
    metas=[
        {"id": 1},
        {"id": 2},
        {"id": 3},
    ],
    index_name=index_name1,
)

# 向2号逻辑库中插入3条数据
rvs.insert_many(
    ["开会去", "好的", "谢谢"],
    metas=[
        {"id": 1},
        {"id": 2},
        {"id": 3},
    ],
    index_name=index_name2,
)

# 从1号和2号逻辑库中搜索关键词并汇总
# 并要求匹配度不低于指定阈值
docs = rvs.similarity_search_and_rerank(
    query="开会",
    index_names=[index_name1, index_name2],
    embeddings_score_threshold=0.65,
    rerank_score_threshold=0.85,
)
assert len(docs) == 2
doc1 = docs[0]
doc2 = docs[1]
assert doc1.vs_index_name in [index_name1, index_name2]
assert doc2.vs_index_name in [index_name1, index_name2]
assert doc1.vs_rerank_score > doc2.vs_rerank_score

版本记录

v0.1.0

  • 版本首发。

v0.1.1

  • 修改:搜索一个空向量库时,只在日志中记录WARNING信息并返回空数组。

v0.1.2

  • 修改:openai_redis_vectorstore.schemas.Document增加content字段。

0.1.3

  • 修正:查询结果page_content字段没有做反序列化的问题。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_redis_vectorstore-0.1.3.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_redis_vectorstore-0.1.3-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file openai_redis_vectorstore-0.1.3.tar.gz.

File metadata

  • Download URL: openai_redis_vectorstore-0.1.3.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for openai_redis_vectorstore-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e500da26a827730d20ba646a6590d8e3420c55af6b86e822122b8c823c4fd75e
MD5 123709d3939dbdfd77db1fc88a7aa651
BLAKE2b-256 ebf4edf8aa66ef149cbfb4b7b7c61d4a4e2e3352c69a530fa84288bf8a7ac54c

See more details on using hashes here.

File details

Details for the file openai_redis_vectorstore-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_redis_vectorstore-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb97fc7336d856606b669a2747484ca25d4e9f0387bbd0e85e72f30eeeefd83
MD5 b2dc70815f4a55202b083ed876fcb5cb
BLAKE2b-256 4d888076f82fa10e6e270876dd330bb4bfef84e4ce21e3bc4a0ef7712faf42b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page