RedisVL CLI

如何使用 RedisVL 的 CLI

RedisVL 是一个 Python 代码库,它有一个专门的 CLI,用于帮助在 Redis 中加载和创建矢量搜索索引。

本指南将介绍如何使用 RedisVL CLI (rvl)。

注意
本文档是 此 Jupyter 笔记本 的转换形式。

在开始之前,请确保

  1. 您已安装了 RedisVL,并已激活该环境。
  2. 您有一个运行的 Redis 实例,它具有搜索和查询能力。
# First, see if the rvl tool is installed
$ rvl version
11:13:52 [RedisVL] INFO   RedisVL version 0.1.2

索引

rvl index 命令可用于执行与创建和管理索引相关的多项任务。无论您是在 Bash 或其他 shell 中工作,此 CLI 工具仍然可用于管理和检查您的索引。

首先,根据看起来类似以下内容的 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
# Create an index from a yaml schema
$ rvl index create -s schema.yaml
11:13:54 [RedisVL] INFO   Index created successfully
# List the indexes that are available
$ rvl index listall
11:13:56 [RedisVL] INFO   Indices:
11:13:56 [RedisVL] INFO   1. vectorizers
# inspect the index fields
$ rvl index info -i providers

Index Information:
╭──────────────┬────────────────┬────────────┬─────────────────┬────────────╮
│ Index Name   │ Storage Type   │ Prefixes   │ Index Options   │   Indexing │
├──────────────┼────────────────┼────────────┼─────────────────┼────────────┤
│ vectorizers  │ HASH           │ ['doc'][]0╰──────────────┴────────────────┴────────────┴─────────────────┴────────────╯
Index Fields:
╭───────────┬─────────────┬────────┬────────────────┬────────────────╮
│ Name      │ Attribute   │ Type   │ Field Option   │   Option Value │
├───────────┼─────────────┼────────┼────────────────┼────────────────┤
│ sentence  │ sentence    │ TEXT   │ WEIGHT         │              1│ embedding │ embedding   │ VECTOR │                │                │
╰───────────┴─────────────┴────────┴────────────────┴────────────────╯
# delete an index without deleting the data within it
$ rvl index delete -i vectorizers
11:13:59 [RedisVL] INFO   Index deleted successfully
# view the index
$ rvl index listall
11:14:00 [RedisVL] INFO   Indices:

统计

rvl stats 命令将返回有关索引的一些基本信息。这对于检查索引的状态或获取有关索引以用于其他命令的信息很有用。

# create a new index with the same schema
$ rvl index create -s schema.yaml
11:14:02 [RedisVL] INFO   Index created successfully
# list the indexes that are available
$ rvl index listall
11:14:03 [RedisVL] INFO   Indices:
11:14:03 [RedisVL] INFO   1. vectorizers
# see all the stats for the index
$ rvl stats -i providers

Statistics:
╭─────────────────────────────┬────────────╮
│ Stat Key                    │ Value      │
├─────────────────────────────┼────────────┤
│ num_docs                    │ 0│ num_terms                   │ 0│ max_doc_id                  │ 0│ num_records                 │ 0│ percent_indexed             │ 1│ hash_indexing_failures      │ 0│ number_of_uses              │ 1│ 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│ total_inverted_index_blocks │ 0│ vector_index_sz_mb          │ 0.00818634 │
╰─────────────────────────────┴────────────╯
$ rvl index destroy -i vectorizers

09:00:27 [RedisVL] INFO   Index deleted successfully
RATE THIS PAGE
Back to top ↑