Skip to content

Commit dc74788

Browse files
Add MistralAI text vectorizer (#169)
As requested in [issue 160](#160)
1 parent 4425437 commit dc74788

File tree

9 files changed

+397
-6
lines changed

9 files changed

+397
-6
lines changed

.github/workflows/run_tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
6262
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
6363
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
64+
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
6465
AZURE_OPENAI_API_KEY: ${{secrets.AZURE_OPENAI_API_KEY}}
6566
AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}
6667
AZURE_OPENAI_DEPLOYMENT_NAME: ${{secrets.AZURE_OPENAI_DEPLOYMENT_NAME}}
@@ -80,6 +81,7 @@ jobs:
8081
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
8182
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
8283
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
84+
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
8385
AZURE_OPENAI_API_KEY: ${{secrets.AZURE_OPENAI_API_KEY}}
8486
AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}
8587
AZURE_OPENAI_DEPLOYMENT_NAME: ${{secrets.AZURE_OPENAI_DEPLOYMENT_NAME}}
@@ -92,4 +94,4 @@ jobs:
9294
with:
9395
token: ${{ secrets.CODECOV_TOKEN }}
9496
files: ./coverage.xml
95-
fail_ci_if_error: false
97+
fail_ci_if_error: false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ Commands:
213213
### ⚡ Community Integrations
214214
Integrate with popular embedding models and providers to greatly simplify the process of vectorizing unstructured data for your index and queries:
215215
- [Cohere](https://www.redisvl.com/api/vectorizer/html#coheretextvectorizer)
216+
- [Mistral](https://www.redisvl.com/api/vectorizer/html#mistralaitextvectorizer)
216217
- [OpenAI](https://www.redisvl.com/api/vectorizer.html#openaitextvectorizer)
217218
- [HuggingFace](https://www.redisvl.com/api/vectorizer.html#hftextvectorizer)
218219
- [GCP VertexAI](https://www.redisvl.com/api/vectorizer.html#vertexaitextvectorizer)

conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def azure_endpoint():
5959
def cohere_key():
6060
return os.getenv("COHERE_API_KEY")
6161

62+
@pytest.fixture
63+
def mistral_key():
64+
return os.getenv("MISTRAL_API_KEY")
65+
6266
@pytest.fixture
6367
def gcp_location():
6468
return os.getenv("GCP_LOCATION")
@@ -133,4 +137,4 @@ def sample_data():
133137
def clear_db(redis):
134138
redis.flushall()
135139
yield
136-
redis.flushall()
140+
redis.flushall()

docs/user_guide/vectorizers_04.ipynb

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"2. HuggingFace\n",
1313
"3. Vertex AI\n",
1414
"4. Cohere\n",
15+
"5. Mistral AI\n",
1516
"\n",
1617
"Before running this notebook, be sure to\n",
1718
"1. Have installed ``redisvl`` and have that environment active for this notebook.\n",
@@ -500,6 +501,44 @@
500501
"Learn more about using RedisVL and Cohere together through [this dedicated user guide](https://docs.cohere.com/docs/redis-and-cohere)."
501502
]
502503
},
504+
{
505+
"cell_type": "markdown",
506+
"metadata": {},
507+
"source": [
508+
"## Mistral AI\n",
509+
"\n",
510+
"[Mistral](https://console.mistral.ai/) offers LLM and embedding APIs you to implement into your product. The `MistralAITextVectorizer` makes it simple to use RedisVL with their embeddings model. You will need to install `mistralai`.\n",
511+
"\n",
512+
"```bash\n",
513+
"pip install mistralai\n",
514+
"```"
515+
]
516+
},
517+
{
518+
"cell_type": "code",
519+
"execution_count": 7,
520+
"metadata": {},
521+
"outputs": [
522+
{
523+
"name": "stdout",
524+
"output_type": "stream",
525+
"text": [
526+
"vector dimensions: 1024\n",
527+
"[-0.02801513671875, 0.02532958984375, 0.04278564453125, 0.0185699462890625, 0.041015625, 0.006053924560546875, 0.03607177734375, -0.0030155181884765625, 0.0033893585205078125, -0.01390838623046875]\n"
528+
]
529+
}
530+
],
531+
"source": [
532+
"from redisvl.utils.vectorize import MistralAITextVectorizer\n",
533+
"\n",
534+
"mistral = MistralAITextVectorizer()\n",
535+
"\n",
536+
"# embed a sentence using their asyncronous method\n",
537+
"test = await mistral.aembed(\"This is a test sentence.\")\n",
538+
"print(\"vector dimensions:\", len(test))\n",
539+
"print(test[:10])"
540+
]
541+
},
503542
{
504543
"cell_type": "markdown",
505544
"metadata": {},
@@ -658,7 +697,7 @@
658697
"name": "python",
659698
"nbconvert_exporter": "python",
660699
"pygments_lexer": "ipython3",
661-
"version": "3.11.5"
700+
"version": "3.12.2"
662701
},
663702
"orig_nbformat": 4,
664703
"vscode": {

poetry.lock

Lines changed: 74 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ openai = { version = ">=1.13.0", optional = true }
3030
sentence-transformers = { version = ">=2.2.2", optional = true }
3131
google-cloud-aiplatform = { version = ">=1.26", optional = true }
3232
cohere = { version = ">=4.44", optional = true }
33+
mistralai = { version = ">=0.2.0", optional = true }
3334

3435
[tool.poetry.extras]
3536
openai = ["openai"]
3637
sentence-transformers = ["sentence-transformers"]
3738
google_cloud_aiplatform = ["google_cloud_aiplatform"]
3839
cohere = ["cohere"]
40+
mistralai = ["mistralai"]
3941

4042
[tool.poetry.group.dev.dependencies]
4143
black = ">=20.8b1"
@@ -116,4 +118,4 @@ directory = "htmlcov"
116118

117119
[tool.mypy]
118120
warn_unused_configs = true
119-
ignore_missing_imports = true
121+
ignore_missing_imports = true

redisvl/utils/vectorize/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from redisvl.utils.vectorize.text.azureopenai import AzureOpenAITextVectorizer
33
from redisvl.utils.vectorize.text.cohere import CohereTextVectorizer
44
from redisvl.utils.vectorize.text.huggingface import HFTextVectorizer
5+
from redisvl.utils.vectorize.text.mistral import MistralAITextVectorizer
56
from redisvl.utils.vectorize.text.openai import OpenAITextVectorizer
67
from redisvl.utils.vectorize.text.vertexai import VertexAITextVectorizer
78

@@ -12,4 +13,5 @@
1213
"OpenAITextVectorizer",
1314
"VertexAITextVectorizer",
1415
"AzureOpenAITextVectorizer",
16+
"MistralAITextVectorizer",
1517
]

0 commit comments

Comments
 (0)