Redis Vector 라이브러리 - Redis의 힘을 활용하는 AI 응용 프로그램을 위해 설계된 최고의 Python 클라이언트 인 Redis Vector 라이브러리에 오신 것을 환영합니다.
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:latestFree Redis Insight GUI로 경험과 관찰 가능성을 향상시킵니다.
내장 된 Redis 및 인덱스 가능한 필드 ( 예 : 텍스트, 태그, 숫자, 지리 및 벡터 )로 데이터 세트를 모델링하는 사용 사례에 대한 스키마를 설계하십시오. 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 ()비동기 호환 검색 인덱스 클래스도 사용할 수 있습니다 : 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- 주어진 지정된 레코드 수를 계산하십시오.
Advanced 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 메모리 및 에이전트로 작업하기위한 모범 사례 및 설계 패턴을 노출시키는 인터페이스를 구현합니다. 우리는 피가 졸업 한 고객뿐만 아니라 사용자 (That 's You)로부터 배운 내용에서 최선을 다하고 포장했습니다.
다른 확장에 대한 아이디어가 있습니까? 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
LLM의 시맨틱 캐싱에 대해 자세히 알아보십시오.
사용자 채팅 기록을 컨텍스트로 제공하여 LLM 응답의 개인화 및 정확성을 향상시킵니다. SemanticSessionManager 와 함께 벡터 검색으로 구동되는 Recency 또는 관련성을 사용하여 세션 데이터에 대한 액세스를 관리하십시오.
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에서 직접 실행되는 빠른 의사 결정 모델을 구축하고 가장 가까운 "경로"또는 "주제"로 ROPE 사용자 쿼리를 라우팅하십시오.
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)
시맨틱 라우팅에 대해 자세히 알아보십시오.
목적으로 rvl 된 CLI 인터페이스에서 REDIS 인덱스 구성을 생성, 파괴 및 관리합니다.
$ 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의 시대에 벡터 데이터베이스 및 LLM은 정보 검색 시스템을 변환하고 있습니다. Langchain 및 Llamaindex와 같은 신흥 및 인기있는 프레임 워크와 함께 혁신은 빠릅니다. 그러나 많은 조직이 AI 솔루션을 빠르고 규모 로 제공하는 데 어려움을 겪고 있습니다.
레 디스 (Redis)는 다재다능한 데이터 구조 및 처리 엔진으로 유명한 NOSQL 세계의 초석입니다. Redis는 캐싱, 세션 관리 및 검색과 같은 실시간 워크로드로 탁월합니다. 또한 RAG, LLM 캐시 및 대화식 AI의 채팅 세션 메모리 저장소의 벡터 데이터베이스로서의 강국이기도합니다.
Redis Vector Library는 Ai-Native 개발자 생태계와 Redis의 강력한 기능 사이의 격차를 해소합니다. 가볍고 우아하며 직관적 인 인터페이스를 통해 Redisvl은 Redis의 힘을 쉽게 활용할 수 있습니다. redisvl Redis Python 클라이언트를 기반으로 Redis의 기능을 오늘날의 AI/ML 엔지니어 및 데이터 과학자의 요구와 완벽하게 조정 된 문법으로 변환합니다.
추가 도움은 다음 리소스를 확인하십시오.
PR에 기여하거나 버그 또는 새로운 기능 아이디어에 대한 GitHub 문제를 열거나 문서화 개선 또는 테스트 범위 증가로 우리를 도와주십시오. 기여 방법에 대해 자세히 알아보십시오!
이 프로젝트는 Redis, Inc가 선의의 노력으로 지원합니다. 버그를보고, 기능을 요청하거나 지원을 받으려면 문제를 제출하십시오.