{ "cells": [ { "cell_type": "markdown", "id": "d14d29ebd3592ecb", "metadata": { "collapsed": false }, "source": [ "# Late Interaction Text Embedding Models\n", "\n", "As of version 0.3.0 FastEmbed supports Late Interaction Text Embedding Models and currently available with one of the most popular embedding model of the family - ColBERT.\n", "\n", "## What is a Late Interaction Text Embedding Model?\n", "\n", "Late Interaction Text Embedding Model is a kind of information retrieval model which performs query and documents interactions at the scoring stage.\n", "In order to better understand it, we can compare it to the models without interaction. \n", "For instance, if you take a sentence-transformer model, compute embeddings for your documents, compute embeddings for your queries, and just compare them by cosine similarity, then you're retrieving points without interaction.\n", "\n", "It is a pretty much easy and straightforward approach, however we might be sacrificing some precision due to its simplicity. It is caused by several facts: \n", "- there is no interaction between queries and documents at the early stage (embedding generation) nor at the late stage (during scoring). \n", "- we are trying to encapsulate all the document information in only one pooled embedding, and obviously, some information might be lost.\n", "\n", "Late Interaction Text Embedding models are trying to address it by computing embeddings for each token in queries and documents, and then finding the most similar ones via model specific operation, e.g. ColBERT (Contextual Late Interaction over BERT) uses MaxSim operation.\n", "With this approach we can have not only a better representation of the documents, but also make queries and documents more aware one of another.\n", "\n", "For more information on ColBERT and MaxSim operation, you can check out [this blogpost](https://jina.ai/news/what-is-colbert-and-late-interaction-and-why-they-matter-in-search/) by Jina AI.\n", "\n", "## ColBERT in FastEmbed\n", "\n", "FastEmbed provides a simple way to use ColBERT model, similar to the ones it has with `TextEmbedding`.\n", " " ] }, { "cell_type": "code", "execution_count": 1, "id": "7f1053b17c810be5", "metadata": { "ExecuteTime": { "end_time": "2024-06-03T17:20:26.927643Z", "start_time": "2024-06-03T17:20:25.128994Z" }, "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/joein/work/qdrant/fastembed/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "data": { "text/plain": "[{'model': 'colbert-ir/colbertv2.0',\n 'dim': 128,\n 'description': 'Late interaction model',\n 'size_in_GB': 0.44,\n 'sources': {'hf': 'colbert-ir/colbertv2.0'},\n 'model_file': 'model.onnx'}]" }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from fastembed import LateInteractionTextEmbedding\n", "\n", "LateInteractionTextEmbedding.list_supported_models()" ] }, { "cell_type": "code", "execution_count": 2, "id": "c2c15893df422631", "metadata": { "ExecuteTime": { "end_time": "2024-06-03T17:23:35.764183Z", "start_time": "2024-06-03T17:23:21.630277Z" }, "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching 5 files: 0%| | 0/5 [00:00