Guides / Algolia AI

Algolia Answers lets you semantically search your index data. It leverages Natural Language Understanding (NLU) technologies to analyze your user’s query and your records, and return the most relevant answer from within your content using machine learning.

For example, given the query “healthy soup” and an index of recipe blog articles, Answers could return the title “Bone Broth Strengthens Immunity, Body, and Joints.” Even if no query words appear in this title, semantic search allows you to draw connections within your content and find answers for your users in seconds.

An example usage of Algolia Answers

This feature is in limited release. You can sign up to request access.

Getting started

Authentication

Once you have access to the Answers API, you need an API key with the nluReadAnswers ACL. It’s best to create a new API key with the nluReadAnswers and the search permission.

Choosing your data

Long texts, such as articles and transcripts, work best with Answers.

Finding Answers in your index

Once you have your credentials set up, you can send requests to the Answers API:

1
2
3
4
5
6
7
8
let response = index.findAnswers(
  'when do babies start learning?',
  ['en'],
  {
    attributesForPrediction: ['description', 'title', 'transcript'],
    nbHits: 2
  }
)

The response has the relevant hits with an extra _answer field in each hit. This field has an extract from the record answering the query, with its confidence score and optionally the original source attribute of the hit as extractAttribute. Answers are ordered by decreasing confidence scores.

If no answers match the query, Answers returns an empty hits array.

Response information

The Answers API response follows the same structure as the Search API response, and includes an _answer field on each hit:

1
2
3
4
5
{
  "extract": "the chances of your brain <em>learning</em> how to see are very, very slim — again, slim or none.So when I heard these two things, it troubled me deeply, both because of personal reasons and scientific reasons. So let me first <em>start</em> with the personal reason. It'll sound corny, but it's sincere. That's my son, Darius. As a new father, I have a qualitatively different sense of just how delicate <em>babies</em> are, what our obligations are towards them",
  "score": 152.885,
  "extractAttribute": "transcript"
}

The response might contain several Answers from the same record if its content answers the query well.

Retrieving multiple answers

You can retrieve multiple answers for a query using the nbHits parameter. For example, the preceding snippet sets the nbHits parameter to 2, to retrieve two answers. When retrieving multiple answers, Answers sorts them by decreasing confidence scores.

Using threshold to filter results based on confidence scores

You can use the threshold parameter to fine-tune the results set depending on confidence score. Answers removes any result with an _answer that has a lower score than the threshold.

You should set a threshold of 0 to always retrieve at least one relevant answer. Only results that are very unrelated to the query have a negative confidence score. You can use a threshold of 185 to retrieve only hits that the Answers engine predicts are highly relevant.

The score attribute for any answer is dependent on the query. While you can compare scores from various answers to the same query, comparing scores on answers for different queries doesn’t make sense.

Controlling highlighting

By default, answers include the matching word extract highlighted in _highlightResult. You can control highlighting at query time by setting attributesToHighlight in the searchParameters parameter.

Managing Search Analytics

To understand how your users search your application and measure the impact of semantic search, Algolia Answers integrates with your Search Analytics.

By default, Algolia tags requests sent to the Answers API with the analyticsTags: "algolia-answers". You can add more analyticsTags by declaring them in the searchParameters parameter.

Did you find this page helpful?