liveBook · Manning

Candidate selection

As explained in Knowledge Graphs and LLMs in Action

Candidate selection is the phase of entity disambiguation that identifies possible reference entities for a recognized mention.

Candidate selection is the retrieval phase of named entity disambiguation: it maps each recognized mention to one or more possible entities in a domain knowledge base or ontology, postponing final choice to ranking or disambiguation. section 7.2 section 8.4.2

Implement candidate selection as a constrained retrieval pipeline:

  • Accept NER-annotated mentions and their entity labels alongside a domain ontology. section 8.4.2
  • Query ontology names with Neo4j full-text search, restricting results to labels relevant to the mention type. section 8.4.2
  • Return candidate identifiers and names for later ranking or ontology-aware disambiguation; vector search can supplement text matching. section 8.4 section 8.4.2

Retrieving candidates for “Zika”

A SNOMED search returns Zika virus (50471002), Zika virus disease (3928002), and Congenital Zika virus infection (762725007). These alternatives form the candidate pool; contextual ranking or ontology-path analysis selects the intended meaning afterward. section 8.4.2 section 8.4

Listing 8.13 Python class for CS
class CandidateSelection:
[...]
  def full_text_query(self):
    query = """
            CALL db.index.fulltext.queryNodes("names", $fulltextQuery,
            {limit: $limit})
            YIELD node
            WHERE node:SnomedEntity AND ANY(x IN node.type 
            WHERE x IN $labels)
            RETURN distinct node.name AS candidate_name, node.id 
            AS candidate_id
            """

    return query

  def generate_full_text_query(self, input):
    full_text_query = ""
    words = [el for el in input.split() if el]

    if len(words) > 1:
      for word in words[:-1]:
        full_text_query += f" {word}~0.80 AND "
        full_text_query += f" {words[-1]}~0.80"
    else:
      full_text_query = words[0] + "~0.80"

    return full_text_query.strip() [...]

The Python class shows how to generate fuzzy full-text queries and restrict Neo4j results to relevant SNOMED entity labels. section 8.4.2

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains inputs, outputs, label filtering, fuzzy full-text querying, and vector-search limitations, but defers final candidate choice.
Examples
Uses biomedical mentions such as “Zika” and returns competing SNOMED concepts with identifiers and names.
What it assumes
Assumes NER-annotated mentions and a loaded domain ontology, while distinguishing retrieval from later contextual disambiguation.
What you can do after
Build candidate retrieval with Neo4j full-text search, ontology labels, fuzzy queries, and structured identifier-name results.
How it connects
Connects named entity recognition, named entity disambiguation, domain ontologies, full-text search, candidate ranking, and vector search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.