Knowledge Bases
A knowledge base is a collection of files used to persist your data in OnceContext.
One or more pipelines can be connected to a knowledge base using the KnowledgeBaseFiles
step.
Connected Pipelines will be triggered automatically when any files are uploaded to the knowledgebase.
Create a Knowledge Base:
const knowledgeBaseCreateArgs: OneContext.KnowledgeBaseCreateType = OneContext.KnowledgeBaseCreateSchema.parse({
API_KEY: API_KEY,
knowledgeBaseName: knowledgeBaseName
})
OneContext.createKnowledgeBase(knowledgeBaseCreateArgs).then((res) => {console.log(res)})
Upload Files to an existing Knowledge Base:
const uploadFilesArgs: OneContext.UploadFilesType = OneContext.UploadFilesSchema.parse({
API_KEY: API_KEY,
knowledgeBaseName: knowledgeBaseName,
file: "./quickstart/demo_data/instruct_gpt.pdf",
metadataJson: {"tag": "longForm"}
})
OneContext.uploadFiles(uploadFilesArgs).then((res) => {console.log(res)})
List Files in a Knowledge Base:
Query the files in a knowledge base with specific filtering, sorting and pagination:
const listFilesArgs: OneContext.ListFilesType = OneContext.ListFilesSchema.parse({
API_KEY: API_KEY,
knowledgeBaseNames: [knowledgeBaseName1, knowledgeBaseName2],
})
OneContext.listFiles(listFilesArgs).then((res) => {console.log(res)})
Delete Files from a Knowledge Base
Remove a list of files from a given knowledge base
const deleteFileArgs: OneContext.DeleteFilesType = OneContext.DeleteFilesSchema.parse({
API_KEY: API_KEY,
knowledgeBaseName: knowledgeBaseName,
fileNames: ["instruct_gpt.pdf"]
})
OneContext.deleteFiles(deleteFileArgs).then((res) => {console.log(res)})
Warning
All chunks associated with the deleted file will also be deleted.
Upload All Supported Files from a Directory
This facilitates bulk uploading of files to your knowledge base from a specified directory:
const uploadDirectoryArgsLongForm: OneContext.UploadDirectoryType = OneContext.UploadDirectorySchema.parse({
API_KEY: API_KEY,
knowledgeBaseName: knowledgeBaseName,
directory: "./quickstart/demo_data/long_form/",
metadataJson: {"tag": "longForm"}
})
OneContext.uploadDirectory(uploadDirectoryArgsLongForm).then((res) => {console.log(res)})