In this area
Knowledge Base
Manage knowledge bases and documents; run semantic search (RAG).
Semantic search across the knowledge base
get/v1/public/knowledge-base/search
Returns the top matching chunks ranked by hybrid (semantic + keyword) score. Use this from external AI agents or MCP clients to ground answers in your KB.
Parameters
knowledgeBaseIdstringoptional· query- Restrict search to a single knowledge base. Omit to search across all.
limitnumberoptional· query- Number of results to return. Range 1–20, default 5.
querystringrequired· query
| Field | In | Type | Description |
|---|---|---|---|
knowledgeBaseIdoptional | query | string | Restrict search to a single knowledge base. Omit to search across all. |
limitoptional | query | number | Number of results to return. Range 1–20, default 5. |
queryrequired | query | string |
Responses
200
Examples
curl -X GET "https://api.cognizy.ai/api/v1/public/knowledge-base/search?query=how%20do%20I%20reset%20my%20password" \
-H "Authorization: Bearer $COGNIZY_API_KEY"List knowledge bases
get/v1/public/knowledge-base
Returns all knowledge bases in the organization, with document counts.
Parameters
No parameters.
Responses
200
Examples
curl -X GET "https://api.cognizy.ai/api/v1/public/knowledge-base" \
-H "Authorization: Bearer $COGNIZY_API_KEY"Create a knowledge base
post/v1/public/knowledge-base
Accepts Idempotency-Key
Creates a new KB. Plan limits apply (RagService enforces this — returns 403 when the org is at its knowledgeBases quota).
Parameters
No parameters.
Body (JSON)required
namestringrequired- Knowledge base name
descriptionstringoptional- Optional description
| Field | Type | Description |
|---|---|---|
namerequired | string | Knowledge base name |
descriptionoptional | string | Optional description |
Responses
201Knowledge base created400Invalid `name` or `description`403Plan quota for knowledge bases exceeded
Examples
curl -X POST "https://api.cognizy.ai/api/v1/public/knowledge-base" \
-H "Authorization: Bearer $COGNIZY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"name": "Maria Souza",
"description": "texto"
}'Get a knowledge base
get/v1/public/knowledge-base/{id}
Returns one KB with metadata and document count.
Parameters
idstringrequired· path- Knowledge base ID
| Field | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Knowledge base ID |
Responses
200Knowledge base returned404Knowledge base not found
Examples
curl -X GET "https://api.cognizy.ai/api/v1/public/knowledge-base/<id>" \
-H "Authorization: Bearer $COGNIZY_API_KEY"List documents in a knowledge base
get/v1/public/knowledge-base/{id}/documents
Lists documents inside a KB with their titles, source URLs, use counts, and timestamps. Use this to avoid duplicating content before adding a new document.
Parameters
idstringrequired· path- Knowledge base ID
| Field | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Knowledge base ID |
Responses
200Document list returned404Knowledge base not found
Examples
curl -X GET "https://api.cognizy.ai/api/v1/public/knowledge-base/<id>/documents" \
-H "Authorization: Bearer $COGNIZY_API_KEY"Add a document to a knowledge base
post/v1/public/knowledge-base/{id}/documents
Accepts Idempotency-Key
Adds a new document, chunks it, generates embeddings, and stores them in pgvector. Same pipeline as the in-app upload. Returns the created document row (without chunks). Subsequent search_knowledge_base calls will surface this content immediately — RAG cache is invalidated automatically.
Parameters
idstringrequired· path- Knowledge base ID
| Field | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Knowledge base ID |
Body (JSON)required
titlestringrequired- Document title (unique per KB)
contentstringrequired- Document body (markdown/text)
sourceUrlstringoptional- Optional source URL
| Field | Type | Description |
|---|---|---|
titlerequired | string | Document title (unique per KB) |
contentrequired | string | Document body (markdown/text) |
sourceUrloptional | string | Optional source URL |
Responses
201Document created and embedded400Invalid title/content/sourceUrl404Knowledge base not found
Examples
curl -X POST "https://api.cognizy.ai/api/v1/public/knowledge-base/<id>/documents" \
-H "Authorization: Bearer $COGNIZY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"title": "texto",
"content": "texto",
"sourceUrl": "https://example.com"
}'Get a document
get/v1/public/knowledge-base/documents/{documentId}
Returns the full document content. Useful to read existing material before suggesting an update.
Parameters
documentIdstringrequired· path- Document ID
| Field | In | Type | Description |
|---|---|---|---|
documentIdrequired | path | string | Document ID |
Responses
200Document returned404Document not found
Examples
curl -X GET "https://api.cognizy.ai/api/v1/public/knowledge-base/documents/<documentId>" \
-H "Authorization: Bearer $COGNIZY_API_KEY"Update a document
patch/v1/public/knowledge-base/documents/{documentId}
Accepts Idempotency-Key
Partial update of a document. Provide any combination of title, content, sourceUrl. When content changes, the document is re-chunked and re-embedded automatically — useCount and feedback stats are preserved. Renaming into a title that already exists in the KB returns 409 (unique constraint).
Parameters
documentIdstringrequired· path- Document ID
| Field | In | Type | Description |
|---|---|---|---|
documentIdrequired | path | string | Document ID |
Body (JSON)required
titlestringoptionalcontentstringoptionalsourceUrlstringoptional
| Field | Type | Description |
|---|---|---|
titleoptional | string | |
contentoptional | string | |
sourceUrloptional | string |
Responses
200Document updated400Invalid patch payload404Document not found409Another document in this KB already has that title
Examples
curl -X PATCH "https://api.cognizy.ai/api/v1/public/knowledge-base/documents/<documentId>" \
-H "Authorization: Bearer $COGNIZY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"title": "texto",
"content": "texto",
"sourceUrl": "https://example.com"
}'Delete a document
delete/v1/public/knowledge-base/documents/{documentId}
Removes a document and its chunks (cascade via Prisma). RAG cache is invalidated automatically. Idempotent — succeeds with 204 even if the document was already gone (P2025 swallowed).
Parameters
documentIdstringrequired· path- Document ID
| Field | In | Type | Description |
|---|---|---|---|
documentIdrequired | path | string | Document ID |
Responses
204Document deleted (or was already gone — idempotent)404Document not found in this organization
Examples
curl -X DELETE "https://api.cognizy.ai/api/v1/public/knowledge-base/documents/<documentId>" \
-H "Authorization: Bearer $COGNIZY_API_KEY"Bulk add or upsert documents
post/v1/public/knowledge-base/{id}/documents/bulk
Accepts Idempotency-Key
Adds many documents in one request. Upsert-by-title: a doc whose title already exists in the KB is UPDATED with the new content; others are created. Returns counts of created/updated/skipped (skipped includes invalid items and intra-batch title duplicates). Use this for migrations, JSON imports, or batch material generated by an LLM. Cap: 200 items per call.
Parameters
idstringrequired· path- Knowledge base ID
| Field | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Knowledge base ID |
Body (JSON)required
documentsobject[]requireddocuments[].titlestringrequireddocuments[].contentstringrequireddocuments[].sourceUrlstringoptional
| Field | Type | Description |
|---|---|---|
documentsrequired | object[] | |
documents[].titlerequired | string | |
documents[].contentrequired | string | |
documents[].sourceUrloptional | string |
Responses
200Bulk import result with created/updated/skipped counts400Invalid documents payload404Knowledge base not found
Examples
curl -X POST "https://api.cognizy.ai/api/v1/public/knowledge-base/<id>/documents/bulk" \
-H "Authorization: Bearer $COGNIZY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"documents": [
{
"title": "texto",
"content": "texto",
"sourceUrl": "https://example.com"
}
]
}'