Edit

Mistral

MistralEmbeddingClient generates text embeddings with Mistral AI models. Use it for vector indexing, semantic search, clustering, or other applications that need an Agent Framework embedding client.

This provider currently supplies embeddings only; it doesn't provide an Agent Framework chat client.

Install the package

pip install agent-framework-mistral --pre

Configuration

MISTRAL_API_KEY="<api-key>"
MISTRAL_EMBEDDING_MODEL="mistral-embed"
# Optional compatible endpoint:
MISTRAL_SERVER_URL="<server-url>"

Generate embeddings

Create the client and call get_embeddings().

async def basic_embedding_example() -> None:
    """Generate embeddings for a list of texts."""
    print("=== Basic Embedding Generation ===")

    # 1. Create the embedding client using environment-based configuration.
    client = MistralEmbeddingClient()

    # 2. Generate embeddings for multiple texts.
    texts = ["Hello, world!", "How are you?", "Agent Framework with Mistral AI"]
    try:
        result = await client.get_embeddings(texts)

        # 3. Print the generated vectors and usage metadata.
        print(f"Generated {len(result)} embeddings")
        for i, embedding in enumerate(result):
            print(f"  Text {i + 1}: dimensions={embedding.dimensions}, vector={embedding.vector[:5]}...")

        if result.usage:
            print(
                f"  Usage: {result.usage['input_token_count']} input tokens, "
                f"{result.usage['total_token_count']} total tokens"
            )
    finally:
        await client.close()


async def embedding_with_options_example() -> None:
    """Generate embeddings with custom dimensions."""
    print("\n=== Embedding with Custom Dimensions ===")

    from agent_framework.mistral import MistralEmbeddingOptions

    # Only some models support a custom output dimension (e.g. codestral-embed; mistral-embed does not).
    client = MistralEmbeddingClient(model="codestral-embed")

    options: MistralEmbeddingOptions = {"dimensions": 256}

Use MistralEmbeddingOptions to request a supported output dimension. You can also set MISTRAL_SERVER_URL when the application uses a custom compatible endpoint.

Important

Mistral AI is a third-party system. Review its service terms, data handling, regional boundaries, model licensing, and usage costs before sending application data.

Tools

Tools aren't applicable because this package currently provides an embedding client, not an Agent Framework chat client.

Next steps

RAG