Redis Vector Libraryへようこそ - Redisの力を活用するAIアプリケーション向けに設計された究極のPythonクライアント。
redisvlは次のためのあなたの頼りになるツールです:
pipを使用して、python(> = 3.8)環境にredisvlをインストールします。
pip install redisvl詳細については、インストールガイドをご覧ください。
複数のRedis展開オプションから選択します。
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest無料のRedis Insight GUIでの経験と観察性を向上させます。
ビルトインREDISおよびインデックス可能なフィールド(テキスト、タグ、数字、GEO、およびベクターなど)でデータセットをモデル化するユースケースのスキーマを設計します。 YAMLファイルからスキーマをロードします。
index :
name : user-idx
prefix : user
storage_type : json
fields :
- name : user
type : tag
- name : credit_score
type : tag
- name : embedding
type : vector
attrs :
algorithm : flat
dims : 4
distance_metric : cosine
datatype : float32 from redisvl . schema import IndexSchema
schema = IndexSchema . from_yaml ( "schemas/schema.yaml" )または、Python辞書から直接読み込みます。
schema = IndexSchema . from_dict ({
"index" : {
"name" : "user-idx" ,
"prefix" : "user" ,
"storage_type" : "json"
},
"fields" : [
{ "name" : "user" , "type" : "tag" },
{ "name" : "credit_score" , "type" : "tag" },
{
"name" : "embedding" ,
"type" : "vector" ,
"attrs" : {
"algorithm" : "flat" ,
"datatype" : "float32" ,
"dims" : 4 ,
"distance_metric" : "cosine"
}
}
]
})Redisのインデックスで管理操作と検索操作を実行するために、入力スキーマとクライアント接続を備えたSearchIndexクラスを作成します。
from redis import Redis
from redisvl . index import SearchIndex
# Establish Redis connection and define index
client = Redis . from_url ( "redis://localhost:6379" )
index = SearchIndex ( schema , client )
# Create the index in Redis
index . create ()Async Complaint Search Indexクラスも利用可能です:asyncsearchindex。
Redisインスタンスへの間でデータを読み込み、取得します。
data = { "user" : "john" , "credit_score" : "high" , "embedding" : [ 0.23 , 0.49 , - 0.18 , 0.95 ]}
# load list of dictionaries, specify the "id" field
index . load ([ data ], id_field = "user" )
# fetch by "id"
john = index . fetch ( "john" )クエリを定義し、ベクトル、メタデータフィルターなどの組み合わせなど、インデックスを介した高度な検索を実行します。
VectorQuery-セマンティック検索を可能にするカスタマイズ可能なフィルターを備えた柔軟なベクトルクエリ:
from redisvl . query import VectorQuery
query = VectorQuery (
vector = [ 0.16 , - 0.34 , 0.98 , 0.23 ],
vector_field_name = "embedding" ,
num_results = 3
)
# run the vector search query against the embedding field
results = index . query ( query )クエリに複雑なメタデータフィルターを組み込みます。
from redisvl . query . filter import Tag
# define a tag match filter
tag_filter = Tag ( "user" ) == "john"
# update query definition
query . set_filter ( tag_filter )
# execute query
results = index . query ( query )rangequery-カスタマイズ可能なフィルターとペアになった定義された範囲内のベクトル検索
FilterQuery-フィルターとフルテキスト検索を使用した標準検索
CountQuery-指定された属性のインデックス化されたレコードの数を数える
高度なRedisクエリの構築の詳細をご覧ください。
人気のある埋め込みプロバイダーと統合して、インデックスとクエリの非構造化データをベクトル化するプロセスを大幅に簡素化します。
from redisvl . utils . vectorize import CohereTextVectorizer
# set COHERE_API_KEY in your environment
co = CohereTextVectorizer ()
embedding = co . embed (
text = "What is the capital city of France?" ,
input_type = "search_query"
)
embeddings = co . embed_many (
texts = [ "my document chunk content" , "my other document chunk content" ],
input_type = "search_document"
)埋め込みワークフローでベクターを使用することの詳細をご覧ください。
Redisからの初期検索結果の関連性を改善するために、人気のある再ランキングプロバイダーと統合してください
RedisVL拡張機能のサポートを発表できることを嬉しく思います。これらのモジュールは、LLMメモリとエージェントを操作するためのベストプラクティスと設計パターンを公開するインターフェイスを実装しています。私たちは、ユーザー(それがあなた)と出血エッジの顧客から学んだことから最善を尽くし、それをパッケージ化しました。
別の拡張機能のアイデアがありますか? PRを開くか、[email protected]で私たちに連絡してください。私たちは常にフィードバックを受け入れています。
アプリケーションのスループットを増やし、以前に生成された知識をSemanticCacheで活用することにより、生産にLLMモデルを使用するコストを削減します。
from redisvl . extensions . llmcache import SemanticCache
# init cache with TTL and semantic distance threshold
llmcache = SemanticCache (
name = "llmcache" ,
ttl = 360 ,
redis_url = "redis://localhost:6379" ,
distance_threshold = 0.1
)
# store user queries and LLM responses in the semantic cache
llmcache . store (
prompt = "What is the capital city of France?" ,
response = "Paris"
)
# quickly check the cache with a slightly different prompt (before invoking an LLM)
response = llmcache . check ( prompt = "What is France's capital city?" )
print ( response [ 0 ][ "response" ]) >>> Paris
LLMSのセマンティックキャッシュの詳細をご覧ください。
ユーザーチャットの履歴をコンテキストとして提供することにより、LLM応答のパーソナライズと精度を向上させます。 SemanticSessionManagerによるベクトル検索を搭載したRemencyまたは関連性を使用して、セッションデータへのアクセスを管理します。
from redisvl . extensions . session_manager import SemanticSessionManager
session = SemanticSessionManager (
name = "my-session" ,
redis_url = "redis://localhost:6379" ,
distance_threshold = 0.7
)
session . add_messages ([
{ "role" : "user" , "content" : "hello, how are you?" },
{ "role" : "assistant" , "content" : "I'm doing fine, thanks." },
{ "role" : "user" , "content" : "what is the weather going to be today?" },
{ "role" : "assistant" , "content" : "I don't know" }
])最近のチャット履歴を入手:
session . get_recent ( top_k = 1 ) >>> [{"role": "assistant", "content": "I don't know"}]
関連するチャット履歴を取得します(ベクター検索を搭載):
session . get_relevant ( "weather" , top_k = 1 ) >>> [{"role": "user", "content": "what is the weather going to be today?"}]
LLMセッション管理の詳細をご覧ください。
Redisで直接実行される高速決定モデルを構築し、ユーザークエリを最も近い「ルート」または「トピック」にルーティングします。
from redisvl . extensions . router import Route , SemanticRouter
routes = [
Route (
name = "greeting" ,
references = [ "hello" , "hi" ],
metadata = { "type" : "greeting" },
distance_threshold = 0.3 ,
),
Route (
name = "farewell" ,
references = [ "bye" , "goodbye" ],
metadata = { "type" : "farewell" },
distance_threshold = 0.3 ,
),
]
# build semantic router from routes
router = SemanticRouter (
name = "topic-router" ,
routes = routes ,
redis_url = "redis://localhost:6379" ,
)
router ( "Hi, good morning" ) >>> RouteMatch(name='greeting', distance=0.273891836405)
セマンティックルーティングの詳細をご覧ください。
専用のCLIインターフェイスからRedisインデックス構成を作成、破壊、および管理するrvl 。
$ rvl -h
usage: rvl < command > [ < args > ]
Commands:
index Index manipulation (create, delete, etc.)
version Obtain the version of RedisVL
stats Obtain statistics about an indexCLIの使用についてもっと読んでください。
Genaiの時代には、 VectorデータベースとLLMが情報検索システムを変換しています。 LangchainやLlamaindexのような新興の人気のあるフレームワークにより、イノベーションは急速です。しかし、多くの組織は、AIソリューションを迅速かつ大規模に配信するという課題に直面しています。
NOSQLの世界の礎石であるRedisを入力します。その多用途のデータ構造と処理エンジンで有名です。 Redisは、キャッシュ、セッション管理、検索などのリアルタイムワークロードに優れています。また、RAGのベクトルデータベース、LLMキャッシュ、会話型AIのチャットセッションメモリストアとしての大国でもあります。
Redis Vector Libraryは、AI-Native Developer EcosystemとRedisの堅牢な機能のギャップを橋渡しします。軽量でエレガントで直感的なインターフェイスを備えたRedisVLにより、Redisのパワーを簡単に活用できます。 RedisPythonクライアントの上に構築されたredisvlは、Redisの機能を、今日のAI/MLエンジニアおよびデータサイエンティストのニーズと完全に整合した文法に変換します。
追加のヘルプについては、次のリソースを確認してください。
PRを寄付したり、バグや新機能のアイデアのためのGitHubの問題を開いたり、ドキュメントを改善したり、テストカバレッジを増やしたりして、お手伝いしてください。貢献方法の詳細を読んでください!
このプロジェクトは、誠実な努力に基づいてRedis、Incによってサポートされています。バグ、機能のリクエスト、または支援を受信するには、問題を提出してください。