What Is The Coveo PipelineContext Component?

The Coveo PipelineContext Component

A Coveo component I hadn't even heard up until quite recently, turns out to be something extremely powerful if you're looking at extending a Query Pipeline by injecting in some contextual data.

I'm of course referring to the PipelineContext Component. Its main purpose is for injecting custom contextual information into a user's search request along with UA search events.

An important note: this shouldn't be used as a way of dealing with security-related queries or queries that require specific permissions to elevate secured content. For that, you want to be updating the Coveo User Context via the Search Token. Anything you place within the PipelineContext is fair game to be manipulated.

How To Implement It?

Well, like most Coveo components, you're able to utilize this functionality very easily through the DOM.

It's not by adding the class to a div element. In this case you're going to use a script element. Have a look at this very simple example.

<script class="CoveoPipelineContext" type="text/context">
"country": "Canada",
"province": "Alberta"

As you can see, the context itself is just an object we're able to assign a key-value pair.

This object can contain essentially whatever you want and through your application, you can derive the information in any number of ways. The big question though is how do you access this information?

Let's Use Our PipelinContext Data

With the custom data loaded, how is it used and how can it be used? There are two ways, one is automatic, the other is by enabling you to modify the Query Pipeline manually.

Query Pipeline Expressions

If you log into your Platform Admin and head to the Query Pipeline you have a few options of where to utilize the $context.

One such place is you can add a Ranking Expression utilizing one or all of the context values you have provided. For example, you can generate a QRE such as the following applying a modifier.

$qre(expression: @country==$, modifier: 250)

This thereby can boost the relevant content. Coveo ML will in turn learn from this behavior.

Query Pipeline Conditions

You can also enable conditions in the pipeline thereby only affecting your results if conditions within the context are present in the same manner. This can be done anywhere within the Query Pipeline that allows for a condition to be placed. You can create filters that are only applied under certain contexts or go as far as enabling a pipeline itself under certain conditions.


CoveoAnalytics And Coveo ML

If you already have a CoveoAnalytics component added to your Search Interface then that context data is automatically added to a property called customData. This property is logged as part of the usage analytics event and prefixed by context_.

Once that is done, the Coveo ML service can effectively learn from it. How awesome is that? The model will be able to promote content that matches that key-value pair.


As the information is logged via the Usage Analytics events, this data is then also available to those who have reporting capabilities within the Platform Admin. Generating reports based upon this information.

The Big Picture

As you can see, by simply enhancing the context in which a search is conducted, both the end-user with those that manage and market the information can each receive more personalized information and thus enhance the experience.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting

Meet David Austin

Development Team Lead | Sitecore Technology MVP x 3


David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David