Skip to content

Commit 6835a45

Browse files
update readme and some doc strings
1 parent e0003c3 commit 6835a45

File tree

3 files changed

+143
-65
lines changed

3 files changed

+143
-65
lines changed

README.md

+141-62
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<h1 align="center">🔥 Redis Vector Library</h1>
1+
<div align="center" style="margin-bottom: 20px;">
2+
<div><img src="docs/_static/Redis_Logo_Red_RGB.svg" style="width: 200px; margin-bottom: 20px;"></div>
3+
<h1>🔥 Vector Library</h1>
4+
</div>
5+
6+
<div align="center" style="margin-top: 20px;">
7+
<span style="display: block; margin-bottom: 10px;">the *AI-native* Redis Python client</span>
8+
<br />
29

3-
<div align="center">
4-
<span style="font-size: smaller;">the AI-native Redis Python client</span>
5-
<br />
610

711
[![Codecov](https://img.shields.io/codecov/c/github/redis/redis-vl-python/dev?label=Codecov&logo=codecov&token=E30WxqBeJJ)](https://codecov.io/gh/redis/redis-vl-python)
812
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -18,33 +22,33 @@
1822
<div display="inline-block">
1923
<a href="https://github.com/redis/redis-vl-python"><b>Home</b></a>&nbsp;&nbsp;&nbsp;
2024
<a href="https://www.redisvl.com"><b>Documentation</b></a>&nbsp;&nbsp;&nbsp;
21-
<a href="https://github.com/redis-developer"><b>More Projects</b></a>&nbsp;&nbsp;&nbsp;
25+
<a href="https://github.com/redis-developer/redis-ai-resources"><b>Recipes</b></a>&nbsp;&nbsp;&nbsp;
2226
</div>
2327
<br />
2428
</div>
2529

2630

2731
# Introduction
2832

29-
The Python Redis Vector Library (RedisVL) is a tailor-made client for AI applications leveraging [Redis](https://redis.com).
33+
Welcome to the Redis Vector Library (`redisvl`) – the ultimate Python client designed for AI applications harnessing the power of [Redis](https://redis.io).
3034

31-
It's specifically designed for:
35+
`redisvl` is your go-to tool for:
3236

33-
- Information retrieval & vector similarity search
37+
- Lightning-fast information retrieval & vector similarity search
3438
- Real-time RAG pipelines
35-
- Recommendation engines
39+
- Agentic memory structures
40+
- Smart recommendation engines
3641

37-
Enhance your applications with Redis' **speed**, **flexibility**, and **reliability**, incorporating capabilities like vector-based semantic search, full-text search, and geo-spatial search.
42+
## 🚀 Why RedisVL?
3843

39-
# 🚀 Why RedisVL?
44+
In the age of GenAI, **vector databases** and **LLMs** are transforming information retrieval systems. With emerging and popular frameworks like [LangChain](https://github.com/langchain-ai/langchain) and [LlamaIndex](https://www.llamaindex.ai/), innovation is soaring. Yet, many organizations face the challenge of delivering AI solutions **quickly** and at **scale**.
4045

41-
The emergence of the modern GenAI stack, including **vector databases** and **LLMs**, has become increasingly popular due to accelerated innovation & research in information retrieval, the ubiquity of tools & frameworks (e.g. [LangChain](https://github.com/langchain-ai/langchain), [LlamaIndex](https://www.llamaindex.ai/), [EmbedChain](https://github.com/embedchain/embedchain)), and the never-ending stream of business problems addressable by AI.
46+
Enter [Redis](https://redis.io) – a cornerstone of the NoSQL world, renowned for its versatile [data structures](https://redis.io/docs/data-types/) and [processing engines](https://redis.io/docs/interact/). Redis excels in real-time workloads like caching, session management, and search. It's also a powerhouse as a vector database for RAG, an LLM cache, and a chat session memory store for conversational AI.
4247

43-
However, organizations still struggle with delivering reliable solutions **quickly** (*time to value*) at **scale** (*beyond a demo*).
48+
The Redis Vector Library bridges the gap between the AI-native developer ecosystem and Redis's robust capabilities. With a lightweight, elegant, and intuitive interface, RedisVL makes it easy to leverage Redis's power. Built on the [Redis Python](https://github.com/redis/redis-py/tree/master) client, `redisvl` transforms Redis's features into a grammar perfectly aligned with the needs of today's AI/ML Engineers and Data Scientists.
4449

45-
[Redis](https://redis.io) has been a staple for over a decade in the NoSQL world, and boasts a number of flexible [data structures](https://redis.io/docs/data-types/) and [processing engines](https://redis.io/docs/interact/) to handle realtime application workloads like caching, session management, and search. Most notably, Redis has been used as a vector database for RAG, as an LLM cache, and chat session memory store for conversational AI applications.
50+
Unleash the full potential of Redis for your AI projects with `redisvl`.
4651

47-
The vector library **bridges the gap between** the emerging AI-native developer ecosystem and the capabilities of Redis by providing a lightweight, elegant, and intuitive interface. Built on the back of the popular Python client, [`redis-py`](https://github.com/redis/redis-py/tree/master), it abstracts the features Redis into a grammar that is more aligned to the needs of today's AI/ML Engineers or Data Scientists.
4852

4953
# 💪 Getting Started
5054

@@ -62,24 +66,24 @@ pip install redisvl
6266
Choose from multiple Redis deployment options:
6367

6468

65-
1. [Redis Cloud](https://redis.com/try-free): Managed cloud database (free tier available)
69+
1. [Redis Cloud](https://redis.io/try-free): Managed cloud database (free tier available)
6670
2. [Redis Stack](https://redis.io/docs/getting-started/install-stack/docker/): Docker image for development
6771
```bash
6872
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
6973
```
70-
3. [Redis Enterprise](https://redis.com/redis-enterprise/): Commercial, self-hosted database
74+
3. [Redis Enterprise](https://redis.io/enterprise/): Commercial, self-hosted database
7175
4. [Azure Cache for Redis Enterprise](https://learn.microsoft.com/azure/azure-cache-for-redis/quickstart-create-redis-enterprise): Fully managed Redis Enterprise on Azure
7276

7377
> Enhance your experience and observability with the free [Redis Insight GUI](https://redis.com/redis-enterprise/redis-insight/).
7478

7579

76-
## What's included?
80+
# Overview
7781

7882

79-
### 🗃️ Redis Index Management
83+
## 🗃️ Redis Index Management
8084
1. [Design an `IndexSchema`](https://www.redisvl.com/user_guide/getting_started_01.html#define-an-indexschema) that models your dataset with built-in Redis [data structures](https://www.redisvl.com/user_guide/hash_vs_json_05.html) (*Hash or JSON*) and indexable fields (*e.g. text, tags, numerics, geo, and vectors*).
8185

82-
[Load a schema](https://www.redisvl.com/user_guide/getting_started_01.html#example-schema-creation) from a [YAML file](schemas/schema.yaml):
86+
[Load a schema](https://www.redisvl.com/user_guide/getting_started_01.html#example-schema-creation) from a YAML file:
8387
```yaml
8488
index:
8589
name: user-index-v1
@@ -155,7 +159,7 @@ and [fetch](https://www.redisvl.com/user_guide/getting_started_01.html#fetch-an-
155159
john = index.fetch("john")
156160
```
157161

158-
### 🔍 Realtime Search
162+
## 🔍 Realtime Search
159163

160164
Define queries and perform advanced searches over your indices, including the combination of vectors, metadata filters, and more.
161165

@@ -191,10 +195,10 @@ Define queries and perform advanced searches over your indices, including the co
191195
- [FilterQuery](https://www.redisvl.com/api/query.html#filterquery) - Standard search using filters and the full-text search
192196
- [CountQuery](https://www.redisvl.com/api/query.html#countquery) - Count the number of indexed records given attributes
193197

194-
> Read more about building advanced Redis queries [here](https://www.redisvl.com/user_guide/hybrid_queries_02.html).
198+
> Read more about building [advanced Redis queries](https://www.redisvl.com/user_guide/hybrid_queries_02.html).
195199

196200

197-
### 🖥️ Command Line Interface
201+
## 🖥️ Command Line Interface
198202
Create, destroy, and manage Redis index configurations from a purpose-built CLI interface: `rvl`.
199203

200204
```bash
@@ -208,15 +212,19 @@ Commands:
208212
stats Obtain statistics about an index
209213
```
210214

211-
> Read more about using the `redisvl` CLI [here](https://www.redisvl.com/user_guide/cli.html).
215+
> Read more about using the `redisvl` [CLI](https://www.redisvl.com/user_guide/cli.html).
216+
217+
## 🔧 Utilities
212218

213-
### ⚡ Community Integrations
214-
Integrate with popular embedding models and providers to greatly simplify the process of vectorizing unstructured data for your index and queries:
215-
- [Cohere](https://www.redisvl.com/api/vectorizer/html#coheretextvectorizer)
219+
### Vectorizers
220+
Integrate with popular embedding providers to greatly simplify the process of vectorizing unstructured data for your index and queries:
221+
- [AzureOpenAI](https://www.redisvl.com/api/vectorizer.html#azureopenaitextvectorizer)
222+
- [Cohere](https://www.redisvl.com/api/vectorizer.html#coheretextvectorizer)
223+
- [Custom](https://www.redisvl.com/api/vectorizer.html#customtextvectorizer)
224+
- [GCP VertexAI](https://www.redisvl.com/api/vectorizer.html#vertexaitextvectorizer)
225+
- [HuggingFace](https://www.redisvl.com/api/vectorizer.html#hftextvectorizer)
216226
- [Mistral](https://www.redisvl.com/api/vectorizer/html#mistralaitextvectorizer)
217227
- [OpenAI](https://www.redisvl.com/api/vectorizer.html#openaitextvectorizer)
218-
- [HuggingFace](https://www.redisvl.com/api/vectorizer.html#hftextvectorizer)
219-
- [GCP VertexAI](https://www.redisvl.com/api/vectorizer.html#vertexaitextvectorizer)
220228

221229
```python
222230
from redisvl.utils.vectorize import CohereTextVectorizer
@@ -235,53 +243,124 @@ embeddings = co.embed_many(
235243
)
236244
```
237245

238-
> Learn more about using `redisvl` Vectorizers in your workflows [here](https://www.redisvl.com/user_guide/vectorizers_04.html).
246+
> Learn more about using `redisvl` [vectorizers]((https://www.redisvl.com/user_guide/vectorizers_04.html)) in your embedding workflows.
239247

240-
### 💫 Beyond Vector Search
241-
In order to perform well in production, modern GenAI applications require much more than vector search for retrieval. `redisvl` provides some common extensions that
242-
aim to improve applications working with LLMs:
243248

244-
- **LLM Semantic Caching** is designed to increase application throughput and reduce the cost of using LLM models in production by leveraging previously generated knowledge.
249+
### Rerankers
250+
Integrate with popular reranking providers to improve the relevancy of the initial search results from Redis:
245251

246-
```python
247-
from redisvl.extensions.llmcache import SemanticCache
248252

249-
# init cache with TTL (expiration) policy and semantic distance threshhold
250-
llmcache = SemanticCache(
251-
name="llmcache",
252-
ttl=360,
253-
redis_url="redis://localhost:6379"
254-
)
255-
llmcache.set_threshold(0.2) # can be changed on-demand
256253

257-
# store user queries and LLM responses in the semantic cache
258-
llmcache.store(
259-
prompt="What is the capital city of France?",
260-
response="Paris",
261-
metadata={}
262-
)
254+
## 💫 Extensions
255+
To improve production performance in GenAI applications, `redisvl` provides some common extensions:
263256

264-
# quickly check the cache with a slightly different prompt (before invoking an LLM)
265-
response = llmcache.check(prompt="What is France's capital city?")
266-
print(response[0]["response"])
267-
```
268-
```stdout
269-
>>> "Paris"
270-
```
257+
### LLM Semantic Caching
258+
Increase application throughput and reduce the cost of using LLM models in production by leveraging previously generated knowledge with the [`SemanticCache`](https://www.redisvl.com/api/cache.html#semanticcache).
259+
260+
```python
261+
from redisvl.extensions.llmcache import SemanticCache
262+
263+
# init cache with TTL and semantic distance threshold
264+
llmcache = SemanticCache(
265+
name="llmcache",
266+
ttl=360,
267+
redis_url="redis://localhost:6379",
268+
distance_threshold=0.1
269+
)
270+
271+
# store user queries and LLM responses in the semantic cache
272+
llmcache.store(
273+
prompt="What is the capital city of France?",
274+
response="Paris",
275+
metadata={}
276+
)
277+
278+
# quickly check the cache with a slightly different prompt (before invoking an LLM)
279+
response = llmcache.check(prompt="What is France's capital city?")
280+
print(response[0]["response"])
281+
```
282+
```stdout
283+
>>> "Paris"
284+
```
271285

272-
> Learn more about Semantic Caching [here](https://www.redisvl.com/user_guide/llmcache_03.html).
286+
> Learn more about [semantic caching]((https://www.redisvl.com/user_guide/llmcache_03.html)) for LLMs with `redisvl`.
273287

274-
- **LLM Session Management (COMING SOON)** aims to improve personalization and accuracy of the LLM application by providing user chat session information and conversational memory.
275-
- **LLM Contextual Access Control (COMING SOON)** aims to improve security concerns by preventing malicious, irrelevant, or problematic user input from reaching LLMs and infrastructure.
288+
### LLM Session Management
276289

290+
Improve personalization and accuracy of LLM responses by providing user chat history as context. Manage access to the session data using recency or relevancy, *powered by vector search* with the [`SemanticSessionManager`]().
291+
292+
```python
293+
from redisvl.extensions.session_manager import SemanticSessionManager
294+
295+
session = SemanticSessionManager(
296+
name="my-session",
297+
redis_url="redis://localhost:6379"
298+
)
299+
300+
session.add_messages([
301+
{"role": "user", "content": "hello, how are you?"},
302+
{"role": "assistant", "content": "I'm doing fine, thanks."},
303+
{"role": "user", "content": "what is the weather going to be today?"},
304+
{"role": "assistant", "content": "I don't know"}
305+
])
306+
```
307+
```python
308+
session.get_recent(top_k=1)
309+
```
310+
```stdout
311+
>>> {"role": "assistant", "content": "I don't know"}
312+
```
313+
```python
314+
session.get_relevant("weather", top_k=1)
315+
```
316+
```stdout
317+
>>> {"role": "user", "content": "what is the weather going to be today?"}
318+
```
319+
> Learn more about [LLM session management]((https://www.redisvl.com/user_guide/session_manager_07.html)) with `redisvl`.
320+
321+
322+
### LLM Semantic Routing
323+
Build fast decision models that run directly in Redis and route user queries to the nearest "route" or "topic".
324+
325+
```python
326+
routes = [
327+
Route(
328+
name="greeting",
329+
references=["hello", "hi"],
330+
metadata={"type": "greeting"},
331+
distance_threshold=0.3,
332+
)
333+
Route(
334+
name="farewell",
335+
references=["bye", "goodbye"],
336+
metadata={"type": "farewell"},
337+
distance_threshold=0.3,
338+
),
339+
]
340+
341+
# build semantic router from routes
342+
router = SemanticRouter(
343+
name="topic-router",
344+
routes=routes,
345+
redis_url="redis://localhost:6379",
346+
)
347+
348+
349+
router("Hi, good morning")
350+
```
351+
```stdout
352+
>>> RouteMatch(name='greeting', distance=0.09384023)
353+
```
354+
> Learn more about [semantic routing](https://www.redisvl.com/user_guide/semantic_router_08.html) in `redisvl`.
277355

278-
## Helpful Links
356+
## 😁 Helpful Links
279357

280-
To get started, check out the following guides:
358+
For additional help, check out the following resources:
281359
- [Getting Started Guide](https://www.redisvl.com/user_guide/getting_started_01.html)
282360
- [API Reference](https://www.redisvl.com/api/index.html)
283361
- [Example Gallery](https://www.redisvl.com/examples/index.html)
284-
- [Official Redis Vector Search Docs](https://redis.io/docs/interact/search-and-query/advanced-concepts/vectors/)
362+
- [Redis AI Recipes](https://github.com/redis-developer/redis-ai-resources)
363+
- [Official Redis Vector API Docs](https://redis.io/docs/interact/search-and-query/advanced-concepts/vectors/)
285364

286365

287366
## 🫱🏼‍🫲🏽 Contributing

redisvl/extensions/session_manager/semantic_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def get_relevant(
198198
as_text (bool): Whether to return the prompts and responses as text
199199
or as JSON
200200
top_k (int): The number of previous messages to return. Default is 5.
201-
fallback (bool): Whether to drop back to recent conversation history
201+
fall_back (bool): Whether to drop back to recent conversation history
202202
if no relevant context is found.
203203
session_tag (str): Tag of entries linked to a specific session.
204204
user_tag (str): Tag of entries linked to a specific user.

redisvl/utils/vectorize/text/custom.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(
4444
embed_many: Optional[Callable] = None,
4545
aembed: Optional[Callable] = None,
4646
aembed_many: Optional[Callable] = None,
47-
model: str = "custom_vectorizer",
4847
):
4948
"""Initialize the Custom vectorizer.
5049
@@ -72,7 +71,7 @@ def __init__(
7271
self._validate_aembed_many(aembed_many)
7372
self._aembed_many_func = aembed_many
7473

75-
super().__init__(model=model, dims=self._set_model_dims())
74+
super().__init__(model=self.type, dims=self._set_model_dims())
7675

7776
def _validate_embed(self, func: Callable):
7877
"""calls the func with dummy input and validates that it returns a vector"""

0 commit comments

Comments
 (0)