Appearance
Knowledge Base and RAG
The AI module lets each agent maintain its own document-backed knowledge base, then exposes that knowledge through a retrieval tool during chat execution.
Controller Surface
GET /agent/:agentId/knowledge/documentsPOST /agent/:agentId/knowledge/documentsDELETE /agent/:agentId/knowledge/documents/:docId
These routes are implemented in source but are not live yet because the module is not mounted.
Knowledge Document Contract
Adding a document requires:
fileNamedescriptionlanguages3KeycontentType
The module persists the row immediately with status pending, then continues processing asynchronously through an event handler.
Indexing Pipeline
KnowledgeDocumentAddedEvent performs the full indexing flow:
- Load the document and agent.
- Mark the document as
processing. - Resolve a download URL for the stored file.
- Download the file content.
- Parse
application/pdf, Word documents, ortext/*payloads. - Split the extracted text using the agent's chunk settings.
- Generate embeddings in batches of 50.
- Ensure the Qdrant collection exists.
- Upsert one vector point per chunk.
- Mark the document as
completedorfailed.
Each embedding batch also emits token accounting events under the DocumentIndexing action.
Retrieval Tool
- Agents with
knowledge.isEnabled=trueautomatically receive thesearch-knowledge-basetool. - The tool embeds the query, searches the agent's Qdrant collection, and returns the best fragments that survive adaptive thresholding.
- Query embeddings are tracked as token usage under the
RagQueryEmbeddingaction. - Retrieved fragments include the source text and a relevance score.
Defaults and Tuning
- knowledge is disabled by default for new agents
- default chunk size is
700 - default chunk overlap is
150 - default similarity threshold is
0.35 - default result limit is
5 - default embedding model is
openai/text-embedding-3-small
Delete Behavior
- Removing a knowledge document first attempts to delete matching Qdrant points by
documentId. - The command then deletes the metadata row from PostgreSQL.
- After database deletion, the module publishes
KnowledgeDocumentRemovedEventso the original file can be deleted from storage.
Current Gaps
The knowledge flow is not fully production-ready yet:
FileDownloadAdaptercurrently always throwsFile not found for key: ..., so document ingestion cannot succeed end-to-end.FileDeletionAdapteris a no-op, so file cleanup is not actually requested after document removal.- The update command intentionally blocks embedding-model changes, because re-embedding and collection migration are not implemented.
Structured Error Contract
| Code | HTTP | Meaning |
|---|---|---|
AI.AGENT_NOT_FOUND | 404 | The target agent does not exist. |
AI.AGENT_HAS_NO_KNOWLEDGE_CONFIG | 400 | Knowledge operations were attempted for an agent without a usable knowledge config. |
AI.DOCUMENT_NOT_FOUND | 404 | The target knowledge document does not exist for that agent. |
AI.UNEXPECTED_ERROR | 500 | Persistence or integration failure while saving or deleting the document row. |