{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ``rvl`` ~ The RedisVL CLI\n", "\n", "RedisVL is a Python library with a dedicated CLI to help load and create vector search indices within Redis.\n", "\n", "This notebook will walk through how to use the Redis Vector Library CLI (``rvl``).\n", "\n", "Before running this notebook, be sure to\n", "1. Have installed ``redisvl`` and have that environment active for this notebook.\n", "2. Have a running Redis instance with the Search and Query capability" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:27:21\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m RedisVL version 0.2.0\n" ] } ], "source": [ "# First, see if the rvl tool is installed\n", "!rvl version" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Index\n", "\n", "The ``rvl index`` command can be used for a number of tasks related to creating and managing indices. Wether you are working in Python or another language, this cli tool can still be useful for managing and inspecting your indices.\n", "\n", "First, we will create an index from a yaml schema that looks like the following:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%writefile schema.yaml\n", "\n", "version: '0.1.0'\n", "\n", "index:\n", " name: vectorizers\n", " prefix: doc\n", " storage_type: hash\n", "\n", "fields:\n", " - name: sentence\n", " type: text\n", " - name: embedding\n", " type: vector\n", " attrs:\n", " dims: 768\n", " algorithm: flat\n", " distance_metric: cosine" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:33\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Index created successfully\n" ] } ], "source": [ "# Create an index from a yaml schema\n", "!rvl index create -s schema.yaml" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:34\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n", "\u001b[32m14:22:34\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. vectorizers\n" ] } ], "source": [ "# list the indices that are available\n", "!rvl index listall" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Index Information:\n", "╭──────────────┬────────────────┬────────────┬─────────────────┬────────────╮\n", "│ Index Name │ Storage Type │ Prefixes │ Index Options │ Indexing │\n", "├──────────────┼────────────────┼────────────┼─────────────────┼────────────┤\n", "│ vectorizers │ HASH │ ['doc'] │ [] │ 0 │\n", "╰──────────────┴────────────────┴────────────┴─────────────────┴────────────╯\n", "Index Fields:\n", "╭───────────┬─────────────┬────────┬────────────────┬────────────────╮\n", "│ Name │ Attribute │ Type │ Field Option │ Option Value │\n", "├───────────┼─────────────┼────────┼────────────────┼────────────────┤\n", "│ sentence │ sentence │ TEXT │ WEIGHT │ 1 │\n", "│ embedding │ embedding │ VECTOR │ │ │\n", "╰───────────┴─────────────┴────────┴────────────────┴────────────────╯\n" ] } ], "source": [ "# inspect the index fields\n", "!rvl index info -i vectorizers" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:36\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Index deleted successfully\n" ] } ], "source": [ "# delete an index without deleting the data within it\n", "!rvl index delete -i vectorizers" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:38\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n" ] } ], "source": [ "# see the index\n", "!rvl index listall" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Stats\n", "\n", "The ``rvl stats`` command will return some basic information about the index. This is useful for checking the status of an index, or for getting information about the index to use in other commands." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:39\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Index created successfully\n" ] } ], "source": [ "# create a new index with the same schema\n", "!rvl index create -s schema.yaml" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:40\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n", "\u001b[32m14:22:40\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. vectorizers\n" ] } ], "source": [ "# list the indices that are available\n", "!rvl index listall" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Statistics:\n", "╭─────────────────────────────┬────────────╮\n", "│ Stat Key │ Value │\n", "├─────────────────────────────┼────────────┤\n", "│ num_docs │ 0 │\n", "│ num_terms │ 0 │\n", "│ max_doc_id │ 0 │\n", "│ num_records │ 0 │\n", "│ percent_indexed │ 1 │\n", "│ hash_indexing_failures │ 0 │\n", "│ number_of_uses │ 1 │\n", "│ bytes_per_record_avg │ nan │\n", "│ doc_table_size_mb │ 0 │\n", "│ inverted_sz_mb │ 0 │\n", "│ key_table_size_mb │ 0 │\n", "│ offset_bits_per_record_avg │ nan │\n", "│ offset_vectors_sz_mb │ 0 │\n", "│ offsets_per_term_avg │ nan │\n", "│ records_per_doc_avg │ nan │\n", "│ sortable_values_size_mb │ 0 │\n", "│ total_indexing_time │ 0 │\n", "│ total_inverted_index_blocks │ 0 │\n", "│ vector_index_sz_mb │ 0.00818634 │\n", "╰─────────────────────────────┴────────────╯\n" ] } ], "source": [ "# see all the stats for the index\n", "!rvl stats -i vectorizers" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m14:22:42\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Index deleted successfully\n" ] } ], "source": [ "!rvl index destroy -i vectorizers" ] } ], "metadata": { "kernelspec": { "display_name": "rvldev", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }