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.

MIN_SIMILARITY_THRESHOLD = 0.01
__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.

Parameters:
  • query – Search query string

  • max_results – Maximum number of results to return

Returns:

List of action_ids sorted by relevance (highest similarity 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