---
title: "Q&A API"
method: POST
path: "/v1/qa/question_answering"
tags: ["Q&A APIs"]
---

# Q&A API

`POST /v1/qa/question_answering`

Question Answering API analyzes each Product's `html` field and extracts paragraphs that can answer users'
questions.

For example, Miso can take question likes `What is python?`, and extract an answer like
`Python is an interpreted, object-oriented, high-level programming language.` from a product's `html` field.

Each answer is assigned a `probability` score that determines how likely a paragraph can accurately answer the
question. A probability at least 0.7 is recommended, but you usually will need to fine-tune
this threshold to find the precision-and-recall sweet-spot for your application.

### Limitations
Miso will only extract answers from the `html` field and from products that have `enable_question_answering` set to `true`. Also,
since Q&A is a much more complex search problem, the response time of this API is usually between 1 to 2 seconds
for a new question. For an old question this API has answered before, the response time will be less than 75ms.

## Request body

- QuestionAnsweringRequest
  - `version` 'v1.2' | 'v1.3' — The model version to use. * **v1.2**: First stable version * **v1.3**: Improve keyword extraction that make answers more precise
  - `q` string, required — The question user has entered.
  - `min_probability` number, required — Minimum acceptable probability (between 0.0 and 1.0). The answers whose probability is lower than this number will be excluded from the response.
  - `rows` integer — Number of search results to return.
  - `fl` string[] — List of fields to retrieve. Each Q&A response, by default, return two fields `answer` and `product_id`, where `answer` is an object with the information about the answer paragraph while `product_id` identifies the *Product* from which the answer is extracted. For example, the following is a sample response from the API: ``` { "product_id": "ABC-123", "answer": { "html": "<p>Python is an interpreted programming language</p>", "text": "Python is an interpreted programming language", "css_selector": ":root > div:nth-child(1) > p:nth-child(2)", "probability": 0.99 } } ``` You can use `fl` parameter to retrieve additional product fields. For example, the following request additionally retrieves the `title` field for each product along with the `product_id` and `answer`, which are always returned. ``` {"fl": ["title"]} ``` You can also match field names by using `*` as a wildcard. For example, the query below retrieves the `title` and all the `custom_attributes` fields. ``` {"fl": ["title", "custom_attributes.*"]} ``` The following request retrieves all the available product fields: ``` {"fl": ["*"]} ``` For the lowest latency, use an empty array (which is the default) to retrieve just the `product_id` and `answer` fields. ``` {"fl": []} ```
  - `spellcheck` SpellCheckRequest
    - `enable_auto_spelling_correction` boolean — This parameter controls whether to automatically correct a misspell search query. If set to `true`, when Miso detects spelling errors, the search results will be based on the **corrected** spelling suggested by Miso. You call tell if Miso made any correction to the search query by checking the `spellcheck.auto_spelling_correction` field in the API response. When this field is `true`, the search results are based on the suggested spelling as opposed to the users' original query. You can opt-out the spelling correction by setting this parameter to `false`. In such cases, Miso will still detect spelling errors, but the search results will be always based on users' original spelling.
  - `enable_answer_html` boolean — Whether to return HTML of the answer paragraph. If you don't need the HTML content of the answer paragraph, setting this parameter to `false` will reduce the response size and lower the response latency.
  - `enable_answer_block` boolean — Whether to return *answer block*. In addition to answer paragraph, Miso can additionally return *answer block*. Answer block is an ancestor HTML node of the answer paragraph that contains the relevant context. The answer block is particularly useful for applications that not only want to show the answer itself but also the **context** surrounding the answer. Answer block is the smallest HTML element that contains the relevant context. However, not all the content inside this node is relevant. You can use the returned `relevant_children_slice` field to identify a portion of this node that is relevant to the answer.
  - `fq` string — Defines a query in Solr syntax that can be used to restrict the superset of products to return, without influencing the overall ranking. `fq` can enable users to drill down to products with specific features based on different product attributes For example, the query below limits the search results to only show products whose size is either `M` or `S` and brand is `Nike`: ``` {"fq": "size:(\"M\" OR \"S\") AND brand:\"Nike\""} ``` You can use `fq` to apply filters against your custom attributes as well. For example, the query below limits the search results to only products whose `designer` attribute is `Calvin Klein` ``` {"fq": "attributes.designer:\"Calvin Klein\""} ``` `fq` can also limit search results by numerical range. For example, the following query limits the results to products that have `rating >= 4`. ``` {"fq": "rating:[4 TO *]"} ```
  - `boost_fq` string — Defines a query in Solr syntax that can be used to boost a subset of products to the top of the ranking, or to specific *boost positions* (See `boost_positions` parameter below.) For example, the query below will promote all the relevant products whose brand is `Nike` to the top of recommendation list: ``` { "boost_fq": "brand:\"Nike\"" } ``` For a slightly more complex example, the query below will promote the Nike products which have also been tagged as `ON SALE` to the top of the ranking: ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"" } ``` It is worth mentioning that, Miso will only boost products that are relevant and have high likelihood to convert, and will not boost a low performance product only because it matches the boosting query. Depending on your boosting rules, in certain cases, you would like to prevent recommendation results from being too monotone due to boosting. With Miso, you have two tools to do so. First, you can specify `boost_positions` to place promoted products at specific positions in the ranking. For example, the query below will place boosted products only at the first and fourth places in the ranking (positions are 0-based), and place the remaining products in their original ranking, skipping these two positions. ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "boost_positions": [0, 3] } ``` The second tool is `diversification`. `diversification` parameter, on a best-effort basis, will try to maintain a minimum distance between products that have the same attributes. For example, the following query will place products made by the same brand apart from each other. ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "diversification": { "brand": {"minimum_distance": 1} } } ```
  - `boost_positions` integer[] — Defines a list of 0-based positions you want to place the boosted products at. For example, the query below will promote products whose brand is `Nike` as the top and second recommendations: ``` { "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] } ``` If `boost_positions` is not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products.
  - `boost_rule_name` string — Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response
  - `boost_rules` BoostingFilterBase[] — Define a list of boosting rules that will be applied to the search or recommendation results simultaneously. `boost_rules` parameter is particularly useful when you want to boost more than one sets of products, and promote each of them to different positions. For example, the query below will promote products whose brand is `Nike` to the top and second results, and products whose brand is `Adidas` to the third and fourth results: ``` { "boost_rules": [ { "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] }, { "boost_fq": "brand:\"Adidas\"", "boost_positions": [2, 3] } ] } ```
    - `boost_fq` string — Defines a query in Solr syntax that can be used to boost a subset of products to the top of the ranking, or to specific *boost positions* (See `boost_positions` parameter below.) For example, the query below will promote all the relevant products whose brand is `Nike` to the top of recommendation list: ``` { "boost_fq": "brand:\"Nike\"" } ``` For a slightly more complex example, the query below will promote the Nike products which have also been tagged as `ON SALE` to the top of the ranking: ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"" } ``` It is worth mentioning that, Miso will only boost products that are relevant and have high likelihood to convert, and will not boost a low performance product only because it matches the boosting query. Depending on your boosting rules, in certain cases, you would like to prevent recommendation results from being too monotone due to boosting. With Miso, you have two tools to do so. First, you can specify `boost_positions` to place promoted products at specific positions in the ranking. For example, the query below will place boosted products only at the first and fourth places in the ranking (positions are 0-based), and place the remaining products in their original ranking, skipping these two positions. ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "boost_positions": [0, 3] } ``` The second tool is `diversification`. `diversification` parameter, on a best-effort basis, will try to maintain a minimum distance between products that have the same attributes. For example, the following query will place products made by the same brand apart from each other. ``` { "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "diversification": { "brand": {"minimum_distance": 1} } } ```
    - `boost_positions` integer[] — Defines a list of 0-based positions you want to place the boosted products at. For example, the query below will promote products whose brand is `Nike` as the top and second recommendations: ``` { "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] } ``` If `boost_positions` is not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products.
    - `boost_rule_name` string — Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response
  - `geo` GeoQuery
    - `filter` GeoDistanceQuery[] — When set, filter result to include only products within certain geographic range from given point.
      - `lat` number, required — Latitude of the center point, should between 90 and -90
      - `lon` number, required — Longitude of the center point, should between 180 and -180
      - `field` string — Name of the field in product data that holds geographic coordinate. Defaults to `location`
      - `distance` number, required — Distance to center point, in kilometer or mile (according to `distance_unit`)
      - `distance_unit` 'km' | 'mile' — Unit of distance(`km` or `mile`). Defaults to `mile`
    - `boost` GeoDistanceQueryBoost[] — When set, boost products within certain geographic range from given point.
      - `lat` number, required — Latitude of the center point, should between 90 and -90
      - `lon` number, required — Longitude of the center point, should between 180 and -180
      - `field` string — Name of the field in product data that holds geographic coordinate. Defaults to `location`
      - `distance` number, required — Distance to center point, in kilometer or mile (according to `distance_unit`)
      - `distance_unit` 'km' | 'mile' — Unit of distance(`km` or `mile`). Defaults to `mile`
      - `boost_positions` integer[] — Defines a list of 0-based positions you want to place the boosted products at. If `boost_positions` is not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products.
  - `boost_probability_threshold` number — Minimum probability required for an answer to be boosted. If not specified, the `min_probability` will be used.

