Skip to content

Commit 0f9ef9e

Browse files
add text embeddings module
1 parent 4c84ed4 commit 0f9ef9e

File tree

18 files changed

+122
-125
lines changed

18 files changed

+122
-125
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
echo REDIS_ADDRESS=$REDIS_ADDRESS >> $GITHUB_ENV
3838
- name: Run tests
3939
env:
40-
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
40+
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
4141
run: |
4242
make test-cov
4343
- name: Publish coverage results

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ RedisVL has a host of powerful features designed to streamline your vector datab
4242

4343
1. **Index Management**: RedisVL allows for indices to be created, updated, and deleted with ease. A schema for each index can be defined in yaml or directly in python code and used throughout the lifetime of the index.
4444

45-
2. **Vector Creation**: RedisVL integrates with OpenAI and other embedding providers to make the process of creating vectors straightforward.
45+
2. **Embedding Creation**: RedisVL integrates with OpenAI and other text embedding providers to simplify the process of vectorizing unstructured data. *Image support coming soon.*
4646

4747
3. **Vector Search**: RedisVL provides robust search capabilities that enable you to query vectors synchronously and asynchronously. Hybrid queries that utilize tag, geographic, numeric, and other filters like full-text search are also supported.
4848

49-
4. **Semantic Caching**: ``LLMCache`` is a semantic caching interface built directly into RedisVL. It allows for the caching of generated output from LLM models like GPT-3 and others. As semantic search is used to check the cache, a threshold can be set to determine if the cached result is relevant enough to be returned. If not, the model is called and the result is cached for future use. This can increase the QPS and reduce the cost of using LLM models.
49+
4. **Powerful Abstractions**
50+
- **Semantic Caching**: `LLMCache` is a semantic caching interface built directly into RedisVL. It allows for the caching of generated output from LLMs like GPT-3 and others. As semantic search is used to check the cache, a threshold can be set to determine if the cached result is relevant enough to be returned. If not, the model is called and the result is cached for future use. This can increase the QPS and reduce the cost of using LLM models in production.
5051

5152

5253
## 😊 Quick Start
@@ -125,6 +126,7 @@ The ``LLMCache`` Interface in RedisVL can be used as follows.
125126

