﻿---
title: Context Engine quickstart
description: Hands-on tutorial for creating reusable context from existing Elasticsearch data and testing it with an Agent Builder agent.
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/quickstart
products:
  - Elastic Documentation
  - Elastic Observability
  - Elastic Security
  - Elasticsearch
  - Kibana
applies_to:
  - Elastic Cloud Serverless: Experimental
  - Elastic Stack: Planned
---

# Context Engine quickstart
<important>
  This page is currently hidden from the documentation navigation.The following Context Engine pages are live:
  - [Landing page](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine)
    - [Context Engine quickstart](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/quickstart)
  - [Context Engine concepts](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/concepts)
  - [Build and maintain an AI index](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/build-and-maintain-ai-index)
    - [Create and manage AI indices](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/create-and-manage-ai-indices)
  - [Add and manage sources](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/add-and-manage-sources)
  - [Create and manage automations](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/create-and-manage-automations)
  - [Manage KIs](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/inspect-and-manage-knowledge-indicators)
  - [Evaluate and improve KIs](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/evaluate-and-improve-knowledge-indicators)
  - [Use an AI index](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/use-an-ai-index)
    - [Retrieve context](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/retrieve-context-from-ai-index)
  - [Save and retrieve memories](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/save-and-retrieve-memories)
  - [Configure agents to use an AI index](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/use-context-engine-with-agents)
    - [Use Context Engine with Agent Builder](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/use-context-engine-with-agent-builder)
  - [Query AI indices from LangChain](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/langchain-integration)
  - [Context Engine APIs](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/context-engine-api)
</important>

In this tutorial, you follow the complete Kibana and Elastic Agent Builder path from data already stored in Elasticsearch to Knowledge Indicators (KIs) that an agent can retrieve. You can use your own data or the Kibana sample ecommerce data.
Suppose an agent regularly answers questions about an Elasticsearch index. Without reusable context, it might first inspect the mapping, interpret the fields, and construct suitable queries. This tutorial generates KIs that give the agent that orientation and query guidance up front.

## Tutorial outcome

By the end of this tutorial, an Elastic Agent Builder agent can retrieve KIs generated from your selected Elasticsearch data. The KIs describe what the data contains and how to query it with verified ES|QL.
An automation, implemented as a workflow in [Elastic Workflows](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/workflows), generates the KIs and can refresh them when the source changes.

## Before you begin

