SemanticRanking    

SemanticRanking[{text1, },ref]

sorts textual items texti by semantic similarity to the reference string ref.

SemanticRanking[list,ref,prop]

returns the specified property prop.

Details

  • SemanticRanking reorders the input textual list according to semantic similarity to a provided reference string.
  • SemanticRanking[{text1, text2, text3, }, ref] sorts texti from the most to least similar.
  • Possible values for prop include:
  • "Ordering"similarity rank for each item
    "Item"items in the original order
    "RankedItem"items reordered from most to least similar (default)
    "Relevance"numerical similarity between each item and the reference
    {prop1,}a list of properties
    Alla Tabular with all the properties
  • The following options can be given:
  • Method Automaticsemantic ranking method
  • Possible values for Method include:
  • Automaticdefault local model
    Tiny, Small, Medium, Largepredefined model sizes
    {"string",size}a named model of the specified size
    fa custom ranking function
  • A custom ranker f must operate on the reference string and a list of strings to produce a numerical vector of the same length. The higher the number, the more similar the pair is.
  • Specific ranking models include:
  • "MiniLM"default (Medium) "MiniLM" ranker
    {"MiniLM",Tiny}MiniLM-V2 L-2
    {"MiniLM",Small}MiniLM-V2 L-4
    {"MiniLM",Medium}MiniLM-V2 L-6
    {"MiniLM",Large}MiniLM-V2 L-12
    "BGE"BAAI BGE-V2-M3

Examples

open allclose all

Basic Examples  (1)

Rerank single-word items according to similarity:

Retrieve the relevance of each item:

Scope  (2)

Retrieve items in order of similarity from a reference text:

Return a selected property of each item:

Retrieve multiple properties:

Get all properties:

Options  (1)

Method  (1)

Specify a reranking function for species designations using a custom text extractor:

Use the extractor in the function:

Rank the text:

Check the ordering:

Properties & Relations  (1)

SemanticSearch automatically reranks the results using SemanticRerank:

This is equivalent to retrieving the "MinItems" for RerankingMethod without actually doing it:

Then taking the first five results after using SemanticRanking:

Possible Issues  (1)

Create several paragraphs of text:

Reranking such a large number of items is slow:

Instead create a SemanticSearchIndex:

Use SemanticSearch to get a shortlist of the best matches:

Then rerank the shortlist:

The closest result is identical:

Wolfram Research (2025), SemanticRanking, Wolfram Language function, https://reference.wolfram.com/language/ref/SemanticReranking.html.

Text

Wolfram Research (2025), SemanticRanking, Wolfram Language function, https://reference.wolfram.com/language/ref/SemanticReranking.html.

CMS

Wolfram Language. 2025. "SemanticRanking." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SemanticReranking.html.

APA

Wolfram Language. (2025). SemanticRanking. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SemanticReranking.html

BibTeX

@misc{reference.wolfram_2025_semanticranking, author="Wolfram Research", title="{SemanticRanking}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/SemanticReranking.html}", note=[Accessed: 25-August-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_semanticranking, organization={Wolfram Research}, title={SemanticRanking}, year={2025}, url={https://reference.wolfram.com/language/ref/SemanticReranking.html}, note=[Accessed: 25-August-2025 ]}