Hello Friends,
I have been hearing about semantic search, but there are no documentations available or little documentation our there which talk about it
I had an opportunity to work on one of the POC where i used semantic search and i have also open source the code for it so you can explore it and use it against your Sitecore search.
What is Sitecore Sematic Search?
Well, semantic search in very quick definition means, Ability to know the intent of use query rather than just simply querying using breakdown of keywords, It uses NLP (Natural Language Processing) to understand the user's intent and predicts the next best results.
The whole working of it behind the scene is very interesting, but i will not go through who it vectorized the results, how it scores it and it finds the highest score and shows those results etc. what we will see is how we can get it working and what configurations are needed.
How to enable it
1) You need to raise a Sitecore support ticket and tell them you want the semantic search enabled, They need domain id so they can enable that feature from their end.
2) Neither Q&A feature or Sitecore semantic search is available OOTB, You need sepreate Sitecore Stream license.
Setup & Configurations
1) Once semantic search is enabled, Go into it and configure "Semantic Vector", This is important because it will tell Sitecore Search which fields are vectorized so semantic can run scoring algorithm on them and try to find the intent out of it and score them, This fields should be in your search sources.
2) Publish the setting (without it, It will not take effect)
3) Go to widgets and create a widget of the type "Search results", This is very important which type of widget you select, and then configure the widget and give it RFKID as this will be used in code to reference the widget
4) Publish it.
Except - Save stayed disabled, with a banner saying *"There are no rule settings to save on this rule."* Turns out this toggle is only a **preview-mode switch** for the in-editor content search box. It does not persist anywhere. First red herring down.
Code reference
At the end of the post i have included the GITHUB public repo, but the main route is /semantic-search, The important part if which end point of Sitecore Search you use
try {
// Real semantic search - hits the /semantic-search path (not the plain /discover/v2
// endpoint the ask/suggest routes use), which is what makes this a vector/semantic
// lookup instead of a keyword match against the same content source.
({ res, payload } = await callSitecoreSearch(
request,
{
widget: {
items: [
{
entity: ENTITY,
rfk_id: SEMANTIC_RESULTS_WIDGET_ID,
...(CONTENT_SOURCE_ID ? { sources: [CONTENT_SOURCE_ID] } : {}),
search: {
content: { fields: ["name", "description", "url", "article_url"] },
query: { keyphrase: sanitizeContentKeyphrase(keyphrase), operator: "or" },
limit: 10,
},
},
],
},
},
"/semantic-search"
));
} catch (err) {
console.error("[semantic-search] failed to reach Sitecore Search", err);
return NextResponse.json(
{ error: "Could not reach the Sitecore Search API. See server logs for details." },
{ status: 502 }
);
}
and here is what happens inside "callSitecoreSearch" function
export async function callSitecoreSearch(
request: NextRequest,
body: Record<string, unknown>,
path = ""
) {
const endpoint = `${HOST!.replace(/\/$/, "")}/discover/v2/${DOMAIN_ID}${path}`;
const res = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(API_KEY ? { Authorization: API_KEY } : {}),
},
body: JSON.stringify({ context: buildContext(request), ...body }),
});
const payload = (await res.json().catch(() => null)) as SitecoreSearchResponse | null;
return { res, payload };
}
Working demo
Semantic search in Sitecore Search is genuinely good once it is wired correctly - it just does not advertise how many small, silent requirements stand between "configured" and "working." Hope this saves someone a few hours.
Cheers !!!