Skip to main content
These are the HTTP doors for the Knowledge Base shelf.

What this means in practice

Important endpoint families include:
  • list/create knowledge bases
  • patch knowledge-base metadata and scope policy
  • import chunks
  • query a knowledge base
  • backfill or maintenance-related KB flows

How it actually works

Key repo surfaces:
  • convex/crystal/knowledgeHttp.ts
  • convex/crystal/knowledgeBases.ts
  • packages/mcp-server/README.md

Endpoint Reference

List Knowledge Bases

GET /api/knowledge-bases

Retrieve all knowledge bases for the authenticated user. This endpoint is agent/scope aware when you pass query parameters like:
  • agentId
  • scope
Request:
Response:

Create Knowledge Base

POST /api/knowledge-bases

Create a new knowledge base. Request:
Response:

Import Chunks

POST /api/knowledge-bases/:knowledgeBaseId/import

Bulk-import document chunks into a knowledge base. Request:
Response:
Upsert by key. Give a chunk a stable dedupeKey (e.g. a title or slug) to replace the existing chunk with the same (knowledgeBaseId, dedupeKey) in place — one key = one chunk — instead of appending a duplicate. Re-importing a key edits that chunk (content, title) and re-embeds it; keyless chunks append as before.
The response includes importedCount (newly inserted) and updatedCount (upsert-replaced). Behavior:
  • Each chunk is embedded using the same model as memories (text-embedding-3-small)
  • With a dedupeKey, re-imports replace the matching chunk in place (no duplicate)
  • Without a dedupeKey, duplicate chunks are deduplicated within the batch by SHA256 of content
  • Failed chunks are logged but don’t block the import

Enumerate Chunks

GET /api/knowledge-bases/:knowledgeBaseId/memories

Walk every chunk in a KB with real cursor pagination and ids — unlike the relevance-capped query endpoint, this enumerates the whole KB so an agent can inspect, clean, or update it programmatically. Query params: limit (1–200, default 100) and cursor (pass the previous response’s continueCursor). Response:
Each returned id works with POST /api/mcp/update (edit content in place) and POST /api/mcp/forget (delete). Page until isDone is true.

Empty a Knowledge Base

POST /api/knowledge-bases/:knowledgeBaseId/empty

Delete all chunks while keeping the KB row, id, and agent bindings, so you can re-import into the same id without re-pointing agents. Returns { deletedMemories, kept: true }.

Patch Knowledge Base

PATCH /api/knowledge-bases/:knowledgeBaseId

Update metadata and visibility policy. Example:
Use this when converting a KB from agent-private to shared-open access under one API key.

Query Knowledge Base

POST /api/knowledge-bases/:knowledgeBaseId/query

Vector search a knowledge base by semantic query. Request:
Response:
Chunk-level peer scope filter (new in 0.7.15). Both the queryKnowledgeBase action and the internal KB-chunk reader now apply a chunk-level peer scope filter that mirrors the KB-level visibility guard. A permissive shared KB will return its parent-scoped chunks plus chunks explicitly scoped to the requesting peer. Cross-peer chunks are dropped. Trailing-colon channels (e.g. peer-coach:) fail closed and return no chunks.
Parameters:
  • query (required): The semantic query string
  • limit (optional): Maximum results to return (default: 10, max: 50)
  • threshold (optional): Minimum relevance score 0–1 (default: 0.0, all results)
  • agentId (optional): Agent visibility context
  • channel (optional): Channel/scope context

Usage Patterns

Example 1: Import API Documentation

Example 2: Query Documentation Before Response

In an agent workflow:

Scope and Tenancy

Knowledge bases are:
  • Per-user — isolated by userId from authentication token
  • Agent/scope aware — visibility can differ for peer-scoped vs shared-main agent lanes
  • Persistent — survive session restarts

Shared-main KB pattern

To make one training KB available to many agents/chats under one key:
  • set scope to something like peer-team:main
  • set peerScopePolicy to "permissive"
  • include all allowed agent IDs in agentIds
To keep private client notes private:
  • keep agentIds: ["coach"]
  • do not move them to a shared :main scope

Common mistakes

  • documenting KB endpoints without mentioning their relationship to the MCP KB tools
  • assuming imported data is the same as conversational memory
  • ignoring scope and tenancy when describing KB behavior

Source of truth

Primary files behind this page:
  • convex/crystal/knowledgeHttp.ts
  • convex/crystal/knowledgeBases.ts
  • packages/mcp-server/README.md