126127
```python
127128
from redisvl.llmcache.semantic import SemanticCache
129+
128130
cache = SemanticCache(
129131
redis_url="redis://localhost:6379",
130132
threshold=0.9, # semantic similarity threshold

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def client():
2323

2424
@pytest.fixture
2525
def openai_key():
26-
return os.getenv("OPENAI_KEY")
26+
return os.getenv("OPENAI_API_KEY")
2727

2828

2929
@pytest.fixture(scope="session")

docs/examples/openai_qna.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
"source": [
505505
"### Embedding Creation\n",
506506
"\n",
507-
"With the text broken up into chunks, we can create embedding with the RedisVL OpenAIProvider. This provider uses the OpenAI API to create embeddings for the text. The code below shows how to create embeddings for the text chunks."
507+
"With the text broken up into chunks, we can create embeddings with the RedisVL `OpenAITextVectorizer`. This provider uses the OpenAI API to create embeddings for the text. The code below shows how to create embeddings for the text chunks."
508508
]
509509
},
510510
{
@@ -709,11 +709,11 @@
709709
],
710710
"source": [
711711
"import os\n",
712-
"from redisvl.providers.openai import OpenAIProvider\n",
712+
"from redisvl.vectorize.text import OpenAITextVectorizer\n",
713713
"from redisvl.utils.utils import array_to_buffer\n",
714714
"\n",
715715
"api_key = os.environ.get(\"OPENAI_API_KEY\", \"\")\n",
716-
"oaip = OpenAIProvider(EMBEDDINGS_MODEL, api_config={\"api_key\": api_key})\n",
716+
"oaip = OpenAITextVectorizer(EMBEDDINGS_MODEL, api_config={\"api_key\": api_key})\n",
717717
"\n",
718718
"chunked_data[\"embedding\"] = oaip.embed_many(chunked_data[\"content\"].tolist())\n",
719719
"chunked_data[\"embedding\"] = chunked_data[\"embedding\"].apply(lambda x: array_to_buffer(x))\n",

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ to supercharge your application!
2121
- header: "{fas}`bolt;pst-color-primary` Vector Search"
2222
content: "Simple vector search capabilities supporting synchronous and asyncronous search."
2323
- header: "{fas}`circle-half-stroke;pst-color-primary` Embedding Creation"
24-
content: "User OpenAI or any of the other embedding providers to create embeddings"
24+
content: "User OpenAI or any of the other supported vectorizers to create embeddings"
2525
- header: "{fas}`palette;pst-color-primary` CLI"
2626
content: "Command line interface for RedisVL makes interacting with Redis as a vector database easy."
2727
- header: "{fab}`python;pst-color-primary` Semantic Caching"

docs/user_guide/embedding_creation.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
Embedding Providers
55
===================
66

7-
RedisVL enables you to call out to embedding providers
7+
RedisVL enables you to vectorize unstructured data by calling out to embedding providers:
88

99

1010
OpenAI
1111
======
1212

13-
OpenAI is a commercial service that provides access to a number of models
13+
[OpenAI](https://platform.openai.com) is a commercial service that provides access to a number of models.
1414

1515

1616
HuggingFace
1717
===========
1818

19-
HuggingFace is a commercial service that provides access to a number of models
19+
[HuggingFace](https://huggingface.co) is a commercial service that provides access to a number of models.
2020

21-
22-
Cohere
23-
======
24-
25-
Cohere is a commercial service that provides access to a number of models

docs/user_guide/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ hybrid_queries_02
1717
```
1818

1919
```{toctree}
20-
:caption: Providers
20+
:caption: Vectorizers
2121
:maxdepth: 3
2222
23-
providers_03
23+
vectorizers_03
2424
```
2525

