Mistral

MistralEmbeddingClient は、Mistral AI モデルを使用してテキスト埋め込みを生成します。 これは、ベクター インデックス作成、セマンティック検索、クラスタリング、または Agent Framework 埋め込みクライアントを必要とするその他のアプリケーションに使用します。

このプロバイダーは現在、埋め込みのみを提供しています。エージェント フレームワーク チャット クライアントは提供されません。

パッケージをインストールする

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>"

埋め込みの生成

クライアントを作成し、 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}

MistralEmbeddingOptionsを使用して、サポートされている出力ディメンションを要求します。 アプリケーションでカスタム互換性のあるエンドポイントを使用する場合は、 MISTRAL_SERVER_URL を設定することもできます。

Important

Mistral AI はサード パーティのシステムです。 アプリケーション データを送信する前に、サービス条件、データ処理、地域境界、モデル ライセンス、および使用コストを確認します。

Tools

このパッケージは現在、Agent Framework チャット クライアントではなく埋め込みクライアントを提供しているため、ツールは適用されません。

次のステップ

RAG