Context0 Quick Start
This topic describes how to activate Context0, obtain endpoints and API Keys, and complete your first integration through CLI plugins, direct API access, or knowledge sync.
Scope of application
Requirement | Description |
Alibaba Cloud account | Used to log on to the PolarDB-X console |
PolarDB-X instance | A PolarDB-X Standard or Enterprise Edition instance is purchased |
Context0 requires a PolarDB-X Search instance (OpenSearch-compatible) for vector and full-text storage in the same region | |
Node.js ≥ 22 | Required only for Path A (CLI plugin) |
Step 1: Activate Context0
Context0 is an AI-enhanced capability of PolarDB-X. You must manually activate it in the console.
1. Go to the Context0 page
Log on to the PolarDB-X console. In the instance list, click the name of the target PolarDB-X instance.
In the left-side navigation pane, expand AI Capability and click Context Service.
2. Create a Context0 instance
On the Context0 page, click Create Context Service in the upper-right corner.
In the creation panel, select a Search instance in the same region as the dependent vector store.
Confirm and click the Create Context Service button in the lower-right corner.
Wait until the instance status changes from Creating to Running. Activation is complete.
Step 2: Obtain endpoints and credentials
After the Context0 instance is created, go to the instance details page to obtain connection information and API Keys.
Connection information
Click the Basic Information tab. The Connection Information section displays the following endpoints:
Address type | Hostname format | Port | Usage |
VPC Address (service) |
| 4040 | Agent / SDK / API direct access to data plane APIs ( |
Public Address (service) | Same as above (assigned after activation) | Custom | Call data plane APIs from the public internet |
Dashboard VPC Address |
| 8080 | Browser access to the Context0 dashboard |
Dashboard Public Address | Same as above (assigned after activation) | Custom | Access the Context0 dashboard from the public internet |
Hostname suffix description: In the hostname, -s indicates the service (data plane), and -d indicates the dashboard (control plane). These are different endpoints. Do not mix them.
Public access: VPC endpoints are reachable only within the VPC. To access from the public internet, click Enable Now in the corresponding row.
In subsequent API calls, $HOST uses the service endpoint (VPC or public). Example format:
http://pxt-xxxx-s.polarxcontextdb.rds.aliyuncs.com:4040Configuration and Management (Admin Key / Owner Key)
Click the Configuration and Management tab. The table displays the key credentials of the current instance:
Field | Example | Description |
Context0 Logical Instance Name |
| Context0 instance identifier |
Admin Key |
| Platform-level admin credential |
Owner Key |
| Workspace-level business credential |
Dependent PolarDB-X Instance Name |
| Underlying relational storage |
Dependent PolarDB-X Search Instance Name |
| Underlying vector and full-text storage |
Each key has Show and Copy buttons. Click to obtain the full credential.
Admin Key vs. Owner Key comparison
Dimension | Admin Key | Owner Key |
Level | Platform-level (unique per instance) | Tenant-level (per workspace) |
Binding | Bound to the entire Context0 instance | 1:1 binding with a single workspace |
Primary use |
|
|
Data plane access | Cannot be used for | Use directly as |
Uniqueness | One per Context0 instance | One per workspace; additional keys can be issued via Admin Key |
Security notice: Admin Key has elevated privileges. Keep it secure and use it only for administrative operations such as creating workspaces. For daily agent access, use Owner Key or a USER Key issued by the Owner.
Key type overview
Type | Permission scope | Typical user |
ADMIN | Platform-level: create/delete workspaces, issue/revoke OWNER Keys | Platform administrator |
OWNER | Full workspace permissions: data plane access, manage members, issue USER Keys | Team lead |
USER | Bound to a single member; access only own memories/sessions | End-user agents |
After activation, use Configuration and Management to obtain the Admin Key and the first Owner Key.
Owner Key can issue USER Keys for each member to distribute to agents.
For general agent access, use USER Keys (principle of least privilege).
Log on to the Context0 dashboard
Open the dashboard URL in a browser (use the VPC endpoint within a VPC, or the public endpoint if enabled):
http://pxt-xxxx-d.polarxcontextdb.rds.aliyuncs.com:8080After logging on, you can:
Workspace management (create/edit workspaces, assign members)
Memory and knowledge browsing (view, search, delete memory entries)
Member and permission management
Usage monitoring and audit logs
Feature flag management (enable/disable and canary releases)
Provider configuration (Embedding / LLM / Rerank model provider management)
GDPR compliance operations (data erasure and export)
Monitoring dashboard (Prometheus metrics, real-time operations dashboard)
Step 3: Choose an access method
Path | Use case | Coding required |
A: CLI plugin | AI coding tools such as Qoder / Claude Code / Codex | No |
B: Direct API | Custom agents and business system integration | Yes |
C: Knowledge sync | Bulk import DingTalk/Feishu documents into knowledge base | No |
Path A: CLI plugin
ctxdb0 is the access layer plugin for Context0 (Hooks + CLI + static Skills). After installation, AI coding tools automatically capture context in the background and can read/write memories and search the knowledge base via CLI.
1. Install
npm install -g @polardbx/ctxdb02. Configure
First establish a connection, then install to the target AI tool:
CTXDB0_API_KEY is the Owner Key from the console. You can also use a User Key assigned by the Owner Key.
printf '%s' "$CTXDB0_API_KEY" | ctxdb0 connect \
--profile default \
--endpoint http://<your-endpoint> \
--user-id <end-user-identifier> \
--api-key-stdin \
--json
ctxdb0 attach --host claude --json
ctxdb0 doctor --host claude --jsonuser-id recommendation: Always provide
--user-idwhen runningconnect. If omitted, the Prompt Hook skips automatic memory recall to prevent OWNER credentials from inadvertently expanding the recall scope; explicit CLI operations are unaffected.
--host values:
AI tool | --host value | Installation path |
Claude Code |
|
|
Qoder |
|
|
QoderWork |
|
|
Codex |
| Codex plugin marketplace (review and trust the Hook in |
Hermes |
|
|
ctxdb0 does not include a stdio MCP Server and does not support MCP protocol access. Native MCP is a separate Context0 capability that must be configured independently per the backend MCP design documentation.
3. Verify
ctxdb0 doctor --host claude --jsondoctor checks the connection profile and API reachability, host installation status, and managed asset integrity. If all checks pass, the setup is complete.
4. How it works
The plugin consists of three components:
Lifecycle Hooks (automatic): Injects historical context at session start; automatically submits each completed round to the backend for asynchronous long-term memory extraction.
Explicit CLI (manual): Agents call
ctxdb0 memory / knowledge / sessions / skillsand other commands on demand to read/write memories and search the knowledge base.Static Skill (guidance): Installs the
ctxdb0-contextSkill with the plugin. Agents automatically select appropriate CLI commands based on user natural language.
5. Command reference
All commands support --json. Agents should always include this flag.
# Connection and diagnostics
ctxdb0 connect --profile <name> --endpoint <url> --user-id <id> --api-key-stdin --json
ctxdb0 setup --host <host> --endpoint <url> --user-id <id> --api-key-stdin --json
ctxdb0 attach --host <host> --json
ctxdb0 doctor --host <host> --json
ctxdb0 config show --json
ctxdb0 refresh --host <host> --json
# Memory
printf '%s' 'Project uses TypeScript + Prisma' | ctxdb0 memory remember --stdin --json
ctxdb0 memory recall 'tech stack selection' --limit 5 --json
ctxdb0 memory browse --offset 0 --limit 20 --json
ctxdb0 memory show <memory-id> --json
printf '%s' 'replacement content' | ctxdb0 memory revise <memory-id> --stdin --json
ctxdb0 memory forget <memory-id> --confirm-id <memory-id> --json
# Knowledge base
ctxdb0 knowledge sources --json
ctxdb0 knowledge sources create --name <name> --description '<description>' --json
ctxdb0 knowledge query 'canary release requirements' --source <source> --json
ctxdb0 knowledge documents --source <source> --json
ctxdb0 knowledge documents show <document-id> --source <source> --json
ctxdb0 knowledge import --source <source> --file ./docs/adr.md --json
# Sessions and managed Skills
ctxdb0 sessions browse --page 0 --limit 20 --json
ctxdb0 sessions restore <session-id> --json
ctxdb0 skills search 'incident response' --json
ctxdb0 skills fetch <skill-id> --json
# Migration and cleanup
ctxdb0 migrate --plan --json
ctxdb0 migrate --apply --confirm <confirmation-token> --json
ctxdb0 purge --plan --json
ctxdb0 purge --confirm <confirmation-token> --json
# Uninstall
ctxdb0 detach --host <host> --json6. Configuration
connect writes non-sensitive configuration to ~/.ctxdb0/plugin/config.json. The API Key is stored separately in credentials.json with 0600 permissions. Default behavior configuration:
Field | Default | Description |
|
| Prompt Hook memory recall strategy: |
|
| Token budget for session startup context injection |
|
| Token budget for prompt memory recall |
|
| Whether to automatically query the knowledge base during the prompt phase; when enabled, the knowledge source ID scope must be fixed |
|
| List of knowledge source IDs to query when enabled |
|
| Scope origin tag ( |
|
|
|
|
| Maximum document chunks per Prompt-KB recall |
|
| Switch to session batch mode (save raw messages per round, extract at session end) |
|
| Debug switch |
Behavior configuration is modified via CLI:
ctxdb0 config set recall-mode intent --json
ctxdb0 config set session-batch off --json
ctxdb0 config set prompt-knowledge-recall off --json
# Enable Prompt-KB recall (specify knowledge source name)
ctxdb0 config set prompt-knowledge-recall on --source <name> --json
# Use all currently accessible knowledge sources (snapshot fixed to configuration)
ctxdb0 config set prompt-knowledge-recall on --all-accessible --json--source (repeatable) and --all-accessible are mutually exclusive. Empty scope, ambiguous names, non-existent sources, insufficient permissions, or more than 100 knowledge sources will all fail and disable the feature.
Project-level override: place .ctxdb0.json in the project root directory. It can only tighten global configuration (reduce recall mode, disable session batch, disable Prompt-KB recall), and cannot select profiles, endpoints, or relax behavior. No credential fields are allowed.
Path B: Direct API
Prerequisites
All requests must include the X-API-Key header. Set environment variables first:
export API_KEY="<YOUR_API_KEY>"
export HOST="http://<your-endpoint>"Authentication supports three equivalent header formats:
-H "X-API-Key: $API_KEY" # recommended
-H "Authorization: Token $API_KEY"
-H "Authorization: Bearer $API_KEY"1. Verify connectivity (whoami)
curl "$HOST/v1/auth/whoami" \
-H "X-API-Key: $API_KEY"Response:
{
"code": 0,
"msg": "ok",
"data": {
"authenticated": true,
"workspace_id": 1,
"member_id": 1,
"key_type": "USER",
"bound_user_id": "user_001"
}
}data.authenticated being true means the connection is successful.
2. Write conversations (ingest)
Write conversations to a session. The server asynchronously extracts memories:
curl -X POST "$HOST/v1/context/ingest" \
-H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
-d '{
"session_id": "sess_789",
"user_id": "user_001",
"agent_id": "my-agent",
"messages": [
{"role": "user", "content": "I want to deploy my app with Docker"},
{"role": "assistant", "content": "You can use Docker Compose to start the stack with one command"}
]
}'Response:
{
"code": 0,
"data": {
"session_id": "sess_789",
"session_internal_id": 1234,
"message_ids": [{"id": 1001, "seq": 1}, {"id": 1002, "seq": 2}],
"event_id": 99001
}
}3. Assemble context (assemble)
Recall relevant memories and knowledge by query, select the best within the token_budget, and output prompt_blocks that can be directly appended to the system prompt:
curl -X POST "$HOST/v1/context/assemble" \
-H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
-d '{
"session_id": "sess_789",
"user_id": "user_001",
"query": "How to deploy the app?",
"token_budget": 4000,
"recall": {"top_k": 8}
}'Response (excerpt):
{
"code": 0,
"data": {
"prompt_blocks": [
{"role": "system", "tag": "user_profile", "content": "User prefers Docker deployment", "tokens": 20, "sources": []}
],
"token_used": 255,
"token_budget": 4000,
"trace_id": "550e8400-..."
}
}When using a USER Key, user_id must match the bound_user_id of the Key; otherwise, a 403 error is returned. Owner Key has no such restriction.
4. Search memories (search)
Search long-term memories by semantics (vector + BM25 hybrid):
curl -X POST "$HOST/v2/memories/search" \
-H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
-d '{
"query": "tech stack selection",
"user_id": "user_001",
"limit": 10
}'Response (raw JSON array):
[
{"id": "mem_123", "memory": "Project uses TypeScript + Prisma", "score": 0.92, "user_id": "user_001"},
{"id": "mem_124", "memory": "Auth solution: NextAuth", "score": 0.85, "user_id": "user_001"}
]For more APIs, see User guide.
Path C: Knowledge sync (DingTalk / Feishu)
ctxdb0-sync batch syncs DingTalk or Feishu documents into the Context0 knowledge base with incremental updates and deduplication.
# Install
npm install -g @polardbx/ctxdb0-sync
# Sync Feishu knowledge space to knowledge base ID=1
ctxdb0-sync run \
--provider feishu \
--space-id <feishu-space-id> \
--kb-id 1 \
--api-key <YOUR_API_KEY> \
--base-url http://<your-endpoint>
# Sync DingTalk knowledge base (pre-authenticated MCP URL; no separate appKey/appSecret required)
ctxdb0-sync run \
--provider dingtalk \
--workspace-id <dingtalk-workspace-id> \
--endpoint "https://mcp-gw.dingtalk.com/server/XXXX?key=your_key" \
--kb-id 1 \
--api-key <YOUR_API_KEY> \
--base-url http://<your-endpoint>DingTalk MCP endpoint: DingTalk MCP Marketplace → Enterprise admin logon → Search for "DingTalk Docs" → Get MCP Server configuration → Copy the URL. This URL already contains authentication credentials.
Supported data sources:
Provider | --provider | Credentials |
Feishu Docs |
|
|
DingTalk Knowledge Base |
| Pre-authenticated MCP URL (endpoint contains |
Local directory |
| None ( |
Sync is incremental based on content hashing. Unchanged documents are automatically skipped. Add --dry-run to preview changes without writing.
What to do next
User guide: Detailed usage of memories, knowledge base, context assembly, memory promotion, and more.
FAQ
ctxdb0 doctorcheck fails: Verify the endpoint and API Key used duringconnect.whoamireturnsauthenticated: false: The key is invalid or has been revoked. Reissue it in the console.Memories not appearing: The plugin submits each round to the backend for asynchronous extraction by default. Wait a moment. To write manually, use
ctxdb0 memory remember.