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

  • 版本首发。

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.0.tar.gz (11.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.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openai-redis-vectorstore-0.1.0.tar.gz
  • Upload date:
  • Size: 11.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.0.tar.gz
Algorithm Hash digest
SHA256 3aa5947848fe3a4a4566ee59306af5b0d3332e56817127b74727bb57114b2542
MD5 c33ef6b38450240f4e9b1a89946b8a49
BLAKE2b-256 6a9ac135f9fd257aa69b2a3e6c95b25adff68d553b2db5027ca7f299fa847436

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_redis_vectorstore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad7b9b0363450fc7bdf05c229c67c046d12caa94da91b254ae0784bd0e7e4b84
MD5 97cf5333b69acbafde8668d14c0441a1
BLAKE2b-256 9d05a848b289a7ca2ce09762436cca7a1397ac809d1d95a9f34dd5628556960d

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