Cortex
TwitterDiscord
  • 👋Welcome to Cortex
  • Overview
    • 💡Understanding Cortex Architecture
  • Product Guides
    • 🛫Making your first Copilot
    • ⚡Making your first Callable
  • Fundamentals
    • ✈️Copilot
    • 🧠Knowledge
    • ⚡Callable
    • 🛠️Getting set up
      • 📝Setting permissions
  • Callable
    • Blocks
      • Models
        • Language Model
        • Language Model With Code
      • Data
        • Dataset Loader
      • Tools
        • Knowledge Search
        • Google Search
        • Curl Request
        • Web Page Crawler
      • Control
        • Code
        • Loop Until
        • Map Reduce
    • Use Cases
      • Building a Company Help Desk
      • Creating a Social Media Manager Chatbot
      • Utilizing Model Examples to Convert Text to JSON
      • Retrievals from Knowledge Search Blocks
      • Chatbot with Google Search Assistance
  • Guides
    • Getting Started with the SDK
    • Documents
  • API References
    • Introduction
    • Authentication
    • Making Curl Requests
    • Node.js Library
    • Python Library
Powered by GitBook
On this page
  • Retrieving a Document
  • Uploading a Document
  • Deleting a Document
  1. Guides

Documents

PreviousGetting Started with the SDKNextIntroduction

Last updated 1 year ago

Retrieving a Document

First, find the name of the knowledge that contains the document you wish to retrieve in the knowledge tab of Cortex.

Then, find the name of the documentID you want to retrieve.

Use the knowledgeName and documentID with the .getDocument function of cortex to retrieve the document. See the Node.js Library for the exact .json return structure.

try {
    const res = await cortex.getDocument('tigers','testing.txt')
    const document = res.data.document
    console.log(document.text);
} catch (error) {
    if (error.response) {
        console.log(error.response.status);
        console.log(error.response.data);
    } else {
        console.log(error.message);
    }
}
CortexAPI.getDocument('tigers','testing.txt')

Uploading a Document

Find the knowledgeName of the desired location of the document.

Create an object that follows the createDocument interface to upload.

interface createDocument {
  timestamp?: number;
  tags?: string[];
  text?: string | null;
  source_url?: string | null;
};
class CreateDocument:
    def __init__(
        self,
        timestamp: Union[int, None] = None,
        tags:
        List[str] = None,
        text: Union[str, None] = None,
        source_url: Union[str, None] = None
    ):
        self.timestamp = timestamp
        self.tags = tags
        self.text = text
        self.source_url = source_url

Use the documentID parameter to name the document you want to upload.

const test = {
  "source_url": "https://www.test.com/",
  "text": "test"
  }

try {
  let output = await cortex.uploadDocument('tigers','test1',test);
  console.log(output.data.document);
} catch (error) {
  if (error.response) {
    console.log(error.response.status);
    console.log(error.response.data);
  } else {
    console.log(error.message);
  }
}
test = cortex.CreateDocument()
test.source_url = "https://www.test.com/"
test.text = "test"

CortexAPI = cortex.CortexAPI("sk-...")
CortexAPI.uploadDocument('tigers','test1',test)

Deleting a Document

try {
  let output = await cortex.deleteDocument('tigers','test1');
  console.log(output.data.document);
} catch (error:any) {
  if (error.response) {
    console.log(error.response.status);
    console.log(error.response.data);
  } else {
    console.log(error.message);
  }
}
CortexAPI.deleteDocument('tigers','test1')