Skip to main content

addEntity()

addEntity(request: AddEntityRequest): Promise<AddEntityResponse>

Defined in: packages/core/src/document-search/index.ts:703

Add a new entity to document chunks

Adds a named entity to a single chunk or all chunks of a file. Useful for manual entity annotation or correction.

Parameters

ParameterTypeDescription
requestAddEntityRequestEntity addition request

Returns

Promise<AddEntityResponse>

Promise resolving to AddEntityResponse:

  • response - Success status (boolean)
  • chunksUpdated - Number of chunks where entity was added
  • chunksSkipped - Number of chunks skipped (already had entity)
  • fileHash - File hash if file-level update
  • updatedEntity - Name of the entity that was added

Throws

401 - Not authenticated

Throws

422 - Validation error

Example

import { addEntity } from "@cpod/sdk";

// Add entity to a specific chunk
const result = await addEntity({
entity: "John Smith",
id: "chunk-abc123",
userName: "admin@example.com",
entityType: "PERSON",
description: "CEO of Acme Corp",
updateType: "chunk",
});
console.log(`Added to ${result.chunksUpdated} chunks`);

// Add entity to all chunks of a file
const fileResult = await addEntity({
entity: "Acme Corporation",
id: "95d47a820fcc0a667004a6da403b3d29",
userName: "admin@example.com",
entityType: "ORGANIZATION",
updateType: "file",
});