Sitecore Cognitive Services: Core

July 23, 2019

Are you ready to add cloud based machine learning APIs to your Sitecore solution? Then save yourself some time and use Sitecore Cognitive Services.

What is it, you ask? It's a series of .NET API connectors (the core) and new features built on that core. It's open source and available on GitHub or Nuget. You can use what's there, improve on them or even build your own using the existing ones a model.

This differs from previous versions of this project by the separation of the core from the features. Earlier I had one large solution with everything in it but now that I have a growing number of features, it's becoming more important to segment the projects and provide them separately. 

Here's a few videos to get you started:

Why Should You?

There's a lot of problems we as developers have long since given up on solving because at the time there was no solution. With the advent of turnkey machine learning cloud APIs it's time to rethink what's possible. Image analysis, language parsing and analytic analysis are now just a few of the new things we can automate at scale. 

The list of systems supported at this point are: 

Installation

There's a few ways you can install this:

Nuget

As of this writing only two of the projects are on Nuget. The other two projects are more of a guide than a finished project but you can get them here:

If you've decide to go this route, you'll need to manually configure the unicorn serialization path to make sure that the serialized files that were installed are synced in properly.

Source Code

When you go to download and setup the system, you want to know they live in nested folders. The core is the main solution and each of the feature projects should be checked out into their own subfolder under /src/Feature (ie: /SitecoreCognitiveServices/src/Feature/OleChat). Each feature has it's own publish profile and can be published onto your working Sitecore website independently. 

Here's the list of parts (as of this writing)

The source code setup steps are as follows:

  • Check out the Core and any Features source code (OleChat, Intelligent Search etc)
  • Open the Core project and under /src create a folder called 'Feature' and move any feature source folders in there (the Feature folder is ignored by the core so no worries there)
  • Browse to the root folder of the Core and run the setup.bat
  • Browse to /<root>/scripts/nant/properties/local.properties and edit any folder paths to match your local environment and sitecore version
  • Open the Core solution in Visual Studio
  • Add a 'Feature' solution folder and then add any specific feature folders (such as OleChat)
  • Open Task Runner Explorer and run the 'Nant' command
  • Publish (using one-click publish) each project to your Sitecore instance (publish path was set in local.properties)
  • After you've published to Sitecore you'll want to sync with Unicorn to get all the structure set into the content tree
  • If you're testing intelligent search and blogcast you'll need to add the website domains (intelligentsearch.local and blogcast.local) to your host file and IIS bindings 
  • Log into Sitecore and browse to /sitecore/system/modules/Sitecore Cognitive Services
  • You can now save any API keys to the api nodes and start injecting the service classes from the SitecoreCognitiveServices.Foundation.SCSDK.Services namespace

Using The Core Services

Most of what how you'll interface with the system is the Core API service classes and making them available to you so you can start building interesting new features but there's a little setup that you need to start with. 

Setting API Keys

One of the most important parts of the system is creating and saving your API keys so that you can use the API connectors. I'm not going to go into detail on how to setup an account for each API but once you do, log into Sitecore and drill down to /sitecore/system/modules/Sitecore Cognitive Services/APIs and select the provider you're using. There is a group of fields that may already have some default values but make sure they all match the environment that you're using. Paste in the value, save and publish and you're done.

Using a Service

If you want to be able to use a service, you must first make sure you've saved the keys into the API section of the content tree. Once that's in place you ready to use the 'Service' classes. The namespaces start with: 'SitecoreCognitiveServices.Foundation.SCSDK.Services'. You can either instantiate them manually or inject them using dependency injection (the easier approach). 

There are a lot more utility classes that I've built into the SCSDK project that you can use to get items or publish. If you're starting new, you can use the existing features to see what's available. 

What about the Features?

For this article I'm limiting the scope to just setting up the project and working with the Core. I'll be writing separate articles later one each feature individually. 

Calling All Creatives

If you like to build new things then destiny is calling you. There isn't a more potent opportunity to stretch your fingers into and really rethink a lot about how we work with our technology. Eventually we'll deplete this vast new resource but until then there is a lot to learn and discover. Carpe all the diems!