Using the Semantic Search Config API
Semantic Search Config API Documentation
Section titled “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
Section titled “Authentication”Clients calling the API are required to add an authentication header with the valid authentication token.
Authorization: Bearer {ACCESS_TOKEN}
Configuring Semantic Search
Section titled “Configuring Semantic Search”In order to use and query Semantic / Hybrid Search we first need to configure it. This can be done using the config
mutation.
GraphQL Example to Configure Semantic Search
Section titled “GraphQL Example to Configure Semantic Search”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
Section titled “GraphQL Response”{ "data": { "config": { "semanticSearch": { "type": "BASIC", "fields": [ "post_title" ] } } }}
Getting Semantic Search configuration
Section titled “Getting Semantic Search configuration”This can be donne using the following query:
query getSemanticSearchConfiguration { config { semanticSearch { type fields } }}
GraphQL Response
Section titled “GraphQL Response”{ "data": { "config": { "semanticSearch": { "type": "BASIC", "fields": [ "post_title" ] } } }}
Complete GraphQL Example ( Configure / Index and Search)
Section titled “Complete GraphQL Example ( Configure / Index and Search) ”1. Configure Semantic Search
Section titled “1. Configure Semantic Search”mutation ConfigureSemanticSearch { config { semanticSearch(fields: ["post_title"]) { type fields } }}
sample response:
{ "data": { "config": { "semanticSearch": { "type": "BASIC", "fields": [ "post_title" ] } } }}
2. Index Document
Section titled “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" } } } }}
3. Search using semantic search:
Section titled “3. Search using semantic search:”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" } } ] } }}