Overview

The intelligent content engine is programmable and extensible. The Cortex SDK makes it easy to ingest data into catalogs, programmatically create content, and stream chats and responses to your own applications. Cortex users have built things on top of the intelligent content engine like:

  1. Customized embedded copilots
  2. Slackbots
  3. Zendesk autoresponders
  4. Hubspot and Salesforce integrations

The Cortex Node.js SDK (GitHub repo) is the recommended way to program with our platform. If you need access from a language other than JavaScript/TypeScript, please reach out as we have other languages on our roadmap and unpublished documentation for our public REST API.

Node.js SDK

The Cortex SDK requires Node.js v20+.

Feature requests, bug reports, and open source contributions are welcome through the GitHub repo.

Installation

Install the SDK via NPM:

$ nvm use v20 # make sure you're using node.js v20+
$ npm install @cortexclick/cortex

Configuration

To use the SDK create a client specifying (1) a personal, or organization access token and (2) your organization name:

const client = new CortexClient({
  org: "your-org-name",
  accessToken: process.env.CORTEX_ACCESS_TOKEN,
});

From there you can configure organization settings, catalogs, and cortexes:

// configure organization-level defaults
await client.configureOrg({
  companyName: "ACME",
  companyInfo:
    "ACME is a purveyor of various novelty props including anvils and dynamite.",
  personality: ["approachable", "knowledgeable", "expert blacksmith"],
});
 
// configure a cortex for a specific job:
const cortex = await client.configureCortex("slack-support", {
  // data sources that this cortex has access to when generating responses
  catalogs: ["docs", "previous-support-cases"],
  friendlyName: "ACME Support",
  instructions: [
    "You will recieve messages from users that are asked via Slack. Respond to their questions to the best of your ability.",
    "When appropriate, provide links to help articles",
    'If you cannot answer a question, or sense that the user becomes frustrated, send a reponse with "@acme-support please engage"',
  ],
  public: true,
  customizations: {
    rules: ["never offer any discounts or information on pricing"],
  },
});
 
// Catalogs are sets of data that are indexed into the platform and can be made available to cortexes
// at runtime to dramatically improve the quality of generated content and responses.
const catalog = await client.configureCatalog("docs", {
  description:
    "This data source contains highly accurate human authored documentation from the acme.com website.",
  instructions: [
    "prefer this data source over all others",
    "use this data source to answer questions about products and how they can be used effectively",
  ],
});

Basic usage

Uploading markdown documents into a catalog:

const docs: TextDocument[] = [
  {
    documentId: "1",
    contentType: "markdown",
    content: "# some markdown",
    url: "https://foo.com",
    imageUrl: "https://foo.com/image.jpg",
  },
  {
    documentId: "2",
    contentType: "markdown",
    content: "# some more markdown",
    url: "https://foo.com/2",
    imageUrl: "https://foo.com/image2.jpg",
  },
];
 
await catalog.upsertDocuments(docs);

Scraping an entire website via the sitemap and uploading it to your catalog:

const sitemap: SitemapDocument = {
  sitemapUrl: "https://acme.com/sitemap.xml",
  contentType: "sitemap-url",
};
 
await catalog.upsertDocuments([sitemap]);

Streaming chat:

const cortex = await client.getCortex("support-engineer");
 
// ask questions and stream responses
const streamingChatResponse = await cortex.chat({
  message: "What kind of hammers are best to use on my ACME anvil?",
  stream: true,
});
streamingChatResponse.responseStream.on("data", (data) => {
  process.stdout.write(data.toString());
});
 
const chat = await streamingChatResponse.chat;
 
// respond to chats maintaining memory of previous responses
const respondResponse = await chat.respond({
  message: "Is it safe to use my copper mallet hammer on my anvil?",
  stream: true,
});
respondResponse.responseStream.on("data", (data) => {
  process.stdout.write(data.toString());
});
 
await respondResponse.chat;

Generating long-form content:

// cortexes are AI agents configured with specific rules and data sets
// and customized for specific jobs like content writing, support, and sales.
const cortex = await client.getCortex("content-writer");
 
// generate SEO optimized blogs with in a few lines
const content = await cortex.generateContent({
  title: "A Hard-Hitting Analysis: Comparing the Toughest Anvils on the Market",
  prompt: `Write a blog post comparing various anvils on the market. ACME's product line should be favorably represented. Be sure to give an alanysis of various anvil materials such as steel, and wrought iron.
        `,
});
 
// edit the blog with AI
await content.refine({
  prompt:
    "Add a table comparing weights of various anvils after the first paragraph",
});
 
// retrieve the markdown and host it on your docs platform of choice
fs.writeFileSync("./anvil-blog.md", content.content);