Semantic search
const url = 'https://flow.work.optidata.cloud/api/semantic/search';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"question":"How do I enable two-factor authentication?","top_k":2}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://flow.work.optidata.cloud/api/semantic/search \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "question": "How do I enable two-factor authentication?", "top_k": 2 }'Answers a natural-language question with the passages of published
pages whose meaning is closest to it — not just the ones sharing its
words. Each result is one passage (chunk) of a page’s current published
version, with the page, its category and a similarity between 0 and 1.
Only pages the caller can see are searched: those in categories visible
to them, plus pages made public. Passages below a minimum similarity are
left out, so a search can legitimately return no results. Newly published
text becomes searchable shortly after publication.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
The question or phrase to search for.
Only search pages of this category.
Maximum number of passages to return.
Examples
{ "question": "How do I enable two-factor authentication?", "top_k": 2}Responses
Section titled “ Responses ”The best-matching passages, most similar first.
object
object
The question, echoed.
object
The passage within the page’s published version.
object
Position of the passage in the page, from 0.
object
The published version the passage comes from.
object
The passage’s text.
How close the passage is to the question; higher is closer.
object
Number of passages returned.
The maximum that was in effect.
Examples
{ "data": { "question": "How do I enable two-factor authentication?", "results": [ { "chunk": { "id": 439, "index": 0 }, "page": { "id": 2927, "identifier": "dDbBQQtcKr", "title": "Onboarding checklist", "page_content_id": 4508 }, "category": { "id": 993, "identifier": "jYpV3A", "name": "Onboarding" }, "content": "Request a laptop and set up your Optiwork account on day one. Read the security handbook and enable two-factor authentication.", "similarity": 0.6173 } ], "meta": { "total_results": 1, "top_k": 2 } }}Nothing close enough
{ "data": { "question": "quarterly revenue forecast", "results": [], "meta": { "total_results": 0, "top_k": 5 } }}No authentication key was sent.
Authentication failures use an error key rather than message.
object
Examples
No bearer token sent
{ "error": "JWT passport exception: Missing bearer token in request"}The authentication key is expired or not recognised. Get a fresh one and retry.
Authentication failures use an error key rather than message.
object
Examples
{ "error": "JWT passport expired: Passport expired"}The body failed validation.
object
The first validation message.
Validation messages keyed by field name.
object
Examples
{ "message": "The question must be at least 3 characters.", "errors": { "question": [ "The question must be at least 3 characters." ] }}{ "message": "The selected category id is invalid.", "errors": { "category_id": [ "The selected category id is invalid." ] }}