Skip to content
Atlas Platform
GitHubDiscordYouTube

Using the Semantic Search Config API

Semantic Search Config API Documentation

In order to use Semantic / Hybrid Search, we first need to configure it.

This can be done using the config mutation. We can also acquire current config settings using the config query.

Authentication

Clients calling the API are required to add an authentication header with the valid authentication token.

Authorization: Bearer {ACCESS_TOKEN}

In order to use and query Semantic / Hybrid Search we first need to configure it. This can be done using the config mutation.

Let’s say we want to configure the post_title field for Semantic Search. We can do this by using the following mutation:

mutation ConfigureSemanticSearch {
    config {
        semanticSearch(fields: ["post_title"]) {
            type
            fields
        }
    }
}

GraphQL Response

{
  "data": {
    "config": {
      "semanticSearch": {
        "type": "BASIC",
        "fields": [
          "post_title"
        ]
      }
    }
  }
}

Getting Semantic Search configuration

This can be donne using the following query:

query getSemanticSearchConfiguration {
    config {
        semanticSearch {
            type
            fields
        }
    }
}

GraphQL Response

{
  "data": {
    "config": {
      "semanticSearch": {
        "type": "BASIC",
        "fields": [
          "post_title"
        ]
      }
    }
  }
}
mutation ConfigureSemanticSearch {
    config {
        semanticSearch(fields: ["post_title"]) {
            type
            fields
        }
    }
}

sample response:

{
  "data": {
    "config": {
      "semanticSearch": {
        "type": "BASIC",
        "fields": [
          "post_title"
        ]
      }
    }
  }
}

2. Index Document

mutation CreateIndexDocument($input: DocumentInput!) {
  index(input: $input) {
    success
    code
    message
    document {
      id
      data
    }
  }
}

with variables:

{
  "input": {
    "data": {
      "ID": 1,
      "post_title": "Rabbit",
      "post_content": "Rabbit is happily running",
      "post_date": "11-06-2023T12:33:00",
      "post_type": "post",
      "post_status": "publish"
    }
  }
}

sample response:

{
  "data": {
    "index": {
      "success": true,
      "code": "200",
      "message": "Document indexed successfully",
      "document": {
        "id": "CJfqrI0BxRpQ02smQWSk",
        "data": {
          "ID": 1,
          "post_content": "Rabbit is happily running",
          "post_date": "11-06-2023T12:33:00",
          "post_status": "publish",
          "post_title": "Rabbit",
          "post_type": "post"
        }
      }
    }
  }
}

Search using semantic search can be done using the following query:

query FindWithSemanticSearch {
  find(
    query: "eats carrots and is a rodent"
    semanticSearch: {searchBias:10, fields: ["post_title"]}
  ) {
    total
    documents {
      score
      data
    }
  }
}

sample response:

{
  "data": {
    "find": {
      "total": 1,
      "documents": [
        {
          "score": 2.5204816,
          "data": {
            "ID": 1,
            "post_content": "Rabbit is happily running",
            "post_date": "11-06-2023T12:33:00",
            "post_status": "publish",
            "post_title": "Rabbit",
            "post_type": "post"
          }
        }
      ]
    }
  }
}