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信息并返回空数组。

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.1.tar.gz (12.0 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.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file openai-redis-vectorstore-0.1.1.tar.gz.

File metadata

  • Download URL: openai-redis-vectorstore-0.1.1.tar.gz
  • Upload date:
  • Size: 12.0 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.1.tar.gz
Algorithm Hash digest
SHA256 3e356b344ef781bd4d73e45ebf8823fa3da078f36a22dd65414cf76c2b5acff1
MD5 4c8da46cdbb6a7e51a9075ae2e79f220
BLAKE2b-256 5aaaeebb8db339ab0d5ef2bcb6840b20a26dc3281169025c235b1a8e978ce5d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_redis_vectorstore-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4223cee5e49531dbe71804f7ed5792103a8b7c64c81d31d030b30fa629433a13
MD5 9eacb75be2af17747e7395a72d95a571
BLAKE2b-256 8fd9414f29a5414b4c7ef77382a165ef39864f3aa01374d62068638661886c52

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