schrodinger.utils.semantic_search_engine module

class schrodinger.utils.semantic_search_engine.SemanticSearchEngine

Bases: object

Semantic search engine for actions using sklearn and cosine similarity.

Uses character n-gram vectorization and cosine similarity to find semantically related actions based on their content. Applies field-level weighting: name > keywords > category > help_text

NAME = 'name'
KEYWORDS = 'keywords'
CATEGORY = 'category'
HELP_TEXT = 'help_text'
MIN_SIMILARITY_THRESHOLD = 0.01
FIELD_WEIGHTS: Dict[str, float] = {'category': 2.0, 'help_text': 1.0, 'keywords': 3.0, 'name': 8.0}
TOTAL_WEIGHT: float = 14.0
__init__()

Initialize a new semantic search engine.

add_action(action_id: str, name: str, help_text: str, category: str, keywords: List[str]) None

Add an action to the search index.

Parameters:
  • action_id – Unique identifier for the action

  • name – Display name of the action

  • help_text – Help text describing the action

  • category – Category the action belongs to

  • keywords – List of search keywords for the action

clear() None

Clear all actions and reset the engine.

initialize() None

Initialize the vectorizer with all actions.

search(query: str, max_results: int) List[str]

Search for actions matching the query.

Results are ranked by weighted field similarity (name > keywords > category > help_text), with actions that exactly match a curated keyword ranked first, followed by actions whose name starts with the query.

Parameters:
  • query – Search query string

  • max_results – Maximum number of results to return

Returns:

List of action_ids sorted by relevance (highest first)

schrodinger.utils.semantic_search_engine.create_engine() int

Create a new isolated semantic search engine instance.

Returns:

Engine ID for the new instance

schrodinger.utils.semantic_search_engine.destroy_engine(engine_id: int) None

Destroy a semantic search engine instance.

Parameters:

engine_id – ID of the engine to destroy

schrodinger.utils.semantic_search_engine.engine_command(engine_id: int, command: str, *args, **kwargs)

Execute a command on a specific engine instance using dispatch pattern.

Parameters:
  • engine_id – ID of the engine to operate on (ignored for create_engine)

  • command – Method name to call on the engine

  • args – Positional arguments to pass to the method

  • kwargs – Keyword arguments to pass to the method

Returns:

Result from the method call

Raises:
  • ValueError – If engine_id is not found

  • AttributeError – If command method doesn’t exist