Skip to main content
A source is a set of files that Cominty indexes, so an agent can search them and cite them. With an API key, you create a source from files on your machine. The SDKs do it in one call. Read Custom agents first for what an API key can and cannot see. Each snippet has a tab for the Python SDK, the JavaScript SDK, and HTTP. Both SDKs have the same methods on client.sources. Only the casing of the longer names differs:
Only drag-and-drop sources can be created with a key. Google Drive and SharePoint sources need the console’s OAuth flow. They can show up in sources.list() as organization sources, but you cannot create them here.

How it works

sources.create runs the first four steps and returns while the source is pending or syncing. Wait until it is synced before you search it.

Create a source

Your files are not available to the agent as soon as the source is created and the upload ends. The platform must first index every file. Until the source is synced, the agent finds nothing, or only some of the files. Wait for synced before you start a chat. Each snippet below waits for it.
In Python, files can be one file Path, a folder Path (its top-level files only, no recursion, hidden files skipped), or an iterable of file Paths. The SDK refuses these before any upload with InvalidParams:
  • a plain str: wrap a path in Path(...);
  • an empty list, or a file that does not exist;
  • two files with the same name;
  • more than 50 files.
In JavaScript, files is one File, one { filename, content } object whose content is a Blob, ArrayBuffer, or Uint8Array, or an array of them. There is no path input: read the files yourself, as in the snippet above. A string, an empty array, two files with the same name, or more than 50 files throw InvalidParams before any upload. See client.sources. name is optional. Without it, the server generates one.

Two ids

A source has two ids. Do not mix them up.

Wait for the sync

The wait method polls the source until it is synced. By default, it gives up after 10 minutes and polls every 5 seconds. The Python SDK takes seconds (timeout=600.0, interval=5.0). The JavaScript SDK takes milliseconds ({ timeout: 600_000, interval: 5_000 }).

Give the source to an agent

Put the source’s number id in an IndexedDocumentsCapability.
You can also pass the source in the thread capabilities on chat.start, or narrow it for one message with the message scope. See Capabilities.

Chat as the key owner

A source created with a key is private to the key owner. A chat that searches it must run as the owner: create the client with the owner’s id as its user id. The owner is agent.owner on any agent the key created.
With any other user id, the agent’s document tool reports You have no authorized document sources. The agent then says it found nothing. The COMINTY_USER_ID of your client may not be the key owner, so read agent.owner.

Read a citation

An answer cites its documents inline, as <cite document_id="2698#10778" pages="1" name="facts.txt"/>. The id is the source id, a #, and the document’s own identifier. It is not always a number. Resolve it to its source and file:
  • An unknown id raises NotFoundError (404). There is no call that lists documents. An empty id is refused before any request (ValueError in Python, InvalidParams in JavaScript).
  • document_uri can be null. For a drag-and-drop source, it ends with the id of the file, the one the download method takes.
To read the original file, list the source’s files and download one:
The SDKs fetch the presigned URL for you, without sending the key. They hold the whole file in memory.

Keep a source up to date

New files follow the same rule. After you add or remove a file, the source is indexed again, and the change reaches the agent only once the source is synced again.
  • Adding files uploads them into the source’s drive, then requests a sync if the source’s status accepts one. If a sync is already running, the new files are left for it or for the daily sync. The limit of 50 files counts the files already in the source.
  • Removing a file deletes it, then requests a sync under the same rule. An empty file id is refused before any request (ValueError in Python, InvalidParams in JavaScript).
  • update only changes the name. The drive of a drag-and-drop source cannot change.
  • list() returns the key owner’s sources and the organization’s sources, archived ones included. get(pid) reads the list and picks, because a key has no single-source read. An unknown pid raises NotFoundError.
Each operation is valid from some statuses only. Any other combination is an APIError with status 400 and detail Operation is not valid. pause returns the source as pausing. It reaches paused a moment later, and only then does start resume it. A start while the source is still pausing fails with the same 400.
archive removes the indexed documents and the files. The source stays in the list with status archived. There is no delete, and no way back.

Limits

  • A source holds at most 50 files. The SDK checks it before it uploads.
  • A user has at most 100 drives. Each sources.create makes one, and a drive cannot be deleted. Reuse a source and add files to it instead of creating a new one for every batch.
  • A presigned download URL is valid for 5 minutes.
  • Uploads go straight to storage. The API key never reaches the storage host, and presigned signatures never appear in error messages.

Supported file types

The indexing pipeline reads more than 130 file formats. These are the most common ones. Audio and video files are transcribed by the indexing pipeline. Almost every common audio and video format works. The agent searches and reads the transcript. For a video, it does not see the images, only what is said.

What the agent can do with an indexed file

Indexing lets the agent find a file and read its content. Two limits apply today:
  • Spreadsheets are not part of the search. An Excel file (or another spreadsheet) is registered in the source with a document id, but the lexical and semantic search never returns its content. The agent can still list the documents of a source, spreadsheets included, and open one by its document id. It then reads the content extracted from the spreadsheet, as long as it is not too large. For a large spreadsheet, or to work on its data, attach the file to the chat instead, with the upload method of the Python SDK or the JavaScript SDK.
  • The agent cannot download the raw file. It reads the indexed content, but it cannot fetch the original file to transform it, for example to edit a document or to compute on a spreadsheet. To get the original, download it from your own code, as in Read a citation.

Next steps

Custom agents

Create and manage the agent that searches the source.

Capabilities

Narrow the sources and documents of a thread or a message.