Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pip install mistral-haystack
`MistralTextEmbedder` needs a Mistral API key to work. It uses a `MISTRAL_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with `api_key`:

```python
from haystack.utils import Secret
from haystack_integrations.components.embedders.mistral.text_embedder import (
MistralTextEmbedder,
)

embedder = MistralTextEmbedder(
api_key=Secret.from_token("<your-api-key>"),
model="mistral-embed",
Expand All @@ -51,34 +56,29 @@ embedder = MistralTextEmbedder(

### On its own

Remember to set the`MISTRAL_API_KEY` as an environment variable first or pass it in directly.

Here is how you can use the component on its own:
Set `MISTRAL_API_KEY` in your environment before running this example.

```python
from haystack.utils import Secret
from haystack_integrations.components.embedders.mistral.text_embedder import (
MistralTextEmbedder,
)

embedder = MistralTextEmbedder(
api_key=Secret.from_token("<your-api-key>"),
model="mistral-embed",
)
embedder = MistralTextEmbedder(model="mistral-embed")

result = embedder.run(text="How can I ise the Mistral embedding models with Haystack?")
result = embedder.run(text="How can I use the Mistral embedding models with Haystack?")

print(result["embedding"])
# [-0.0015687942504882812, 0.052154541015625, 0.037109375...]
print(len(result["embedding"]))
# >> 1024
```

### In a pipeline

Below is an example of the `MistralTextEmbedder` in a document search pipeline. We are building this pipeline on top of an `InMemoryDocumentStore` where we index the contents of two URLs.

Set `MISTRAL_API_KEY` and `OPENAI_API_KEY` in your environment before running the pipeline.

```python
from haystack import Document, Pipeline
from haystack.utils import Secret
from haystack import Pipeline
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.components.fetchers import LinkContentFetcher
from haystack.components.converters import HTMLToDocument
Expand Down Expand Up @@ -117,7 +117,7 @@ indexing.run(
data={
"fetcher": {
"urls": [
"https://docs.mistral.ai/self-deployment/cloudflare/",
"https://docs.mistral.ai/inference/deployment/local-deployment/cloudflare",
"https://docs.mistral.ai/platform/endpoints/",
],
},
Expand All @@ -142,10 +142,7 @@ prompt_builder = ChatPromptBuilder(
template=prompt_template,
required_variables={"query", "documents"},
)
llm = OpenAIChatGenerator(
model="gpt-4o-mini",
api_key=Secret.from_token("<your-api-key>"),
)
llm = OpenAIChatGenerator()

doc_search = Pipeline()
doc_search.add_component("text_embedder", text_embedder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pip install mistral-haystack
`MistralTextEmbedder` needs a Mistral API key to work. It uses a `MISTRAL_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with `api_key`:

```python
from haystack.utils import Secret
from haystack_integrations.components.embedders.mistral.text_embedder import (
MistralTextEmbedder,
)

embedder = MistralTextEmbedder(
api_key=Secret.from_token("<your-api-key>"),
model="mistral-embed",
Expand All @@ -51,34 +56,29 @@ embedder = MistralTextEmbedder(

### On its own

Remember to set the`MISTRAL_API_KEY` as an environment variable first or pass it in directly.

Here is how you can use the component on its own:
Set `MISTRAL_API_KEY` in your environment before running this example.

```python
from haystack.utils import Secret
from haystack_integrations.components.embedders.mistral.text_embedder import (
MistralTextEmbedder,
)

embedder = MistralTextEmbedder(
api_key=Secret.from_token("<your-api-key>"),
model="mistral-embed",
)
embedder = MistralTextEmbedder(model="mistral-embed")

result = embedder.run(text="How can I ise the Mistral embedding models with Haystack?")
result = embedder.run(text="How can I use the Mistral embedding models with Haystack?")

print(result["embedding"])
# [-0.0015687942504882812, 0.052154541015625, 0.037109375...]
print(len(result["embedding"]))
# >> 1024
```

### In a pipeline

Below is an example of the `MistralTextEmbedder` in a document search pipeline. We are building this pipeline on top of an `InMemoryDocumentStore` where we index the contents of two URLs.

Set `MISTRAL_API_KEY` and `OPENAI_API_KEY` in your environment before running the pipeline.

```python
from haystack import Document, Pipeline
from haystack.utils import Secret
from haystack import Pipeline
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.components.fetchers import LinkContentFetcher
from haystack.components.converters import HTMLToDocument
Expand Down Expand Up @@ -117,7 +117,7 @@ indexing.run(
data={
"fetcher": {
"urls": [
"https://docs.mistral.ai/self-deployment/cloudflare/",
"https://docs.mistral.ai/inference/deployment/local-deployment/cloudflare",
"https://docs.mistral.ai/platform/endpoints/",
],
},
Expand All @@ -142,10 +142,7 @@ prompt_builder = ChatPromptBuilder(
template=prompt_template,
required_variables={"query", "documents"},
)
llm = OpenAIChatGenerator(
model="gpt-4o-mini",
api_key=Secret.from_token("<your-api-key>"),
)
llm = OpenAIChatGenerator()

doc_search = Pipeline()
doc_search.add_component("text_embedder", text_embedder)
Expand Down