RedisVL CLI
RedisVL 是一个 Python 库,带有一个专用的 CLI 工具,用于在 Redis 中加载和创建向量搜索索引。
本 Notebook 将详细介绍如何使用 Redis Vector Library CLI (rvl
)。
在运行此 Notebook 之前,请确保
- 已安装
redisvl
,并已激活该环境以供此 Notebook 使用。 - 有一个正在运行的 Redis 实例,并启用了搜索和查询功能
# First, see if the rvl tool is installed
!rvl version
09:58:03 [RedisVL] INFO RedisVL version 0.5.2
命令
这里列出了所有 rvl 命令和选项的表格。我们将在下面详细介绍每个命令。
命令 | 选项 | 描述 |
---|---|---|
rvl version |
显示 redisvl 库版本 | |
rvl index |
create --schema 或 -s <schema.yaml> |
从指定的 schema 文件创建 Redis 索引 |
rvl index |
listall |
列出所有现有的搜索索引 |
rvl index |
info --index 或 -i <index_name> |
以表格格式显示索引定义 |
rvl index |
delete --index 或 -i <index_name> |
移除指定的索引,但保留数据在 Redis 中 |
rvl index |
destroy --index 或 -i <index_name> |
移除指定的索引以及相关联的数据 |
rvl stats |
--index 或 -i <index_name> |
显示索引统计信息,包括文档数量、每条记录的平均字节数、索引时间等 |
rvl stats |
--schema 或 -s <schema.yaml> |
显示 <schema.yaml> 中定义的 schema 的索引统计信息。该索引必须已在 Redis 中创建。 |
索引
rvl index
命令可用于许多与创建和管理索引相关的任务。无论您是使用 Python 还是其他语言进行开发,此 CLI 工具对于管理和检查索引仍然非常有用。
首先,我们将从一个如下所示的 yaml schema 创建一个索引
%%writefile schema.yaml
version: '0.1.0'
index:
name: vectorizers
prefix: doc
storage_type: hash
fields:
- name: sentence
type: text
- name: embedding
type: vector
attrs:
dims: 768
algorithm: flat
distance_metric: cosine
Overwriting schema.yaml
# Create an index from a yaml schema
!rvl index create -s schema.yaml
18:12:32 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:12:32 [RedisVL] INFO Index created successfully
# list the indices that are available
!rvl index listall
18:12:35 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:12:35 [RedisVL] INFO Indices:
18:12:35 [RedisVL] INFO 1. vectorizers
# inspect the index fields
!rvl index info -i vectorizers
18:12:37 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
Index Information:
╭──────────────┬────────────────┬────────────┬─────────────────┬────────────╮
│ Index Name │ Storage Type │ Prefixes │ Index Options │ Indexing │
├──────────────┼────────────────┼────────────┼─────────────────┼────────────┤
│ vectorizers │ HASH │ ['doc'] │ [] │ 0 │
╰──────────────┴────────────────┴────────────┴─────────────────┴────────────╯
Index Fields:
╭───────────┬─────────────┬────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬────────────────┬─────────────────┬────────────────╮
│ Name │ Attribute │ Type │ Field Option │ Option Value │ Field Option │ Option Value │ Field Option │ Option Value │ Field Option │ Option Value │
├───────────┼─────────────┼────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼─────────────────┼────────────────┤
│ sentence │ sentence │ TEXT │ WEIGHT │ 1 │ │ │ │ │ │ │
│ embedding │ embedding │ VECTOR │ algorithm │ FLAT │ data_type │ FLOAT32 │ dim │ 768 │ distance_metric │ COSINE │
╰───────────┴─────────────┴────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴─────────────────┴────────────────╯
# delete an index without deleting the data within it
!rvl index delete -i vectorizers
18:12:40 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:12:40 [RedisVL] INFO Index deleted successfully
# see the indices that still exist
!rvl index listall
18:12:43 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:12:43 [RedisVL] INFO Indices:
统计信息
rvl stats
命令将返回有关索引的一些基本信息。这对于检查索引的状态,或获取索引信息以在其他命令中使用很有用。
# create a new index with the same schema
# recreating the index will reindex the documents
!rvl index create -s schema.yaml
18:13:21 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:13:21 redisvl.index.index INFO Index already exists, not overwriting.
18:13:21 [RedisVL] INFO Index created successfully
# list the indices that are available
!rvl index listall
18:13:25 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:13:25 [RedisVL] INFO Indices:
18:13:25 [RedisVL] INFO 1. vectorizers
# see all the stats for the index
!rvl stats -i vectorizers
18:13:31 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
Statistics:
╭─────────────────────────────┬─────────╮
│ Stat Key │ Value │
├─────────────────────────────┼─────────┤
│ num_docs │ 0 │
│ num_terms │ 0 │
│ max_doc_id │ 0 │
│ num_records │ 0 │
│ percent_indexed │ 1 │
│ hash_indexing_failures │ 3 │
│ number_of_uses │ 2 │
│ bytes_per_record_avg │ nan │
│ doc_table_size_mb │ 0 │
│ inverted_sz_mb │ 0 │
│ key_table_size_mb │ 0 │
│ offset_bits_per_record_avg │ nan │
│ offset_vectors_sz_mb │ 0 │
│ offsets_per_term_avg │ nan │
│ records_per_doc_avg │ nan │
│ sortable_values_size_mb │ 0 │
│ total_indexing_time │ 0.02 │
│ total_inverted_index_blocks │ 0 │
│ vector_index_sz_mb │ 0 │
╰─────────────────────────────┴─────────╯
可选参数
您可以使用以下可选参数修改这些命令
参数 | 描述 | 默认值 |
---|---|---|
-u --url |
要连接的完整 Redis URL | redis://:6379 |
--host |
要连接的 Redis 主机 | localhost |
-p --port |
要连接的 Redis 端口。必须是整数。 | 6379 |
--user |
Redis 用户名,如果需要的话 | default |
--ssl |
布尔标志,指示是否需要 SSL。如果设置,Redis 基础 URL 将更改为 rediss:// |
无 |
-a --password |
Redis 密码,如果需要的话 | "" |
选择您的 Redis 实例
默认情况下,rvl 首先检查您是否定义了 REDIS_URL
环境变量,并尝试连接到它。如果没有定义,则回退到 localhost:6379
,除非您传递了 --host
或 --port
参数。
# specify your Redis instance to connect to
!rvl index listall --host localhost --port 6379
18:13:36 [RedisVL] INFO Using Redis address from environment variable, REDIS_URL
18:13:36 [RedisVL] INFO Indices:
18:13:36 [RedisVL] INFO 1. vectorizers
使用 SSL 加密
如果您的 Redis 实例配置为使用 SSL 加密,请设置 --ssl
标志。您可以类似地指定用户名和密码来构建完整的 Redis URL。
# connect to rediss://jane_doe:password123@localhost:6379
!rvl index listall --user jane_doe -a password123 --ssl
!rvl index destroy -i vectorizers