knowledge
The methods of pd.knowledge. Inputs and outputs are described in Conventions; every method can also fail as described in Errors.
Methods
pd.knowledge.list(input, init?)
List a project's knowledge sources
GET /api/workspaces/{workspaceId}/projects/{projectId}/knowledge
Requires knowledge.read on the project; an unknown project answers 404. Returns the sources newest first, each with its ingestion status and the number of stored passages (chunkCount). Passages reach article generation only where the server's rag feature flag is on.
Input
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workspaceId |
path | string (uuid) |
yes | Id of the workspace the request works in. The caller must be a member of it, or hold an API key issued by it. For anyone else, an unknown id and an id they do not belong to both answer 404 RESOURCE_NOT_FOUND, so membership cannot be probed. |
projectId |
path | string (uuid) |
yes | Id of a project of workspaceId. A project of another workspace answers 404 RESOURCE_NOT_FOUND, as if it did not exist. When the project has members, a workspace member who is not one of them answers 403 FORBIDDEN, and a project role can only narrow the permissions the member's workspace roles grant. |
init |
init | { signal?: AbortSignal; timeoutMs?: number } |
no | The second argument: signal aborts the call, timeoutMs overrides the client's per-attempt timeout. |
Returns 200 OK
| Field | Type | Required | Description |
|---|---|---|---|
sources |
object[] |
yes | The project's knowledge sources, newest first. |
sources[].id |
string (uuid) |
yes | Knowledge source id. |
sources[].type |
"pdf" | "docx" | "txt" | "markdown" | "url" | "web_page" | "article" |
yes | How the source is read: pdf, docx, txt and markdown as that file format (uploaded with PUT /api/workspaces/{workspaceId}/knowledge/{sourceId}/content, or fetched from sourceUrl); url, web_page and article as an HTML page fetched from sourceUrl. |
sources[].name |
string |
yes | Label given to the source when it was registered. |
sources[].sourceUrl |
string | null |
yes | Address the source is fetched from. Null for a source that is an uploaded file. |
sources[].status |
"pending" | "processing" | "ready" | "failed" |
yes | Ingestion state: pending until the source is picked up (also after a new upload or a retry), processing while it is read and embedded, ready once its passages are stored, failed with the reason in errorMessage. |
sources[].errorMessage |
string | null |
yes | Why the last ingestion failed. Null unless status is failed. |
sources[].chunkCount |
integer |
yes | Passages stored for the source; 0 until it is ingested. |
sources[].createdAt |
string (date-time) |
yes | When the source was registered. |
Errors 400 invalid input, 401 missing or invalid key, 403 the key's roles lack the permission, 404 not found, 429 rate limited or out of quota. See Errors.
Example
import { PrismDraft } from "@prism-draft/sdk";
const pd = new PrismDraft({ apiKey: process.env.PRISMDRAFT_API_KEY! });
const result = await pd.knowledge.list({
workspaceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
projectId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
});
console.log(result);
pd.knowledge.create(input, init?)
Register a knowledge source
POST /api/workspaces/{workspaceId}/projects/{projectId}/knowledge
Requires knowledge.create on the project; an unknown project answers 404. Answers 201 with the source at status pending. With sourceUrl, the address is checked against private ranges (400 if refused) and ingestion is queued at once. Without it, nothing runs until the file is sent with PUT /api/workspaces/{workspaceId}/knowledge/{sourceId}/content. A successful ingestion costs 1 credit (reserved when the run starts, released if it fails; a workspace without the credit gets a failed source). Records a knowledge.added audit entry.
Input
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workspaceId |
path | string (uuid) |
yes | Id of the workspace the request works in. The caller must be a member of it, or hold an API key issued by it. For anyone else, an unknown id and an id they do not belong to both answer 404 RESOURCE_NOT_FOUND, so membership cannot be probed. |
projectId |
path | string (uuid) |
yes | Id of a project of workspaceId. A project of another workspace answers 404 RESOURCE_NOT_FOUND, as if it did not exist. When the project has members, a workspace member who is not one of them answers 403 FORBIDDEN, and a project role can only narrow the permissions the member's workspace roles grant. |
body |
body | object |
yes | |
body.type |
body | "pdf" | "docx" | "txt" | "markdown" | "url" | "web_page" | "article" |
yes | How the source is read: pdf, docx, txt and markdown as that file format; url, web_page and article as an HTML page fetched from sourceUrl. A file source must be uploaded with a matching content type. |
body.name |
body | string |
yes | Label for the source, 1-200 characters. |
body.sourceUrl |
body | string (uri) |
no | Address to fetch the source from: http or https, no credentials, and not a private or internal address (400 otherwise). When set, ingestion is queued immediately. Omit it for a file you will upload. |
init |
init | { signal?: AbortSignal; timeoutMs?: number } |
no | The second argument: signal aborts the call, timeoutMs overrides the client's per-attempt timeout. |
Returns 201 Created
| Field | Type | Required | Description |
|---|---|---|---|
source |
object |
yes | The source as stored after the call. |
source.id |
string (uuid) |
yes | Knowledge source id. |
source.workspaceId |
string (uuid) |
yes | Workspace that owns the source. |
source.projectId |
string (uuid) |
yes | Project whose knowledge base the source belongs to. |
source.type |
"pdf" | "docx" | "txt" | "markdown" | "url" | "web_page" | "article" |
yes | How the source is read: pdf, docx, txt and markdown as that file format (uploaded with PUT /api/workspaces/{workspaceId}/knowledge/{sourceId}/content, or fetched from sourceUrl); url, web_page and article as an HTML page fetched from sourceUrl. |
source.name |
string |
yes | Label given to the source when it was registered. |
source.sourceUrl |
string | null |
yes | Address the source is fetched from. Null for a source that is an uploaded file. |
source.storagePath |
string | null |
yes | Internal location of the uploaded file; null until a file is uploaded. |
source.status |
"pending" | "processing" | "ready" | "failed" |
yes | Ingestion state: pending until the source is picked up (also after a new upload or a retry), processing while it is read and embedded, ready once its passages are stored, failed with the reason in errorMessage. |
source.errorMessage |
string | null |
yes | Why the last ingestion failed. Null unless status is failed. |
source.createdAt |
string (date-time) |
yes | When the source was registered. |
source.updatedAt |
string (date-time) |
yes | When the source row last changed, including each status change. |
Errors 400 invalid input, 401 missing or invalid key, 403 the key's roles lack the permission, 404 not found, 429 rate limited or out of quota. See Errors.
Example
import { PrismDraft } from "@prism-draft/sdk";
const pd = new PrismDraft({ apiKey: process.env.PRISMDRAFT_API_KEY! });
const result = await pd.knowledge.create({
workspaceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
projectId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
body: {
type: "pdf",
name: "example",
},
});
console.log(result);
pd.knowledge.uploadContent(input, init?)
Upload a knowledge source's bytes
PUT /api/workspaces/{workspaceId}/knowledge/{sourceId}/content
The body is the raw file, sent with its own content type (PDF, DOCX, text or markdown). The filename is not kept. Requires knowledge.create. Accepted content types: application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, text/plain and text/markdown, and the type must match the source's type (pdf, docx, txt, markdown); anything else, or an empty body, answers 400. The limit is 10 MiB (10485760 bytes); a larger body answers 413. A source of type url, web_page or article has no file to upload and answers 400. The source goes back to pending and ingestion is queued. The run is keyed on the source and the file's byte length: a file of the same size uploaded while the earlier run is still on record (about a day after it completes, a week after it fails) is stored but not ingested, and the source stays pending until POST /api/workspaces/{workspaceId}/knowledge/{sourceId}/reingest. Once the new run completes it replaces the stored passages. Records a knowledge.added audit entry.
Input
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workspaceId |
path | string (uuid) |
yes | Id of the workspace the request works in. The caller must be a member of it, or hold an API key issued by it. For anyone else, an unknown id and an id they do not belong to both answer 404 RESOURCE_NOT_FOUND, so membership cannot be probed. |
sourceId |
path | string (uuid) |
yes | Id of the knowledge source, from knowledge.list. |
body |
body | Blob | ArrayBuffer | Uint8Array |
yes | The raw file. |
contentType |
body | "application/pdf" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "text/plain" | "text/markdown" |
yes | Sent as the Content-Type header; picks how the server reads the file. |
init |
init | { signal?: AbortSignal; timeoutMs?: number } |
no | The second argument: signal aborts the call, timeoutMs overrides the client's per-attempt timeout. |
Returns 200 OK
| Field | Type | Required | Description |
|---|---|---|---|
source |
object |
yes | The source as stored after the call. |
source.id |
string (uuid) |
yes | Knowledge source id. |
source.workspaceId |
string (uuid) |
yes | Workspace that owns the source. |
source.projectId |
string (uuid) |
yes | Project whose knowledge base the source belongs to. |
source.type |
"pdf" | "docx" | "txt" | "markdown" | "url" | "web_page" | "article" |
yes | How the source is read: pdf, docx, txt and markdown as that file format (uploaded with PUT /api/workspaces/{workspaceId}/knowledge/{sourceId}/content, or fetched from sourceUrl); url, web_page and article as an HTML page fetched from sourceUrl. |
source.name |
string |
yes | Label given to the source when it was registered. |
source.sourceUrl |
string | null |
yes | Address the source is fetched from. Null for a source that is an uploaded file. |
source.storagePath |
string | null |
yes | Internal location of the uploaded file; null until a file is uploaded. |
source.status |
"pending" | "processing" | "ready" | "failed" |
yes | Ingestion state: pending until the source is picked up (also after a new upload or a retry), processing while it is read and embedded, ready once its passages are stored, failed with the reason in errorMessage. |
source.errorMessage |
string | null |
yes | Why the last ingestion failed. Null unless status is failed. |
source.createdAt |
string (date-time) |
yes | When the source was registered. |
source.updatedAt |
string (date-time) |
yes | When the source row last changed, including each status change. |
Errors 400 invalid input, 401 missing or invalid key, 403 the key's roles lack the permission, 404 not found, 429 rate limited or out of quota. See Errors.
Example
import { PrismDraft } from "@prism-draft/sdk";
const pd = new PrismDraft({ apiKey: process.env.PRISMDRAFT_API_KEY! });
const result = await pd.knowledge.uploadContent({
workspaceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
sourceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
body: new Blob([/* the file's bytes */]),
contentType: "application/pdf",
});
console.log(result);
pd.knowledge.reingest(input, init?)
Re-run ingestion for a knowledge source
POST /api/workspaces/{workspaceId}/knowledge/{sourceId}/reingest
Requires knowledge.update. Queues a new ingestion run for the source and answers at once with status pending; the run itself is asynchronous and ends at ready or failed. Meant for a source that failed, but the call does not check the current status. A source with neither an uploaded file nor a sourceUrl answers 400, an unknown one 404. A successful run costs 1 credit; a workspace without the credit gets a failed source with the reason in errorMessage.
Input
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workspaceId |
path | string (uuid) |
yes | Id of the workspace the request works in. The caller must be a member of it, or hold an API key issued by it. For anyone else, an unknown id and an id they do not belong to both answer 404 RESOURCE_NOT_FOUND, so membership cannot be probed. |
sourceId |
path | string (uuid) |
yes | Id of the knowledge source, from knowledge.list. |
init |
init | { signal?: AbortSignal; timeoutMs?: number } |
no | The second argument: signal aborts the call, timeoutMs overrides the client's per-attempt timeout. |
Returns 200 OK
| Field | Type | Required | Description |
|---|---|---|---|
source |
object |
yes | Only what the call settles: the source id and its queued status. |
source.id |
string (uuid) |
yes | Id of the source that was queued again. |
source.status |
"pending" | "processing" | "ready" | "failed" |
yes | Always pending: the run is queued. The status moves to processing when the run starts. |
Errors 400 invalid input, 401 missing or invalid key, 403 the key's roles lack the permission, 404 not found, 429 rate limited or out of quota. See Errors.
Example
import { PrismDraft } from "@prism-draft/sdk";
const pd = new PrismDraft({ apiKey: process.env.PRISMDRAFT_API_KEY! });
const result = await pd.knowledge.reingest({
workspaceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
sourceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
});
console.log(result);
pd.knowledge.delete(input, init?)
Delete a knowledge source
DELETE /api/workspaces/{workspaceId}/knowledge/{sourceId}
Requires knowledge.delete; a source that does not exist or belongs to another workspace answers 404. Removes the source and its stored passages, then the uploaded file from storage. A failure to remove the file does not fail the call. Records a knowledge.deleted audit entry.
Input
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workspaceId |
path | string (uuid) |
yes | Id of the workspace the request works in. The caller must be a member of it, or hold an API key issued by it. For anyone else, an unknown id and an id they do not belong to both answer 404 RESOURCE_NOT_FOUND, so membership cannot be probed. |
sourceId |
path | string (uuid) |
yes | Id of the knowledge source, from knowledge.list. |
init |
init | { signal?: AbortSignal; timeoutMs?: number } |
no | The second argument: signal aborts the call, timeoutMs overrides the client's per-attempt timeout. |
Returns 200 OK
| Field | Type | Required | Description |
|---|---|---|---|
ok |
boolean |
yes | Always true; a failure is an error response. |
Errors 400 invalid input, 401 missing or invalid key, 403 the key's roles lack the permission, 404 not found, 429 rate limited or out of quota. See Errors.
Example
import { PrismDraft } from "@prism-draft/sdk";
const pd = new PrismDraft({ apiKey: process.env.PRISMDRAFT_API_KEY! });
const result = await pd.knowledge.delete({
workspaceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
sourceId: "3f0c5a1e-8b2d-4c6e-9a7f-1d2e3f4a5b6c",
});
console.log(result);