> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# infer_topics

> Generate topics and subtopics for given texts using OpenAI. 

## Usage

The following example shows how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      Generate topics for a given text column

      ```stan theme={null}
      infer_topics(ds.texts, {
          "integration": "open-ai-1",
          "n_topics": 10,
          "n_subtopics": 5,
          "inference_model": "openai/gpt-4.1",
          "assignment_model": "openai/gpt-4.1-mini",
      }) ->(ds.topic, ds.subtopic)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      infer_topics(texts: category|text, {
          "param": value,
          ...
      }) -> (topic: category, subtopic: category)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="texts" type="column[category|text]" required>
    Column containing the texts to infer topics from.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="topic" type="column[category]" required>
    Inferred topic for each text.
  </ParamField>

  <ParamField path="subtopic" type="column[category]" required>
    Inferred subtopic for each text.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="integration" type="string" required>
    Associated integration.
  </ParamField>

  <ParamField path="n_topics" type="integer" default="10">
    Number of Topics.
    Maximum approximate number of topics to infer.

    Values must be in the following range:

    ```javascript theme={null}
    2 ≤ n_topics ≤ 20
    ```
  </ParamField>

  <ParamField path="n_subtopics" type="integer" default="5">
    Number of Subtopics.
    Maximum approximate number of subtopics to infer per topic.

    Values must be in the following range:

    ```javascript theme={null}
    2 ≤ n_subtopics ≤ 10
    ```
  </ParamField>

  <ParamField path="n_samples" type="integer" default="500">
    Number of Samples.
    Maximum number of text samples to use for topic extraction. More texts consume more tokens and increase cost.

    Values must be in the following range:

    ```javascript theme={null}
    1 ≤ n_samples ≤ 10000
    ```
  </ParamField>

  <ParamField path="multitopic" type="boolean" default="false">
    Multi-topic Assignment.
    Whether to allow assigning multiple topics to each text. If enabled, the output columns will contain lists of
    topics/subtopics instead of single values.
  </ParamField>

  <ParamField path="inference_model" type="string">
    Inference AI Model.
    AI model used to infer topic hierarchy. This model will receive all sample texts, so potentially
    a large context, and needs to be reasonably capable to generate a well-structured topic hierarchy
    (no repeated or similar topics etc.).

    Values must be one of the following:

    `openai/gpt-4.1` `openai/gpt-4.1-mini` `openai/gpt-4.1-nano` `openai/gpt-5` `openai/gpt-5-mini` `openai/gpt-5-nano` `openai/gpt-5.1` `openai/gpt-5.2`
  </ParamField>

  <ParamField path="assignment_model" type="string">
    Assignment AI Model.
    AI model used to assign topic and subtopics to each text (row). This model will receive individual texts
    along with the inferred topic hierarchy, so it can be a smaller model focused on classification.

    Values must be one of the following:

    `openai/gpt-4.1` `openai/gpt-4.1-mini` `openai/gpt-4.1-nano` `openai/gpt-5` `openai/gpt-5-mini` `openai/gpt-5-nano` `openai/gpt-5.1` `openai/gpt-5.2`
  </ParamField>

  <ParamField path="inference_params" type="object">
    Inference Parameters.
    Additional parameters passed to the responses API for the inference call.
  </ParamField>

  <ParamField path="assignment_params" type="object">
    Assignment Parameters.
    Additional parameters passed to the responses API for the assignment call.
  </ParamField>
</Accordion>