You need:
- An Elastic Stack 9.6 deployment with an Enterprise license, or an Elastic Cloud Serverless project.
- Permission to change Advanced Settings in the current Kibana space.
- Permission to [create and run workflows](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/workflows/get-started/setup) and manage Context Engine AI indices.
- Elasticsearch data that you can read. If you do not have suitable data, install the [**Sample eCommerce orders** data](https://www.elastic.co/docs/manage-data/ingest/sample-data#add-sample-data-sets), which creates the `kibana_sample_data_ecommerce` index.

Starting with existing data matters. An AI index does not ingest source data by itself. Its sources identify the data that an automation can use to generate KIs.

## 1. Enable Context Engine

Turn on Context Engine for the current Kibana space:
1. In Kibana, open **Stack Management → Advanced Settings**.
2. Search for **Context Engine**.
3. Turn on **Context Engine** (`contextEngine:enabled`).
4. Open **Context** from the Kibana navigation.

This setting applies to the current Kibana space.

## 2. Create an AI index

An AI index stores KIs for a particular purpose. Its name and description also help agents decide whether it is relevant to a question.
Create the AI index:
1. Select **Create AI Index**.
2. Enter a name that identifies the knowledge the AI index will contain. For example, enter `ecommerce-orders` if you are using the sample data.
3. Add a description that identifies the data and the questions it should support. For example:
   > Context about ecommerce orders, including customers, products, order value, and sales trends. It should help answer questions about revenue, top products, and customer activity. It does not contain inventory, fulfillment, returns, or payment data.
4. Select **Create AI index**.

The AI index initially has no sources, automations, or KIs. You must add a source before you can create an automation.

## 3. Add the source data

A source identifies the data that the automation can analyze. For this tutorial, select one Elasticsearch index, data stream, or alias.
Add a source to the AI index:
1. In **Sources**, select **Add sources**.
2. On the **Elasticsearch data** tab, start typing the name of an index, data stream, or alias. If you are using the ecommerce sample data, enter `kibana_sample_data_ecommerce`.
3. Select the matching result.
4. Confirm that the source appears under **Selected sources**, then select **Save**.

Selecting an index, data stream, or alias creates an ES|QL source in the form `FROM <name>`. You can use **Advanced: ES|QL** to define a narrower source, but that is not necessary for this tutorial.

## 4. Create the automation

This tutorial uses the guided route, where Elastic Agent Builder creates the automation for you. For an AI index without an automation, Elastic Agent Builder has no default generation strategy. It chooses one from the shape of your data, such as one KI for each document, or one KI for each recurring entity, like a customer or a product.
Create the automation:
1. In **Automations**, select **Add automation** → **Create with AI Agent**.
2. Elastic Agent Builder opens a conversation and sends **Suggest an automation for this AI index.**
3. Review the strategy that Elastic Agent Builder names and the evidence it cites from your data. Confirm that it uses the intended source index.
4. For the ecommerce sample data, Elastic Agent Builder names **Cumulative / Wiki-style** and asks whether to profile products, customers, or both. Select an option, then select **Submit**.

What happens next depends on the strategy:
- **Index/Table Metadata, Bottom-Up, Cumulative / Wiki-style, and Targeted KI**: Elastic Agent Builder installs a template and attaches the workflow. The install has no confirmation prompt. If it asks which entity to profile, or which strategy to use, answer that question first.
- **Other strategies**: Elastic Agent Builder describes a plan and asks you to confirm before it builds and pilots a workflow.

Installing the automation does not run it. For each path, refer to [Create an automation with Agent Builder](/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/create-and-manage-automations#create-an-automation-with-agent-builder).
<note>
  **Add automation** → **Create workflow** is the manual route. It opens a new, disabled workflow in the [Workflows YAML editor](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/workflows/authoring-techniques/use-yaml-editor) with a manual trigger and generic starter YAML. Use it when you intend to author the KI-generation workflow yourself.
</note>


## 5. Run the automation and inspect the Knowledge Indicators

Run the automation and inspect its output:
1. If the run would write more than five KIs, select **Run pilot**. **Cancel** is the other button. A workflow that Elastic Agent Builder already piloted skips this step.
2. When Elastic Agent Builder asks to start the full run, select **Run automation**. After a successful pilot, it also estimates how long the full run takes.
3. If the pilot fails, or doesn't write a KI for each item, Elastic Agent Builder reports the problem and stops.
4. The full run continues in the background. Ask Elastic Agent Builder for a progress update until the run completes.
5. Return to the AI index in **Context**, then open **Knowledge Indicators**.
6. Open the KIs that the run wrote and confirm that they describe the intended data and include useful ES|QL access patterns.

For a detailed review process, refer to [Evaluate and improve Knowledge Indicators](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/evaluate-and-improve-knowledge-indicators).

## 6. Make the AI index available to an agent

Add the populated AI index to an Agent Builder agent:
1. Open **Agent Builder**.
2. Create an agent or edit an existing one.
3. In **AI Indices**, add the AI index under **Additional indices**.
4. Save the agent.

The assignment makes the AI index and the dedicated Context Engine retrieval tools available to the agent. Its name and description help the agent decide when to retrieve its KIs. For details about the tools, source-data access, and custom instructions, refer to [Use Context Engine with Elastic Agent Builder](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/use-context-engine-with-agent-builder).

## 7. Test how the agent uses the Knowledge Indicators

Ask the agent questions that exercise both kinds of context:
1. Ask a question that a KI can answer from its distilled content.
2. Ask for current or detailed information that requires a verified ES|QL query from one of the KIs.

For the ecommerce sample data, ask about something a KI describes, then ask for a current revenue breakdown by manufacturer. Check whether the agent answers from a KI or queries the source data. Which one it uses depends on the strategy Elastic Agent Builder chose.
Confirm that the agent:
- Selects the relevant AI index
- Retrieves a KI as context
- Answers directly when the KI contains the required knowledge
- Uses targeted ES|QL against the source when current detail is required

KIs can reduce the time and model tokens agents spend exploring source data. They provide reusable knowledge and tested query guidance while preserving access to current source data.

## Next steps

After completing this tutorial, you can:
- [Add or refine sources](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/add-and-manage-sources) to control the data that automations analyze.
- [Create, run, and schedule automations](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/create-and-manage-automations) that use other generation strategies.
- [Evaluate and improve the generated KIs](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/evaluate-and-improve-knowledge-indicators).
- [Use the AI index](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9070/explore-analyze/ai-features/context-engine/use-an-ai-index) through APIs or another agent integration.