Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MistralAI text vectorizer #169

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
AZURE_OPENAI_API_KEY: ${{secrets.AZURE_OPENAI_API_KEY}}
AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}
AZURE_OPENAI_DEPLOYMENT_NAME: ${{secrets.AZURE_OPENAI_DEPLOYMENT_NAME}}
Expand All @@ -80,6 +81,7 @@ jobs:
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
AZURE_OPENAI_API_KEY: ${{secrets.AZURE_OPENAI_API_KEY}}
AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}
AZURE_OPENAI_DEPLOYMENT_NAME: ${{secrets.AZURE_OPENAI_DEPLOYMENT_NAME}}
Expand All @@ -92,4 +94,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false
fail_ci_if_error: false
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Commands:
### ⚡ Community Integrations
Integrate with popular embedding models and providers to greatly simplify the process of vectorizing unstructured data for your index and queries:
- [Cohere](https://www.redisvl.com/api/vectorizer/html#coheretextvectorizer)
- [Mistral](https://www.redisvl.com/api/vectorizer/html#mistralaitextvectorizer)
- [OpenAI](https://www.redisvl.com/api/vectorizer.html#openaitextvectorizer)
- [HuggingFace](https://www.redisvl.com/api/vectorizer.html#hftextvectorizer)
- [GCP VertexAI](https://www.redisvl.com/api/vectorizer.html#vertexaitextvectorizer)
Expand Down
6 changes: 5 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def azure_endpoint():
def cohere_key():
return os.getenv("COHERE_API_KEY")

@pytest.fixture
def mistral_key():
return os.getenv("MISTRAL_API_KEY")

@pytest.fixture
def gcp_location():
return os.getenv("GCP_LOCATION")
Expand Down Expand Up @@ -133,4 +137,4 @@ def sample_data():
def clear_db(redis):
redis.flushall()
yield
redis.flushall()
redis.flushall()
41 changes: 40 additions & 1 deletion docs/user_guide/vectorizers_04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"2. HuggingFace\n",
"3. Vertex AI\n",
"4. Cohere\n",
"5. Mistral AI\n",
"\n",
"Before running this notebook, be sure to\n",
"1. Have installed ``redisvl`` and have that environment active for this notebook.\n",
Expand Down Expand Up @@ -500,6 +501,44 @@
"Learn more about using RedisVL and Cohere together through [this dedicated user guide](https://docs.cohere.com/docs/redis-and-cohere)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mistral AI\n",
"\n",
"[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",
"\n",
"```bash\n",
"pip install mistralai\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"vector dimensions: 1024\n",
"[-0.02801513671875, 0.02532958984375, 0.04278564453125, 0.0185699462890625, 0.041015625, 0.006053924560546875, 0.03607177734375, -0.0030155181884765625, 0.0033893585205078125, -0.01390838623046875]\n"
]
}
],
"source": [
"from redisvl.utils.vectorize import MistralAITextVectorizer\n",
"\n",
"mistral = MistralAITextVectorizer()\n",
"\n",
"# embed a sentence using their asyncronous method\n",
"test = await mistral.aembed(\"This is a test sentence.\")\n",
"print(\"vector dimensions:\", len(test))\n",
"print(test[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -658,7 +697,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.2"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
75 changes: 74 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ openai = { version = ">=1.13.0", optional = true }
sentence-transformers = { version = ">=2.2.2", optional = true }
google-cloud-aiplatform = { version = ">=1.26", optional = true }
cohere = { version = ">=4.44", optional = true }
mistralai = { version = ">=0.2.0", optional = true }

[tool.poetry.extras]
openai = ["openai"]
sentence-transformers = ["sentence-transformers"]
google_cloud_aiplatform = ["google_cloud_aiplatform"]
cohere = ["cohere"]
mistralai = ["mistralai"]

[tool.poetry.group.dev.dependencies]
black = ">=20.8b1"
Expand Down Expand Up @@ -116,4 +118,4 @@ directory = "htmlcov"

[tool.mypy]
warn_unused_configs = true
ignore_missing_imports = true
ignore_missing_imports = true
2 changes: 2 additions & 0 deletions redisvl/utils/vectorize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from redisvl.utils.vectorize.text.azureopenai import AzureOpenAITextVectorizer
from redisvl.utils.vectorize.text.cohere import CohereTextVectorizer
from redisvl.utils.vectorize.text.huggingface import HFTextVectorizer
from redisvl.utils.vectorize.text.mistral import MistralAITextVectorizer
from redisvl.utils.vectorize.text.openai import OpenAITextVectorizer
from redisvl.utils.vectorize.text.vertexai import VertexAITextVectorizer

Expand All @@ -12,4 +13,5 @@
"OpenAITextVectorizer",
"VertexAITextVectorizer",
"AzureOpenAITextVectorizer",
"MistralAITextVectorizer",
]
Loading
Loading