Selamat datang di Perpustakaan Vektor Redis - Klien Python terbaik yang dirancang untuk aplikasi AI yang memanfaatkan kekuatan Redis.
Redisvl adalah alat masuk Anda untuk:
Install redisvl into your Python (>=3.8) environment using pip :
pip install redisvlUntuk instruksi yang lebih rinci, kunjungi Panduan Instalasi.
Pilih dari beberapa opsi penyebaran Redis:
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latestTingkatkan pengalaman dan pengamatan Anda dengan GUI Redis Insight gratis.
Design a schema for your use case that models your dataset with built-in Redis and indexable fields ( eg text, tags, numerics, geo, and vectors ). Muat skema dari file 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" )Atau memuat langsung dari kamus 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"
}
}
]
})Buat kelas SearchIndex dengan skema input dan koneksi klien untuk melakukan admin dan operasi pencarian pada indeks Anda di redis:
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 ()Kelas Indeks Pencarian Pencarian Async juga tersedia: AsyncsearchIndex.
Memuat dan mengambil data ke/dari instance Redis Anda:
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" )Tentukan pertanyaan dan lakukan pencarian lanjutan atas indeks Anda, termasuk kombinasi vektor, filter metadata, dan banyak lagi.
VectorQuery - Permintaan vektor fleksibel dengan filter yang dapat disesuaikan yang memungkinkan pencarian semantik:
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 )Menggabungkan filter metadata yang kompleks pada pertanyaan Anda:
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 - Pencarian vektor dalam kisaran yang ditentukan dipasangkan dengan filter yang dapat disesuaikan
FilterQuery - Pencarian Standar Menggunakan Filter dan Pencarian Teks Lengkap
CountQuery - Hitung jumlah catatan yang diindeks yang diberikan atribut
Baca lebih lanjut tentang membangun kueri Redis canggih.
Integrasi dengan penyedia embedding populer untuk sangat menyederhanakan proses vektorisasi data yang tidak terstruktur untuk indeks dan kueri Anda:
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"
)Pelajari lebih lanjut tentang menggunakan vektoris dalam alur kerja penyembatan Anda.
Integrasi dengan penyedia reranking populer untuk meningkatkan relevansi hasil pencarian awal dari Redis
We're excited to announce the support for RedisVL Extensions . Modul -modul ini menerapkan antarmuka yang memperlihatkan praktik terbaik dan pola desain untuk bekerja dengan memori dan agen LLM. Kami telah mengambil yang terbaik dari apa yang telah kami pelajari dari pengguna kami (itu Anda) serta pelanggan pendarahan, dan mengemasnya.
Punya ide untuk ekstensi lain? Buka PR atau hubungi kami di [email protected]. Kami selalu terbuka untuk umpan balik.
Increase application throughput and reduce the cost of using LLM models in production by leveraging previously generated knowledge with the SemanticCache .
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
Pelajari lebih lanjut tentang caching semantik untuk LLMS.
Tingkatkan personalisasi dan keakuratan tanggapan LLM dengan memberikan riwayat obrolan pengguna sebagai konteks. Manage access to the session data using recency or relevancy, powered by vector search with the SemanticSessionManager .
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" }
])Dapatkan riwayat obrolan terbaru:
session . get_recent ( top_k = 1 ) >>> [{"role": "assistant", "content": "I don't know"}]
Dapatkan riwayat obrolan yang relevan (didukung oleh pencarian vektor):
session . get_relevant ( "weather" , top_k = 1 ) >>> [{"role": "user", "content": "what is the weather going to be today?"}]
Pelajari lebih lanjut tentang manajemen sesi LLM.
Bangun model keputusan cepat yang berjalan langsung di Redis dan rute kueri pengguna ke "rute" atau "topik" terdekat.
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)
Pelajari lebih lanjut tentang routing semantik.
Create, destroy, and manage Redis index configurations from a purpose-built CLI interface: 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 indexBaca lebih lanjut tentang menggunakan CLI.
In the age of GenAI, vector databases and LLMs are transforming information retrieval systems. Dengan kerangka kerja yang muncul dan populer seperti Langchain dan Llamaindex, inovasi cepat. Yet, many organizations face the challenge of delivering AI solutions quickly and at scale .
Masukkan Redis - landasan dunia NoSQL, yang terkenal dengan struktur data serbaguna dan mesin pemrosesan. Redis unggul dalam beban kerja real-time seperti caching, manajemen sesi, dan pencarian. Ini juga merupakan pembangkit tenaga listrik sebagai database vektor untuk RAG, cache LLM, dan toko memori sesi obrolan untuk percakapan AI.
Perpustakaan Redis Vector menjembatani kesenjangan antara ekosistem pengembang asli AI dan kemampuan Redis yang kuat. Dengan antarmuka yang ringan, elegan, dan intuitif, RedisVL memudahkan untuk memanfaatkan kekuatan Redis. Built on the Redis Python client, redisvl transforms Redis's features into a grammar perfectly aligned with the needs of today's AI/ML Engineers and Data Scientists.
Untuk bantuan tambahan, lihat sumber daya berikut:
Tolong bantu kami dengan menyumbangkan PRS, membuka masalah gitub untuk bug atau ide -ide fitur baru, meningkatkan dokumentasi, atau meningkatkan cakupan tes. Baca lebih lanjut tentang cara berkontribusi!
Proyek ini didukung oleh Redis, Inc berdasarkan upaya itikad baik. Untuk melaporkan bug, meminta fitur, atau menerima bantuan, silakan mengajukan masalah.