## Response `200`

Successful Response

- QAResponse
  - `message` string
  - `data` QAResponseBody, required
    - `took` integer — Number of milliseconds Miso took to retrieve the results.
    - `miso_id` string, uuid — Miso-generated unique Id for each recommendation or search result. Maintaining this Id for subsequent page views is important to Miso's performance as we use `miso_id` to track and fine-tune the performance of personalization and search results. When a user clicks on a recommendation or search result, you should pass the associated `miso_id` to the next page view, and associate the `miso_id` with the interactions that take place on the page (e.g. `product_detail_page_view`, `add_to_cart`, `add_to_collection`, `like`, etc.). In this way, Miso will learn which recommendations work and which didn't. Example: ``` {"misoId": "123e4567-e89b-12d3-a456-426614174000"} ```
    - `total` integer, required — Total number of Question-Answer hits.
    - `spellcheck` SpellCheckResponse, required
      - `spelling_errors` boolean, required — Whether Miso detects any spelling errors.
      - `auto_spelling_correction` boolean, required — Whether Miso has automatically corrected the misspelled search query. When this field is `true`, the search result is based on the corrected spelling in the `corrected_query` field instead of users' original search query.
      - `original_query` string, required — Original query string
      - `original_query_with_markups` string, required — Original query with the spelling errors (if any) surrounded by the <mark> tags
      - `corrected_query` string, required — The corrected spelling suggested by Miso. If no spelling error is detected, this will be the same as `original_query`
      - `corrected_query_with_markups` string, required — The corrected spelling suggested by Miso where the revised tokens are surrounded by the <mark> tags.
    - `answers` RecordWithAnswer[], required — The Question-Answer results.
      - `product_id` string, required — The unique identifier of the product whose content contains the answer.
      - `answer` Answer, required
        - `probability` number, required — The probability this paragraph can sufficiently answer the user's question (from 0.0 to 1.0).
        - `html` string — The answer paragraph in its original html tag, i.e. or the `outerHTML` of the answer paragraph node.
        - `text` string, required — The plain text version of answer paragraph.
        - `css_selector` string, required — The CSS selector that uniquely identifies the answer paragraph node in the original HTML content. This css selector matches exactly one HTML node that contains the answer paragraph. In order to be as unambiguous as possible, the returned CSS selector is in the form of a series of nth-child selectors starting from `:root` node (which is usually the `<html>`). For example, ``` :root > div:nth-child(1) > p:nth-child(2) ``` . This selector means the answer paragraph is a `<p>` tag that is the second child of a `<div>` node, which is in turn, the first child of the `:root` node. This CSS selector is useful when you want to make the answer paragraph stand out from the rest of the document. For example, the following JQuery code turns the background color of the answer paragraph to yellow: ``` $(answer.css_selector).css("background-color", "yellow"); ```
      - `answer_block` AnswerBlock
        - `html` string, required — The HTML content of the answer block
        - `css_selector` string, required — The CSS selector that uniquely identifies the answer block from the HTML root
        - `relevant_children_slice` unknown[], required — The range of children nodes inside the *answer block* that is relevant to the selected answer.
          - unknown
        - `answer_css_selector` string, required — The CSS selector to the selected answer paragraph inside the answer block. You can use this selector to select the answer from the answer block (as supposed to selecting from the HTML root)
        - `title` string, required — The relevant title to the answer paragraph. This title is extracted from a header node close to the answer paragraph. If there is no such node, the title will be an empty string

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/askmiso/apis/miso-api.md) · [All operations](https://skmtc.dev/askmiso/apis/miso-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/askmiso/miso-api/revisions/f2fa5ba6025f/schema)
