Knowledge Bases
Node.js SDK - Knowledge base management resource
KnowledgeBases
Resource for managing knowledge bases and their documents. Access via client.knowledgeBases.
Methods
list(params?, options?)
Lists knowledge bases with pagination.
const page = await client.knowledgeBases.list({ limit: 10 });
for (const kb of page.data) {
console.log(kb.name, kb.documentCount);
}Returns: Promise<Page<KnowledgeBase>>
get(id, options?)
Retrieves a single knowledge base by ID.
const kb = await client.knowledgeBases.get('kb_abc123');Returns: Promise<KnowledgeBase>
create(params, options?)
Creates a new knowledge base.
const kb = await client.knowledgeBases.create({
name: 'Product catalog',
description: 'Product information database',
});Returns: Promise<KnowledgeBase>
update(id, params, options?)
Updates an existing knowledge base.
const kb = await client.knowledgeBases.update('kb_abc123', {
name: 'Updated catalog',
});Returns: Promise<KnowledgeBase>
delete(id, options?)
Deletes a knowledge base.
await client.knowledgeBases.delete('kb_abc123');Returns: Promise<void>
search(id, params, options?)
Searches a knowledge base for matching documents.
const results = await client.knowledgeBases.search('kb_abc123', {
query: 'invoice total',
limit: 5,
});
for (const item of results.data) {
console.log(item.document.content, item.similarity);
}Returns: Promise<SearchResult>
sync(id, options?)
Triggers a sync operation for the knowledge base.
const result = await client.knowledgeBases.sync('kb_abc123');
console.log(result.status, result.documentsProcessed);Returns: Promise<SyncResult>
Documents
Access knowledge base documents via client.knowledgeBases.documents(knowledgeBaseId).
documents(kbId).list(params?, options?)
Lists documents in a knowledge base.
const docs = await client.knowledgeBases.documents('kb_abc123').list();documents(kbId).get(docId, options?)
Gets a single document.
const doc = await client.knowledgeBases.documents('kb_abc123').get('doc_xyz');documents(kbId).create(params, options?)
Creates a new document in the knowledge base.
const doc = await client.knowledgeBases.documents('kb_abc123').create({
content: { title: 'Invoice', amount: 100 },
metadata: { source: 'upload' },
});documents(kbId).update(docId, params, options?)
Updates an existing document.
const doc = await client.knowledgeBases.documents('kb_abc123').update('doc_xyz', {
content: { title: 'Updated Invoice' },
});documents(kbId).delete(docId, options?)
Deletes a document from the knowledge base.
await client.knowledgeBases.documents('kb_abc123').delete('doc_xyz');