Matching¶

class database.service.matching.MatchingService(model=typing.Type[sqlalchemy.orm.decl_api.Base])¶

Class that provide services for matching text with database entries

get_exact_match(db: Session, user_input: str, language: str = None, k: int = 0, tag: str = None)¶

Get exact match from database

Parameters:
  • db (Session)

  • user_input (str) – User input to match database entries

  • language (str, optional) – Question and results language

  • k (int, optional) – Number of results to return

Return type:

list of dict

get_fuzzy_match(db: Session, user_input: str, threshold: int = 150, language: str = None, k: int = 0, tag: str = None)¶

Get fuzzy match from database using levenshtein distance

Parameters:
  • db (Session)

  • user_input (str) – User input to match database entries

  • threshold (int, optional)

  • language (str, optional) – Question and results language

  • k (int, optional) – Number of results to return

Return type:

list of dict

get_trigram_match(db: Session, user_input: str, threshold: int = 0.4, language: str = None, k: int = 0, tag: str = None)¶

Get trigram match from database

Parameters:
  • db (Session)

  • user_input (str) – User input to match database entries

  • threshold (int, optional) – Trigram similarity threshold, default to 0.4

  • language (str, optional) – Question and results language

  • k (int, optional) – Number of results to return, default to 0 (return all results)

get_semantic_match(db: Session, user_input: str, language: str = None, k: int = 0, symbol: str = '<=>', tag: str = None)¶

Get semantic similarity match from database

Parameters:
  • db (Session)

  • user_input (str) – User input to match database entries

  • symbol (str, optional) – distance function symbol, default to <=> (cosine distance). For other options, see https://github.com/pgvector/pgvector

  • language (str, optional) – Question and results language

  • k (int, optional) – Number of results to return, default to 0 (return all results)

Return type:

list of dict

semantic_similarity_match_l1(db: Session, user_input: str, language: str = None, k: int = 0, tag: str = None)¶

Get semantic similarity match from database using L1 distance

semantic_similarity_match_l2(db: Session, user_input: str, language: str = None, k: int = 0, tag: str = None)¶

Get semantic similarity match from database using L2 distance

semantic_similarity_match_inner_prod(db: Session, user_input: str, language: str = None, k: int = 0, tag: str = None)¶

Get semantic similarity match from database using inner product