Skip to main content
Query a knowledge base to search for relevant chunks by semantic similarity. KB query is the correct path for named reference material. It does not perform broad account recall first. The backend resolves KB visibility from the authenticated user plus agentId, channel, KB scope, and peer policy, then searches chunks in that KB. Returned chunks can include compact graph context when includeGraphContext is enabled.

What this means in practice

When you have organized information into a knowledge base (via import or chunking), use crystal_query_knowledge_base to:
  • Retrieve relevant information by semantic meaning (not just keyword match)
  • Scope queries to a specific knowledge base
  • Filter by agent or channel if the knowledge base supports it
  • Limit results to reduce noise and context overhead
This matters most for mixed private/shared deployments:
  • private KBs can stay peer-scoped for coach/client isolation
  • shared training KBs can live at scope: "...:main" with peerScopePolicy: "permissive"
  • the backend now supports querying those shared-main KBs from peer-scoped coach sessions when the agent is allowed

Parameters

Returns

Examples

Basic query by name:
Query by ID with result limit:
Scoped query for a specific agent:
Shared-main KB queried from a peer-scoped coach session:

When to use vs alternatives

Error handling

Source of truth

  • mcp-server/src/tools/query-knowledge-base.ts — tool definition and HTTP handler
  • convex/crystal/knowledgeBases.ts — backend query logic
  • apps/web/app/(dashboard)/knowledge-bases/ — KB management UI

Notes

Chunk-level peer scope filter (new in 0.7.15)

Both the queryKnowledgeBase action and the internal getKBMemoriesInternal path 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.

Source-role ranking

Direct KB query searches only the selected KB, but the KB’s sourceRole is still returned so agents can interpret why the source was retrieved. Broad recall also uses that role as a ranking signal; for example a voice_style KB can outrank social artifacts for voice or phrasing questions.