2626
```{toctree}

docs/user_guide/providers_03.ipynb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"cell_type": "markdown",
66
"metadata": {},
77
"source": [
8-
"# Embedding Providers\n",
8+
"# Vectorizers\n",
99
"\n",
10-
"In this notebook, we will show how to use RedisVL to create embeddings using the built-in Providers. Today RedisVL supports:\n",
10+
"In this notebook, we will show how to use RedisVL to create embeddings using the built-in text embedding vectorizers. Today RedisVL supports:\n",
1111
"1. OpenAI\n",
1212
"2. HuggingFace\n",
1313
"\n",
@@ -33,7 +33,7 @@
3333
"source": [
3434
"## Creating Embeddings\n",
3535
"\n",
36-
"This example will show how to create an embedding from 3 simple sentences with a number of different providers\n",
36+
"This example will show how to create an embedding from 3 simple sentences with a number of different vectorizers\n",
3737
"\n",
3838
"- \"That is a happy dog\"\n",
3939
"- \"That is a happy person\"\n",
@@ -80,11 +80,11 @@
8080
],
8181
"source": [
8282
"os.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\"\n",
83-
"from redisvl.providers import HuggingfaceProvider\n",
83+
"from redisvl.vectorize.text import HFTextVectorizer\n",
8484
"\n",
8585
"\n",
8686
"# create a provider\n",
87-
"hf = HuggingfaceProvider(model=\"sentence-transformers/all-mpnet-base-v2\")\n",
87+
"hf = HFTextVectorizer(model=\"sentence-transformers/all-mpnet-base-v2\")\n",
8888
"\n",
8989
"# embed a sentence\n",
9090
"test = hf.embed(\"This is a test sentence.\")\n",
@@ -118,7 +118,7 @@
118118
"\n",
119119
"First, we need to create the schema for our index.\n",
120120
"\n",
121-
"Here's what the schema for the example looks like in yaml for the HuggingFace Provider\n",
121+
"Here's what the schema for the example looks like in yaml for the HuggingFace vectorizer:\n",
122122
"\n",
123123
"```yaml\n",
124124
"index:\n",
@@ -211,7 +211,7 @@
211211
"source": [
212212
"from redisvl.query import VectorQuery\n",
213213
"\n",
214-
"# use the HuggingFace Provider again to create a query embedding\n",
214+
"# use the HuggingFace vectorizer again to create a query embedding\n",
215215
"query_embedding = hf.embed(\"That is a happy cat\")\n",
216216
"\n",
217217
"query = VectorQuery(\n",
@@ -226,13 +226,6 @@
226226
" print(doc.text)\n",
227227
" print(doc.vector_distance)"
228228
]
229-
},
230-
{
231-
"cell_type": "code",
232-
"execution_count": null,
233-
"metadata": {},
234-
"outputs": [],
235-
"source": []
236229
}
237230
],
238231
"metadata": {

redisvl/llmcache/semantic.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from redisvl.index import SearchIndex
66
from redisvl.llmcache.base import BaseLLMCache
7-
from redisvl.providers import HuggingfaceProvider
8-
from redisvl.providers.base import BaseProvider
7+
from redisvl.vectorize.text import HFTextVectorizer
8+
from redisvl.vectorize.base import BaseVectorizer
99
from redisvl.query import VectorQuery
1010
from redisvl.utils.utils import array_to_buffer
1111

@@ -28,7 +28,7 @@ def __init__(
2828
prefix: str = "llmcache",
2929
threshold: float = 0.9,
3030
ttl: Optional[int] = None,
31-
provider: Optional[BaseProvider] = HuggingfaceProvider(
31+
vectorizer: Optional[BaseVectorizer] = HFTextVectorizer(
3232
"sentence-transformers/all-mpnet-base-v2"
3333
),
3434
redis_url: Optional[str] = "redis://localhost:6379",
@@ -41,8 +41,8 @@ def __init__(
4141
prefix (str, optional): The prefix for the index. Defaults to "llmcache".
4242
threshold (float, optional): Semantic threshold for the cache. Defaults to 0.9.
4343
ttl (Optional[int], optional): The TTL for the cache. Defaults to None.
44-
provider (Optional[BaseProvider], optional): The provider for the cache.
45-
Defaults to HuggingfaceProvider("sentence-transformers/all-mpnet-base-v2").
44+
vectorizer (Optional[BaseVectorizer], optional): The vectorizer for the cache.
45+
Defaults to HFTextVectorizer("sentence-transformers/all-mpnet-base-v2").
4646
redis_url (Optional[str], optional): The redis url. Defaults to "redis://localhost:6379".
4747
connection_args (Optional[dict], optional): The connection arguments for the redis client. Defaults to None.
4848
@@ -51,7 +51,7 @@ def __init__(
5151
5252
"""
5353
self._ttl = ttl
54-
self._provider = provider
54+
self._vectorizer = vectorizer
5555
self.set_threshold(threshold)
5656

5757
index = SearchIndex(name=index_name, prefix=prefix, fields=self._default_fields)
@@ -150,7 +150,7 @@ def check(
150150
raise ValueError("Either prompt or vector must be specified.")
151151

152152
if not vector:
153-
vector = self._provider.embed(prompt) # type: ignore
153+
vector = self._vectorizer.embed(prompt) # type: ignore
154154

155155
v = VectorQuery(
156156
vector=vector,
@@ -195,7 +195,7 @@ def store(
195195
key = self.hash_input(prompt)
196196

197197
if not vector:
198-
vector = self._provider.embed(prompt) # type: ignore
198+
vector = self._vectorizer.embed(prompt) # type: ignore
199199

200200
payload = {
201201
"id": key,

redisvl/providers/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)