Define and Query Selectors

Sophia allows you to define custom selectors, enabling you to group phrases and responses for any topic or question you want to parse against user input. For instance, you might create a selector called "check if user is available," which includes multiple possible answers—ranging from "immediately" to "never"—with each answer encompassing various predefined phrases. When you parse user input against a selector, the engine will match the input to one of the defined groupings and return the top answer along with a confidence score.

You can also configure an external LLM as a fallback option. If the engine cannot confidently match user input to a predefined grouping, the LLM will be prompted for an answer. The engine will then cache this response for future queries, making it self-improving. The fallback LLM can be a local Ollama installation with any model or accessed via API from OpenAI or Mistral.

To import selectors, simply prepare a directory with one JSON file per selector. Each JSON file should contain an associative array, where the keys represent the groupings or answers, and the values are one-dimensional arrays of predefined phrases. Import these selectors into the vocabulary by running a function within the shared library or calling the RPC command: import_selectors(dirname).

Once imported, you can query user input against any selector by invoking the function within the shared library or via the RPC daemon using the command: assess(input, selector_alias).