Pular para o conteúdo
CognizyCognizyAjuda
Entrar
Nesta área

Knowledge Base

Manage knowledge bases and documents; run semantic search (RAG).

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

bash
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

Respostas

  • 201Knowledge base created
  • 400Invalid `name` or `description`
  • 403Plan quota for knowledge bases exceeded

Exemplos

bash
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

Respostas

  • 200Knowledge base returned
  • 404Knowledge base not found

Exemplos

bash
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

Respostas

  • 200Document list returned
  • 404Knowledge base not found

Exemplos

bash
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

Corpo (JSON)obrigatório

titlestringobrigatório
Document title (unique per KB)
contentstringobrigatório
Document body (markdown/text)
sourceUrlstringopcional
Optional source URL

Respostas

  • 201Document created and embedded
  • 400Invalid title/content/sourceUrl
  • 404Knowledge base not found

Exemplos

bash
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

Respostas

  • 200Document returned
  • 404Document not found

Exemplos

bash
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

Corpo (JSON)obrigatório

titlestringopcional
contentstringopcional
sourceUrlstringopcional

Respostas

  • 200Document updated
  • 400Invalid patch payload
  • 404Document not found
  • 409Another document in this KB already has that title

Exemplos

bash
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

Respostas

  • 204Document deleted (or was already gone — idempotent)
  • 404Document not found in this organization

Exemplos

bash
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

Corpo (JSON)obrigatório

documentsobject[]obrigatório
documents[].titlestringobrigatório
documents[].contentstringobrigatório
documents[].sourceUrlstringopcional

Respostas

  • 200Bulk import result with created/updated/skipped counts
  • 400Invalid documents payload
  • 404Knowledge base not found

Exemplos

bash
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"
    }
  ]
}'

Toda a referência