Search
Expanding Search Queries
In this example, we will demonstrate how to leverage the enums and typed arrays to segment a complex search prompt into multiple, better structured queries that can be executed separately against specialized APIs or search engines.
Motivation
Extracting a list of tasks from text is a common use case for leveraging language models. This pattern can be applied to various applications, such as virtual assistants like Siri or Alexa, where understanding user intent and breaking down requests into actionable tasks is crucial. In this example, we will demonstrate how to use Instructor to segment search queries, so you can execute them separately against specialized APIs or search engines.
Structure of the Data
The SearchQuery
class is a PHP class that defines the structure of an individual search query. It has three fields: title
, query
, and type
. The title
field is the title of the request, the query
field is the query to search for relevant content, and the type
field is the type of search. The execute
method is used to execute the search query.
Segmenting the Search Prompt
The segment
function takes a string data
and segments it into multiple search queries. It uses the Instructor::respond
method to send a prompt and extract the data into the target object. The responseModel
parameter specifies Search::class
as the model to use for extraction.