-
Notifications
You must be signed in to change notification settings - Fork 367
Context retriever quickstart #4116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8da8ce7
Add Context Retriever quickstart
mich-elle-luna b762217
Cross-link Context Retriever quickstart and concepts pages
mich-elle-luna 5c9c1bf
Move Context Retriever self-managed guide under operate/iris
mich-elle-luna b7ec64f
Update content/develop/ai/context-engine/context-retriever/quickstart.md
mich-elle-luna a532a72
Address review feedback on Context Retriever quickstart
mich-elle-luna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
content/develop/ai/context-engine/context-retriever/quickstart.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| --- | ||
| alwaysopen: false | ||
| categories: | ||
| - docs | ||
| - develop | ||
| - ai | ||
| description: Model a data source, generate MCP tools, and call them from an agent using the ctxctl CLI. | ||
| hideListLinks: true | ||
| linktitle: Quickstart | ||
| title: Redis Context Retriever quickstart | ||
| weight: 10 | ||
| bannerText: Redis Context Retriever is currently available in preview. Features and behavior are subject to change. | ||
| --- | ||
|
|
||
| Use this quickstart to model a Redis data source as a context surface, generate the retrieval tools that Context Retriever exposes, and call one of those tools as an agent would. | ||
|
|
||
| This quickstart walks you through: | ||
|
|
||
| 1. [Install the Python client](#install-the-python-client) | ||
| 1. [Sign in and create an admin key](#sign-in-and-create-an-admin-key) | ||
| 1. [Define your data model](#define-your-data-model) | ||
| 1. [Load sample data](#load-sample-data) | ||
| 1. [Create a surface](#create-a-surface) | ||
| 1. [Create an agent key](#create-an-agent-key) | ||
| 1. [List the generated tools](#list-the-generated-tools) | ||
| 1. [Call a tool](#call-a-tool) | ||
| 1. [Clean up](#clean-up) | ||
|
|
||
| This quickstart uses Redis Cloud. If you're running Context Retriever self-managed, see [Install Context Retriever]({{< relref "/operate/iris/context-retriever/self-managed" >}}) instead; every step after sign-in and admin-key creation is the same either way. | ||
|
|
||
| ## Before you begin | ||
|
|
||
| To complete this quickstart, you need: | ||
|
|
||
| * A Redis Cloud account. | ||
| * A Redis Cloud database. If you don't have one, see [Create a database]({{< relref "/operate/rc/databases/create-database" >}}). | ||
| * Python 3.11 or later and `pip`. | ||
| * `redis-cli`, to load sample data. See [Install redis-cli]({{< relref "/operate/oss_and_stack/install/install-stack/install-redis-cli" >}}). | ||
|
|
||
| ## Install the Python client | ||
|
|
||
| The Python client includes the `ctxctl` CLI, which you use to model data, manage keys, and call the tools Context Retriever generates. | ||
|
|
||
| ```bash | ||
| pip install redis-context-retriever | ||
| ``` | ||
|
|
||
| ## Sign in and create an admin key | ||
|
|
||
| 1. Start a session against your Redis Cloud account: | ||
|
|
||
| ```bash | ||
| ctxctl auth login -u <your-redis-cloud-email> | ||
| ``` | ||
|
|
||
| 1. Create an admin key. An admin key authorizes operations such as creating surfaces and agent keys. | ||
|
|
||
| ```bash | ||
| ctxctl --output json admin create --name "quickstart-admin" | ||
| ``` | ||
|
|
||
| 1. Save the returned key. Export it so later commands can use it: | ||
|
|
||
| ```bash | ||
| export CTX_ADMIN_KEY='<the returned key, starts with cs_admin_>' | ||
| ``` | ||
|
|
||
| This quickstart uses a Redis Cloud account for sign-in and admin-key creation. If you're running Context Retriever self-managed instead, see [Install Context Retriever]({{< relref "/operate/iris/context-retriever/self-managed" >}}) to bootstrap your first admin key. Every other step in this quickstart applies to both. | ||
|
|
||
| ## Define your data model | ||
|
|
||
| Context Retriever generates tools from a data model, not from CLI flags entered one field at a time. Define your entities in a Python file. | ||
|
|
||
| Create `models.py`: | ||
|
|
||
| ```python | ||
| from context_surfaces.context_model import ContextField, ContextModel | ||
|
|
||
| class Customer(ContextModel): | ||
| __redis_key_template__ = "customer:{id}" | ||
|
|
||
| id: str = ContextField(description="Unique customer ID", is_key_component=True) | ||
| name: str = ContextField(description="Customer name", index="text") | ||
| email: str = ContextField(description="Customer email address", index="tag") | ||
| ``` | ||
|
|
||
| ## Load sample data | ||
|
|
||
| Load a few customer hashes that match the model, so the tool call later in this quickstart returns predictable results: | ||
|
|
||
| ```bash | ||
| redis-cli -h <your-database-host> -p <port> -a '<your-database-password>' HSET customer:1 id 1 name "Jane Doe" email "jane.doe@example.com" | ||
| redis-cli -h <your-database-host> -p <port> -a '<your-database-password>' HSET customer:2 id 2 name "John Smith" email "john.smith@example.com" | ||
| redis-cli -h <your-database-host> -p <port> -a '<your-database-password>' HSET customer:3 id 3 name "Jane Roberts" email "jane.roberts@example.com" | ||
| ``` | ||
|
|
||
| If you already have data that matches this shape, you can skip this step and use your own keys instead. | ||
|
|
||
| ## Create a surface | ||
|
|
||
| 1. Create a context surface from your model file, pointing it at your Redis Cloud database: | ||
|
|
||
| ```bash | ||
| ctxctl --output json surface create \ | ||
| --name "quickstart-surface" \ | ||
| --description "Quickstart context surface" \ | ||
| --models ./models.py \ | ||
| --redis-addr <your-database-host>:<port> \ | ||
| --redis-password '<your-database-password>' \ | ||
| --admin-key "$CTX_ADMIN_KEY" | ||
| ``` | ||
|
|
||
| 1. Save the returned surface ID: | ||
|
|
||
| ```bash | ||
| export CTX_SURFACE_ID='<the returned surface id>' | ||
| ``` | ||
|
|
||
| 1. Confirm the surface was created: | ||
|
|
||
| ```bash | ||
| ctxctl surface describe "$CTX_SURFACE_ID" --admin-key "$CTX_ADMIN_KEY" | ||
| ``` | ||
|
|
||
| ## Create an agent key | ||
|
|
||
| An agent key authorizes an agent to call the tools generated for a surface. | ||
|
|
||
| 1. Create one scoped to the surface you just created: | ||
|
|
||
| ```bash | ||
| ctxctl --output json agent create \ | ||
| --surface-id "$CTX_SURFACE_ID" \ | ||
| --name "quickstart-agent" \ | ||
| --admin-key "$CTX_ADMIN_KEY" | ||
| ``` | ||
|
|
||
| 1. Save the returned key: | ||
|
|
||
| ```bash | ||
| export CTX_AGENT_KEY='<the returned key, starts with cs_agent_>' | ||
| ``` | ||
|
|
||
| ## List the generated tools | ||
|
|
||
| As the admin, confirm which tools Context Retriever generated from your model: | ||
|
|
||
| ```bash | ||
| ctxctl tools list --agent-key "$CTX_AGENT_KEY" | ||
| ``` | ||
|
|
||
| The list includes tools such as a search tool and a get-by-ID tool for each entity you defined. | ||
|
|
||
| ## Call a tool | ||
|
|
||
| Call a generated tool directly, using the agent key instead of the admin key: | ||
|
|
||
| ```bash | ||
| ctxctl tools call search_customer_by_text --agent-key "$CTX_AGENT_KEY" --args '{"query": "jane", "limit": 5}' | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > **What to expect:** A JSON result containing `Jane Doe` and `Jane Roberts`, the two sample customers whose `name` field matches `jane`. The agent never sends a database query directly. It calls a tool that Context Retriever generated from your model. | ||
|
|
||
| ## Clean up | ||
|
|
||
| Delete the surface you created, which also revokes its agent keys: | ||
|
|
||
| ```bash | ||
| ctxctl surface delete "$CTX_SURFACE_ID" --admin-key "$CTX_ADMIN_KEY" --confirm | ||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| * Read [Context Retriever concepts]({{< relref "/develop/ai/context-engine/context-retriever/concepts" >}}) to understand tools, providers, and access tags. | ||
| * [Create a Context Retriever service in Redis Cloud]({{< relref "/operate/iris/context-retriever/create-service" >}}) using the console instead of the CLI. | ||
| * [Manage admin keys]({{< relref "/operate/iris/context-retriever/view-admin-keys" >}}). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
...ngine/context-retriever/install/_index.md → .../context-retriever/self-managed/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.