Models¶
A model in mteb covers two concepts: metadata and implementation.
- Metadata contains information about the model such as maximum input
length, valid frameworks, license, and degree of openness.
- Implementation is a reproducible workflow, which allows others to run the same model again, using the same prompts, hyperparameters, aggregation strategies, etc.
mtebUtilities¶
mteb.get_model_metas(model_names=None, languages=None, open_weights=None, frameworks=None, n_parameters_range=(None, None), use_instructions=None, zero_shot_on=None, model_types=None)
¶
Load all models' metadata that fit the specified criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_names
|
Iterable[str] | None
|
A list of model names to filter by. If None, all models are included. |
None
|
languages
|
Iterable[str] | None
|
A list of languages to filter by. If None, all languages are included. |
None
|
open_weights
|
bool | None
|
Whether to filter by models with open weights. If None this filter is ignored. |
None
|
frameworks
|
Iterable[str] | None
|
A list of frameworks to filter by. If None, all frameworks are included. |
None
|
n_parameters_range
|
tuple[int | None, int | None]
|
A tuple of lower and upper bounds of the number of parameters to filter by. If (None, None), this filter is ignored. |
(None, None)
|
use_instructions
|
bool | None
|
Whether to filter by models that use instructions. If None, all models are included. |
None
|
zero_shot_on
|
list[AbsTask] | None
|
A list of tasks on which the model is zero-shot. If None this filter is ignored. |
None
|
model_types
|
Iterable[str] | None
|
A list of model types to filter by. If None, all model types are included. |
None
|
Returns:
| Type | Description |
|---|---|
list[ModelMeta]
|
A list of model metadata objects that fit the specified criteria. |
Source code in mteb/models/get_model_meta.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
mteb.get_model_meta(model_name, revision=None, fetch_from_hf=True, fill_missing=False)
¶
A function to fetch a model metadata object by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model to fetch |
required |
revision
|
str | None
|
Revision of the model to fetch |
None
|
fetch_from_hf
|
bool
|
Whether to fetch the model from HuggingFace Hub if not found in the registry |
True
|
fill_missing
|
bool
|
Fill missing attributes from the metadata including number of parameters and memory usage. |
False
|
Returns:
| Type | Description |
|---|---|
ModelMeta
|
A model metadata object |
Source code in mteb/models/get_model_meta.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
mteb.get_model(model_name, revision=None, device=None, **kwargs)
¶
A function to fetch and load model object by name.
Note
This function loads the model into memory. If you only want to fetch the metadata, use get_model_meta instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model to fetch |
required |
revision
|
str | None
|
Revision of the model to fetch |
None
|
device
|
str | None
|
Device used to load the model |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the model loader |
{}
|
Returns:
| Type | Description |
|---|---|
MTEBModels
|
A model object |
Source code in mteb/models/get_model_meta.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
Metadata¶
mteb.models.model_meta.ModelMeta
¶
Bases: BaseModel
The model metadata object.
Attributes:
| Name | Type | Description |
|---|---|---|
loader |
Callable[..., MTEBModels] | None
|
The function that loads the model. If None it assumes that the model is not implemented. |
loader_kwargs |
dict[str, Any]
|
The keyword arguments to pass to the loader function. |
name |
str | None
|
The name of the model, ideally the name on huggingface. It should be in the format "organization/model_name". |
n_parameters |
int | None
|
The total number of parameters in the model, e.g. |
n_embedding_parameters |
int | None
|
The number of parameters used for the embedding layer. Can be None if the number of embedding parameters is not known (e.g. for proprietary models). |
n_active_parameters_override |
int | None
|
The number of active parameters used bu model. Should be used only for Mixture of Experts models. |
memory_usage_mb |
float | None
|
The memory usage of the model in MB. Can be None if the memory usage is not known (e.g. for proprietary models). To calculate it use the |
max_tokens |
float | None
|
The maximum number of tokens the model can handle. Can be None if the maximum number of tokens is not known (e.g. for proprietary models). |
embed_dim |
int | None
|
The dimension of the embeddings produced by the model. Currently all models are assumed to produce fixed-size embeddings. |
revision |
str | None
|
The revision number of the model. If None, it is assumed that the metadata (including the loader) is valid for all revisions of the model. |
release_date |
StrDate | None
|
The date the model's revision was released. If None, then release date will be added based on 1st commit in hf repository of model. |
license |
Licenses | StrURL | None
|
The license under which the model is released. Required if open_weights is True. |
open_weights |
bool | None
|
Whether the model is open source or proprietary. |
public_training_code |
str | None
|
A link to the publicly available training code. If None, it is assumed that the training code is not publicly available. |
public_training_data |
str | bool | None
|
A link to the publicly available training data. If None, it is assumed that the training data is not publicly available. |
similarity_fn_name |
ScoringFunction | None
|
The distance metric used by the model. |
framework |
list[FRAMEWORKS]
|
The framework the model is implemented in, can be a list of frameworks e.g. |
reference |
StrURL | None
|
A URL to the model's page on huggingface or another source. |
languages |
list[ISOLanguageScript] | None
|
The languages the model is intended to be specified as a 3-letter language code followed by a script code e.g., "eng-Latn" for English in the Latin script. |
use_instructions |
bool | None
|
Whether the model uses instructions E.g. for prompt-based models. This also includes models that require a specific format for input, such as "query: {document}" or "passage: {document}". |
citation |
str | None
|
The citation for the model. This is a bibtex string. |
training_datasets |
set[str] | None
|
A dictionary of datasets that the model was trained on. Names should be names as their appear in |
adapted_from |
str | None
|
Name of the model from which this model is adapted. For quantizations, fine-tunes, long doc extensions, etc. |
superseded_by |
str | None
|
Name of the model that supersedes this model, e.g., nvidia/NV-Embed-v2 supersedes v1. |
model_type |
list[MODEL_TYPES]
|
A list of strings representing the type of model. |
modalities |
list[Modalities]
|
A list of strings representing the modalities the model supports. Default is ["text"]. |
contacts |
list[str] | None
|
The people to contact in case of a problem in the model, preferably a GitHub handle. |
Source code in mteb/models/model_meta.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |
is_cross_encoder
property
¶
Returns True if the model is a cross-encoder.
Derived from model_type field. A model is considered a cross-encoder if "cross-encoder" is in its model_type list.
n_active_parameters
property
¶
Number of active parameters. Assumed to be n_parameters - n_embedding_parameters. Can be overwritten using n_active_parameters_override e.g. for MoE models.
calculate_memory_usage_mb()
¶
Calculates the memory usage of the model in MB.
Returns:
| Type | Description |
|---|---|
int | None
|
The memory usage of the model in MB, or None if it cannot be determined. |
Source code in mteb/models/model_meta.py
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | |
calculate_num_parameters_from_hub()
¶
Calculates the number of parameters in the model.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of parameters in the model. |
Source code in mteb/models/model_meta.py
909 910 911 912 913 914 915 | |
create_empty(overwrites=None)
classmethod
¶
Creates an empty ModelMeta with all fields set to None or empty.
Source code in mteb/models/model_meta.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
fetch_release_date(model_name)
staticmethod
¶
Fetches the release date from HuggingFace Hub based on the first commit.
Returns:
| Type | Description |
|---|---|
StrDate | None
|
The release date in YYYY-MM-DD format, or None if it cannot be determined. |
Source code in mteb/models/model_meta.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | |
from_cross_encoder(model, revision=None, fill_missing=None, compute_metadata=None, fetch_from_hf=False)
classmethod
¶
Generates a ModelMeta from a CrossEncoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CrossEncoder
|
The CrossEncoder model |
required |
revision
|
str | None
|
Revision of the model |
None
|
fill_missing
|
bool | None
|
Fill missing attributes from the metadata including number of parameters and memory usage. |
None
|
compute_metadata
|
bool | None
|
Deprecated. Use fill_missing instead. |
None
|
fetch_from_hf
|
bool
|
Whether to fetch additional metadata from HuggingFace Hub based on the model name. If False, only metadata that can be extracted from the CrossEncoder model will be used. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
The generated ModelMeta |
Source code in mteb/models/model_meta.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |
from_hub(model, revision=None, fill_missing=None, compute_metadata=None)
classmethod
¶
Generates a ModelMeta for model from HuggingFace hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Name of the model from HuggingFace hub. For example, |
required |
revision
|
str | None
|
Revision of the model |
None
|
fill_missing
|
bool | None
|
Deprecated. The fill missing did not add any functionality for this function, but was added for compatibility with
'from_sentence_transformer_model' and |
None
|
compute_metadata
|
bool | None
|
Deprecated. Was superseded by fill_missing. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The generated ModelMeta. |
Source code in mteb/models/model_meta.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
from_sentence_transformer_model(model, revision=None, fill_missing=False, compute_metadata=None, fetch_from_hf=False)
classmethod
¶
Generates a ModelMeta from a SentenceTransformer model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
SentenceTransformer
|
SentenceTransformer model. |
required |
revision
|
str | None
|
Revision of the model |
None
|
fill_missing
|
bool
|
Fill missing attributes from the metadata including number of parameters and memory usage. |
False
|
compute_metadata
|
bool | None
|
Deprecated. Use fill_missing instead. |
None
|
fetch_from_hf
|
bool
|
Whether to fetch additional metadata from HuggingFace Hub based on the model name. If False, only metadata that can be extracted from the SentenceTransformer model will be used. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
The generated ModelMeta. |
Source code in mteb/models/model_meta.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | |
get_training_datasets()
¶
Returns all training datasets of the model including similar tasks.
Source code in mteb/models/model_meta.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
is_zero_shot_on(tasks)
¶
Indicates whether the given model can be considered zero-shot or not on the given tasks.
Returns:
| Type | Description |
|---|---|
bool | None
|
None if no training data is specified on the model. |
Source code in mteb/models/model_meta.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
load_model(device=None, **kwargs)
¶
Loads the model using the specified loader function.
Source code in mteb/models/model_meta.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
merge(overwrite)
¶
Merges another this ModelMeta with another ModelMeta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overwrite
|
Self
|
The ModelMeta to merge into this one. Non-None fields in this ModelMeta will overwrite the corresponding fields in this
ModelMeta. the |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new ModelMeta with the merged fields. |
Source code in mteb/models/model_meta.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
model_name_as_path()
¶
Returns the model name in a format that can be used as a file path.
Replaces "/" with "__" and spaces with "_".
Source code in mteb/models/model_meta.py
294 295 296 297 298 299 300 301 | |
to_dict()
¶
Returns a dictionary representation of the model metadata.
Source code in mteb/models/model_meta.py
239 240 241 242 243 244 245 246 247 248 249 250 | |
to_python()
¶
Returns a string representation of the model.
Source code in mteb/models/model_meta.py
1069 1070 1071 | |
zero_shot_percentage(tasks)
¶
Indicates how out-of-domain the selected tasks are for the given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Sequence[AbsTask] | Sequence[str]
|
A sequence of tasks or dataset names to evaluate against. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
An integer percentage (0-100) indicating how out-of-domain the tasks are for the model. |
int | None
|
Returns None if no training data is specified on the model or if no tasks are provided. |
Source code in mteb/models/model_meta.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
Model Protocols¶
mteb.models.EncoderProtocol
¶
Bases: Protocol
The interface for an encoder in MTEB.
Besides the required functions specified below, the encoder can additionally specify the following signatures seen below. In general the interface is kept aligned with sentence-transformers interface. In cases where exceptions occurs these are handled within MTEB.
Source code in mteb/models/models_protocols.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
mteb_model_meta
property
¶
Metadata of the model
__init__(model_name, revision, device=None, **kwargs)
¶
The initialization function for the encoder. Used when calling it from the mteb run CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model |
required |
revision
|
str | None
|
revision of the model |
required |
device
|
str | None
|
Device used to load the model |
None
|
kwargs
|
Any
|
Any additional kwargs |
{}
|
Source code in mteb/models/models_protocols.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
encode(inputs, *, task_metadata, hf_split, hf_subset, prompt_type=None, **kwargs)
¶
Encodes the given sentences using the encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
DataLoader[BatchedInput]
|
Batch of inputs to encode. |
required |
task_metadata
|
TaskMetadata
|
The metadata of the task. Encoders (e.g. SentenceTransformers) use to select the appropriate prompts, with priority given to more specific task/prompt combinations over general ones. The order of priorities for prompt selection are: 1. Composed prompt of task name + prompt type (query or passage) 2. Specific task prompt 3. Composed prompt of task type + prompt type (query or passage) 4. Specific task type prompt 5. Specific prompt type (query or passage) |
required |
hf_split
|
str
|
Split of current task, allows to know some additional information about current split. E.g. Current language |
required |
hf_subset
|
str
|
Subset of current task. Similar to |
required |
prompt_type
|
PromptType | None
|
The name type of prompt. (query or passage) |
None
|
**kwargs
|
Unpack[EncodeKwargs]
|
Additional arguments to pass to the encoder. |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The encoded input in a numpy array or torch tensor of the shape (Number of sentences) x (Embedding dimension). |
Source code in mteb/models/models_protocols.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
similarity(embeddings1, embeddings2)
¶
Compute the similarity between two collections of embeddings.
The output will be a matrix with the similarity scores between all embeddings from the first parameter and all embeddings from the second parameter. This differs from similarity_pairwise which computes the similarity between corresponding pairs of embeddings.
Read more at: https://www.sbert.net/docs/package_reference/sentence_transformer/SentenceTransformer.html#sentence_transformers.SentenceTransformer.similarity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings1
|
Array
|
[num_embeddings_1, embedding_dim] or [embedding_dim]-shaped numpy array or torch tensor. |
required |
embeddings2
|
Array
|
[num_embeddings_2, embedding_dim] or [embedding_dim]-shaped numpy array or torch tensor. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A [num_embeddings_1, num_embeddings_2]-shaped torch tensor with similarity scores. |
Source code in mteb/models/models_protocols.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
similarity_pairwise(embeddings1, embeddings2)
¶
Compute the similarity between two collections of embeddings. The output will be a vector with the similarity scores between each pair of embeddings.
Read more at: https://www.sbert.net/docs/package_reference/sentence_transformer/SentenceTransformer.html#sentence_transformers.SentenceTransformer.similarity_pairwise
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings1
|
Array
|
[num_embeddings, embedding_dim] or [embedding_dim]-shaped numpy array or torch tensor. |
required |
embeddings2
|
Array
|
[num_embeddings, embedding_dim] or [embedding_dim]-shaped numpy array or torch tensor. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A [num_embeddings]-shaped torch tensor with pairwise similarity scores. |
Source code in mteb/models/models_protocols.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
mteb.models.SearchProtocol
¶
Bases: Protocol
Interface for searching models.
Source code in mteb/models/models_protocols.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
mteb_model_meta
property
¶
Metadata of the model
index(corpus, *, task_metadata, hf_split, hf_subset, encode_kwargs, num_proc)
¶
Index the corpus for retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus
|
CorpusDatasetType
|
Corpus dataset to index. |
required |
task_metadata
|
TaskMetadata
|
Metadata of the task, used to determine how to index the corpus. |
required |
hf_split
|
str
|
Split of current task, allows to know some additional information about current split. |
required |
hf_subset
|
str
|
Subset of current task. Similar to |
required |
encode_kwargs
|
EncodeKwargs
|
Additional arguments to pass to the encoder during indexing. |
required |
num_proc
|
int | None
|
Number of processes to use for dataloading. |
required |
Source code in mteb/models/models_protocols.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
search(queries, *, task_metadata, hf_split, hf_subset, top_k, encode_kwargs, top_ranked=None, num_proc)
¶
Search the corpus using the given queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries
|
QueryDatasetType
|
Queries to find |
required |
task_metadata
|
TaskMetadata
|
Task metadata |
required |
hf_split
|
str
|
split of the dataset |
required |
hf_subset
|
str
|
subset of the dataset |
required |
top_ranked
|
TopRankedDocumentsType | None
|
Top-ranked documents for each query, mapping query IDs to a list of document IDs. Passed only from Reranking tasks. |
None
|
top_k
|
int
|
Number of top documents to return for each query. |
required |
encode_kwargs
|
EncodeKwargs
|
Additional arguments to pass to the encoder during indexing. |
required |
num_proc
|
int | None
|
Number of processes to use for dataloading. |
required |
Returns:
| Type | Description |
|---|---|
RetrievalOutputType
|
Dictionary with query IDs as keys with dict as values, where each value is a mapping of document IDs to their relevance scores. |
Source code in mteb/models/models_protocols.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
mteb.models.CrossEncoderProtocol
¶
Bases: Protocol
The interface for a CrossEncoder in MTEB.
Besides the required functions specified below, the cross-encoder can additionally specify the following signatures seen below. In general the interface is kept aligned with sentence-transformers interface. In cases where exceptions occurs these are handled within MTEB.
Source code in mteb/models/models_protocols.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
mteb_model_meta
property
¶
Metadata of the model
__init__(model_name, revision, device=None, **kwargs)
¶
The initialization function for the encoder. Used when calling it from the mteb run CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model |
required |
revision
|
str | None
|
revision of the model |
required |
device
|
str | None
|
Device used to load the model |
None
|
kwargs
|
Any
|
Any additional kwargs |
{}
|
Source code in mteb/models/models_protocols.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
predict(inputs1, inputs2, *, task_metadata, hf_split, hf_subset, prompt_type=None, **kwargs)
¶
Predicts relevance scores for pairs of inputs. Note that, unlike the encoder, the cross-encoder can compare across inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs1
|
DataLoader[BatchedInput]
|
First Dataloader of inputs to encode. For reranking tasks, these are queries (for text only tasks |
required |
inputs2
|
DataLoader[BatchedInput]
|
Second Dataloader of inputs to encode. For reranking, these are documents (for text only tasks |
required |
task_metadata
|
TaskMetadata
|
Metadata of the current task. |
required |
hf_split
|
str
|
Split of current task, allows to know some additional information about current split. E.g. Current language |
required |
hf_subset
|
str
|
Subset of current task. Similar to |
required |
prompt_type
|
PromptType | None
|
The name type of prompt. (query or passage) |
None
|
**kwargs
|
Unpack[EncodeKwargs]
|
Additional arguments to pass to the cross-encoder. |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The predicted relevance scores for each inputs pair. |
Source code in mteb/models/models_protocols.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
mteb.models.MTEBModels = EncoderProtocol | CrossEncoderProtocol | SearchProtocol
module-attribute
¶
Type alias for all MTEB model types as many models implement multiple protocols and many tasks can be solved by multiple model types.
mteb.models.IndexEncoderSearchProtocol
¶
Bases: Protocol
Protocol for search backends used in encoder-based retrieval.
Source code in mteb/models/search_encoder_index/search_backend_protocol.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
add_documents(embeddings, idxs)
¶
Add documents to the search backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
Array
|
Embeddings of the documents to add. |
required |
idxs
|
list[str]
|
IDs of the documents to add. |
required |
Source code in mteb/models/search_encoder_index/search_backend_protocol.py
14 15 16 17 18 19 20 21 22 23 24 | |
clear()
¶
Clear all stored documents and embeddings from the backend.
Source code in mteb/models/search_encoder_index/search_backend_protocol.py
53 54 | |
search(embeddings, top_k, similarity_fn, top_ranked=None, query_idx_to_id=None)
¶
Search through added corpus embeddings or rerank top-ranked documents.
Supports both full-corpus and reranking search modes
- Full-corpus mode:
top_ranked=None, uses added corpus embeddings. - Reranking mode:
top_rankedcontains mapping {query_id: [doc_ids]}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
Array
|
Query embeddings, shape (num_queries, dim). |
required |
top_k
|
int
|
Number of top results to return. |
required |
similarity_fn
|
Callable[[Array, Array], Array]
|
Function to compute similarity between query and corpus. |
required |
top_ranked
|
TopRankedDocumentsType | None
|
Mapping of query_id -> list of candidate doc_ids. Used for reranking. |
None
|
query_idx_to_id
|
dict[int, str] | None
|
Mapping of query index -> query_id. Used for reranking. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[list[float]], list[list[int]]]
|
A tuple (top_k_values, top_k_indices), for each query: - top_k_values: List of top-k similarity scores. - top_k_indices: List of indices of the top-k documents in the added corpus. |
Source code in mteb/models/search_encoder_index/search_backend_protocol.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
mteb.models.CacheBackendProtocol
¶
Bases: Protocol
Protocol for a vector cache map (used to store text/image embeddings).
Implementations may back the cache with different storage backends.
The cache maps an input item (text or image) to its vector embedding, identified by a deterministic hash.
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__contains__(item)
¶
Check whether the cache contains an item.
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
56 57 | |
__init__(directory=None, **kwargs)
¶
Initialize the cache backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path | None
|
Directory path to store cache files. |
None
|
**kwargs
|
Any
|
Additional backend-specific arguments. |
{}
|
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
21 22 23 24 25 26 27 | |
add(item, vectors)
¶
Add a vector to the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
list[dict[str, Any]]
|
Input item containing 'text' or 'image'. |
required |
vectors
|
Array
|
Embedding vector of shape (dim,) or (1, dim). |
required |
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
29 30 31 32 33 34 35 | |
close()
¶
Release resources or flush data.
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
53 54 | |
get_vector(item)
¶
Retrieve the cached vector for the given item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
dict[str, Any]
|
Input item. |
required |
Returns:
| Type | Description |
|---|---|
Array | None
|
Cached vector as np.ndarray, or None if not found. |
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
37 38 39 40 41 42 43 44 45 | |
load()
¶
Load cache from disk (index + metadata).
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
50 51 | |
save()
¶
Persist cache data to disk (index + metadata).
Source code in mteb/models/cache_wrappers/cache_backend_protocol.py
47 48 | |