Nesta área
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.
Parâmetros
knowledgeBaseIdstringopcional· consulta- Restrict search to a single knowledge base. Omit to search across all.
limitnumberopcional· consulta- Number of results to return. Range 1–20, default 5.
querystringobrigatório· consulta
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
knowledgeBaseIdopcional | consulta | string | Restrict search to a single knowledge base. Omit to search across all. |
limitopcional | consulta | number | Number of results to return. Range 1–20, default 5. |
queryobrigatório | consulta | string |
Respostas
200
Exemplos
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.
Parâmetros
Sem parâmetros.
Respostas
200
Exemplos
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
Aceita Idempotency-Key
Creates a new KB. Plan limits apply (RagService enforces this — returns 403 when the org is at its knowledgeBases quota).
Parâmetros
Sem parâmetros.
Corpo (JSON)obrigatório
namestringobrigatório- Knowledge base name
descriptionstringopcional- Optional description
| Campo | Tipo | Descrição |
|---|---|---|
nameobrigatório | string | Knowledge base name |
descriptionopcional | string | Optional description |
Respostas
201Knowledge base created400Invalid `name` or `description`403Plan quota for knowledge bases exceeded
Exemplos
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.
Parâmetros
idstringobrigatório· caminho- Knowledge base ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
idobrigatório | caminho | string | Knowledge base ID |
Respostas
200Knowledge base returned404Knowledge base not found
Exemplos
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.
Parâmetros
idstringobrigatório· caminho- Knowledge base ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
idobrigatório | caminho | string | Knowledge base ID |
Respostas
200Document list returned404Knowledge base not found
Exemplos
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
Aceita 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.
Parâmetros
idstringobrigatório· caminho- Knowledge base ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
idobrigatório | caminho | string | Knowledge base ID |
Corpo (JSON)obrigatório
titlestringobrigatório- Document title (unique per KB)
contentstringobrigatório- Document body (markdown/text)
sourceUrlstringopcional- Optional source URL
| Campo | Tipo | Descrição |
|---|---|---|
titleobrigatório | string | Document title (unique per KB) |
contentobrigatório | string | Document body (markdown/text) |
sourceUrlopcional | string | Optional source URL |
Respostas
201Document created and embedded400Invalid title/content/sourceUrl404Knowledge base not found
Exemplos
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.
Parâmetros
documentIdstringobrigatório· caminho- Document ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
documentIdobrigatório | caminho | string | Document ID |
Respostas
200Document returned404Document not found
Exemplos
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}
Aceita 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).
Parâmetros
documentIdstringobrigatório· caminho- Document ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
documentIdobrigatório | caminho | string | Document ID |
Corpo (JSON)obrigatório
titlestringopcionalcontentstringopcionalsourceUrlstringopcional
| Campo | Tipo | Descrição |
|---|---|---|
titleopcional | string | |
contentopcional | string | |
sourceUrlopcional | string |
Respostas
200Document updated400Invalid patch payload404Document not found409Another document in this KB already has that title
Exemplos
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).
Parâmetros
documentIdstringobrigatório· caminho- Document ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
documentIdobrigatório | caminho | string | Document ID |
Respostas
204Document deleted (or was already gone — idempotent)404Document not found in this organization
Exemplos
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
Aceita 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.
Parâmetros
idstringobrigatório· caminho- Knowledge base ID
| Campo | Onde | Tipo | Descrição |
|---|---|---|---|
idobrigatório | caminho | string | Knowledge base ID |
Corpo (JSON)obrigatório
documentsobject[]obrigatóriodocuments[].titlestringobrigatóriodocuments[].contentstringobrigatóriodocuments[].sourceUrlstringopcional
| Campo | Tipo | Descrição |
|---|---|---|
documentsobrigatório | object[] | |
documents[].titleobrigatório | string | |
documents[].contentobrigatório | string | |
documents[].sourceUrlopcional | string |
Respostas
200Bulk import result with created/updated/skipped counts400Invalid documents payload404Knowledge base not found
Exemplos
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"
}
]
}'