Mistral Cookbook

repository·main·Indexed 25 days ago

https://github.com/mistralai/cookbook

A collection of practical examples, notebooks, and guides for implementing Mistral AI models. It covers real-world scenarios including RAG, agentic workflows, tool integration, and the Model Context Protocol (MCP). The documentation provides deep dives into LLM concepts such as quantization formats (GGUF, GPTQ, AWQ, EXL2), memory estimation, sampling settings (Temperature, Top P, Top K, Min P), and tokenization versions (V1, V2, V3).

Tokens
116.6K
Snippets
266
Records
379
Agent score
81%

What's inside mistralai-cookbook

  1. Overview of Invoice OCR Analyzer Features

    main

    The Invoice OCR Analyzer is a Mistral Document AI-powered tool designed for the extraction, correction, and analysis of PDF documents.

    Key capabilities include:

    • OCR Extraction: Uses Mistral Document AI (Azure-hosted) to extract text, tables, and images.
    • OCR Error Correction: Automatically fixes common OCR errors in units and numbers.
    • Completeness Checking: Detects skipped rows, empty cells, and sequential gaps in tables.
    • Invoice Value Analysis: Extracts structured lab values and compares them against 60+ standard clinical reference ranges.
    • Anomaly Highlighting: Provides color-coded status badges: Normal (green), Low/High (orange), and Critical (red).
    • Interactive Web UI: A Gradio interface featuring a PDF viewer, results panel, corrections log, and reference table.
  2. Overview of the Tic-Tac-Toe MCP Server project structure

    main

    The project is organized into the following files:

    • mcp_server.py: The main MCP server implementation.
    • app.py: Contains the core game logic and the Flask API.
    • requirements.txt: Lists the necessary Python dependencies.
    • Dockerfile: Configuration for deploying the server to Hugging Face Spaces.
    tictactoe-mcp-server/
    ├── mcp_server.py      # Main MCP server code
    ├── app.py             # Game logic and Flask API
    ├── requirements.txt   # Python dependencies
    ├── Dockerfile        # For Hugging Face deployment
  3. Overview of Indexify-Mistral Cookbooks

    main

    The Indexify-Mistral Cookbooks demonstrate how to integrate Indexify's data pipeline engine with Mistral's large language models to build production-ready pipelines for document understanding.

    Indexify is an open-source engine designed for building fast data pipelines for unstructured data (video, audio, images, and documents). It uses reusable extractors for embedding, transformation, and feature extraction, and automatically updates vector databases and structured databases (like Postgres) when pipelines produce data. Applications can then query these indexes using semantic search and SQL.

  4. Overview of Phoenix for Mistral AI Observability

    main

    Phoenix is an open-source AI observability platform designed to help you trace, evaluate, and experiment with Mistral AI applications. It supports several core workflows:

    • Tracing: Monitor your Mistral AI application's runtime using OpenTelemetry-based instrumentation.
    • Evaluation: Use Mistral AI to benchmark application performance through response and retrieval evaluations.
    • Datasets: Manage versioned datasets of examples for use in experimentation, evaluation, and fine-tuning.
    • Experiments: Track and evaluate modifications made to prompts, LLMs, and retrieval mechanisms.

    Phoenix is highly portable and can be run in Jupyter notebooks, on local machines, in containerized deployments, or in the cloud.

  5. Build a Property Graph using LlamaIndex and MistralAI

    main

    This cookbook provides several patterns for building PropertyGraphs by combining LlamaIndex's graph capabilities with MistralAI models. You can choose between different implementation strategies depending on your requirements for schema control, storage, and retrieval:

    • Default Implementation: Use property_graph.ipynb to build a graph using default extractors and retrievers.
    • Custom Extractors and Retrievers: Use property_graph_extractors_retrievers.ipynb to learn how to define custom extractors, retrievers, and prompts.
    • Neo4j Integration: Use property_graph_neo4j.ipynb to build PropertyGraphs specifically with Neo4j by customizing extractors and retrievers.
    • Pre-defined Schema: Use property_graph_predefined_schema.ipynb to build graphs using the SchemaLLMPathExtractor, which allows you to pre-define the graph schema.
    • Custom Retrieval Logic: Use property_graph_custom_retriever.ipynb to implement custom retrieval using VectorContextRetriever and Text2CypherRetriever.
  6. Set up E2B Python AI Code Execution with Mistral's Codestral

    main

    This project demonstrates an AI data analyst that performs data analysis tasks (like plotting linear regression) on CSV data. It combines Mistral's Codestral model for code generation with the E2B Code Interpreter SDK for secure code execution.

    How it works:

    1. Sandboxing: The E2B SDK creates a secure cloud sandbox powered by Firecracker containing a running Jupyter server.
    2. Data Upload: The CSV dataset is uploaded to the E2B sandboxed environment.
    3. Code Generation: A prompt is sent to the Codestral model to generate Python code for the specific analysis task.
    4. Execution: The generated code is executed within the E2B sandbox.
    5. Output: Visualizations (like plots) are saved as PNG files (e.g., image_1.png).
  7. Use LlamaIndex with MistralAI models

    main
    LlamaIndex is a data framework for LLM-based applications that focuses on context augmentation. You can use LlamaIndex to ingest, structure, and access private or domain-specific data to inject it into MistralAI's LLMs and Embedding models. The cookbook provides several specialized notebooks for different RAG (Retrieval-Augmented Generation) and Agentic patterns using Mistral models.
  8. Trace and observe Mistral AI models with Langtrace

    main
    Langtrace is an open-source, OpenTelemetry-based observability platform for LLM applications. It allows you to capture rich model traces (including prompts, completions, and hyperparameters), monitor other parts of your stack (like vector databases and frameworks), annotate/evaluate model generations, run automated evaluations to detect regressions, and manage/version control prompts.
  9. LLM Judge: Detecting hallucinations in language models

    main

    This project demonstrates how to fine-tune and evaluate a Mistral AI language model to detect factual inconsistencies and hallucinations in text summaries. It utilizes datasets from the Factual Inconsistency Benchmark (FIB) and USB.

    Key capabilities include:

    • Preparing datasets for hallucination detection.
    • Fine-tuning a Mistral 7B model.
    • Evaluating performance using accuracy, F1 score, precision, and recall.
    • Integrating with Weights & Biases (W&B) for experiment tracking and W&B Weave for tracing and organizing model evaluations.